Page 172 - DCAP103_Principle of operating system
P. 172

Unit 5: Memory Management



            5.5.5 Shared Pages                                                                    Notes
            Another advantage of paging is the possibility of sharing common code. This consideration is
            particularly important in a time-sharing environment. Consider a system that supports 40 users,
            each of whom executes a text editor. If the text editor consists of 150 KB of code and 50 KB of
            data space, we would need 8,000 KB to support the 40 users. If the code is reentrant code, Here
            we see a three-page editor-each page of size 50 KB; the large page size is used to simplify the
            figure-being shared among three processes. Each process has its own data page. Reentrant code
            (or pure code) is non-self-modifying code. If the code is reentrant, then it never changes during
            execution. Thus, two or more processes can execute the same code at the same time. Each process
            has its own copy of registers and data storage to hold the data for the process execution. The
            data for two different processes will, of course, vary for each process.

                           Figure 5.19: Sharing of Code in a Paging Environment
































            Only one copy of the editor needs to be kept in physical memory. Each user’s page table maps
            onto the same physical copy of the editor, but data pages are mapped onto different frames.
            Thus, to support 40 users, we need only one copy of the editor (150 KB), plus 40 copies of the
            50 KB of data space per user. The total space required is now 2,150 KB, instead of 8,000 KB-a
            significant savings. Other heavily used programs can also be shared-compilers, window systems,
            run-time libraries, database systems, and so on. To be sharable, the code must be reentrant. The
            read-only nature of shared code should not be left to the correctness of the code; the operating
            system  should  enforce  this  property  have  difficulty  implementing  shared  memory.  Shared
            memory is usually implemented as multiple virtual addresses (one for each process sharing
            the memory) that are mapped to one physical address. This standard method cannot be used,
            however, as there is only one virtual page entry for every physical page, so one physical page
            cannot have two (or more) shared virtual addresses. Organizing memory according to pages
            provides numerous other benefits in addition to allowing several processes to share the same
            physical pages.








                                             LOVELY PROFESSIONAL UNIVERSITY                                   165
   167   168   169   170   171   172   173   174   175   176   177