Page 368 - DCAP103_Principle of operating system
P. 368

Unit 12: Processes and Threads in Windows



            Once code or data is mapped onto a page, the page is said to be committed. A reference to a   Notes
            committed page is mapped using the virtual memory hardware and succeeds if the page is in
            main memory. If the page is not in main memory, a page fault occurs and the operating system
            finds and brings in the page from disk.

            A virtual page can also be in reserved state, meaning it is not available for being mapped until
            the  reservation  is  explicitly  removed.  For  example,  when  a  new  thread  is  created,  1  MB  of
            stack space is reserved in the process virtual address space, but only one page is committed.
            This technique means that the stack can eventually grow to 1 MB without fear that some other
            thread will allocate the needed contiguous piece of virtual address space out from under it. In
            addition to the free, reserved, and committed attributes, pages also have other attributes, such
            as being readable, writable, and executable.
            An interesting trade-off occurs with assignment of backing store to committed pages. A simple
            strategy would be to assign a page in one of the paging files to back up each committed page at
            the time the page was committed. This would guarantee that there was always a known place
            to write out each committed page should it be necessary to evict it from memory. The downside
            of this strategy is that the paging file might have to be as large as the union of all processes’
            virtual memory. On a large system that rarely ran out of memory and thus rarely paged, this
            approach would waste disk space.

            To avoid wasting disk space, Windows 2000 committed pages that have no natural home on
            the disk (e.g., stack pages) are not assigned a disk page until the moment that they have to be
            paged out. This design makes the system more complex because the paging files maps may
            have to be fetched during a page fault, and fetching them may cause one or more additional
            page faults inside the page fault handler. On the other hand, no disk space need be allocated
            for pages that are never paged out.
            Trade-offs like this (system complexity versus better performance or more features) tend to get
            resolved in favour of the latter because the value of better performance or more features is clear
            but the downside of complexity (a bigger maintenance headache and more crashes per year) is
            hard to quantify. Free and reserved pages never have shadow pages on disk and references to
            them always cause page faults.
            The shadow pages on the disk are arranged into one or more paging files. There may be up to
            16 paging files, possibly spread over 16 separate disks, for higher I/O bandwidth. Each one has
            an initial size and a maximum size it can grow to later if needed. These files can be created at
            the maximum size at system installation time in order to reduce the chances that they are highly
            fragmented, but new ones can be created using the control panel later on. The operating system
            keeps track of which virtual page maps onto which part of which paging file. For (execute only)
            program text, the executable binary file (i.e., .exe or .dll file) contains the shadow pages; for data
            pages, the paging files are used.
            Windows 2000, like many versions of UNIX, allows files to be mapped directly onto regions of
            the virtual address spaces (i.e., runs of consecutive pages). Once a file has been mapped onto
            the address space, it can be read or written using ordinary memory references. Memory-mapped
            files are implemented in the same way its other committed pages, only the shadow pages are
            in the users file instead of in the paging file. As a result, while a file is mapped in, the version
            in memory may not be identical to the disk version (due to recent writes to the virtual address
            space). However, when the file is unmapped or is explicitly flushed, the disk version is brought
            up-to-date.
            Windows 2000 explicitly allows two or more processes to map onto the same part of the same
            file at the same time, possibly at different virtual addresses, as shown in Figure 12.10. By reading
            and writing memory words, the processes can now communicate with each other and pass data
            back and forth at very high bandwidth, since no copying is required. Different processes may
            have different access permissions. Since all the processes using a mapped file share the same
            pages, changes made by one of them are immediately visible to all the others, even if the disk



                                             LOVELY PROFESSIONAL UNIVERSITY                                   361
   363   364   365   366   367   368   369   370   371   372   373