Page 372 - DCAP103_Principle of operating system
P. 372

Unit 12: Processes and Threads in Windows



            The most important bits in the page table entry for purposes of the paging algorithm are the A   Notes
            and D bits. They are fed by the hardware and keep track of whether the page has been referenced
            or written on, respectively, since the last time they were cleared.

            Page faults come in five categories:
               1.  The page referenced is not committed.
               2.  A protection violation occurred.

               3.  A shared page has been written.
               4.  The stack needs to grow.
               5.  The page referenced is committed but not currently mapped in.

            The first and second cases are fatal errors from which there is no recovery for the faulting process.
            The third case has the same symptoms as the second one (an attempt to write to a read-only
            page), but the treatment is different. The solution is to copy the page to a new physical page
            frame and map the same in read/write. This is how copy-on-write works. (If a shared page is
            marked writable in all the processes using it, it is not copy-on-write and no fault occurs when
            writing to it.) The fourth case requires allocating a new page frame and mapping in it. However,
            the security rules require that the page contain only 0s, to prevent the process from snooping
            on the previous owner of the page. Thus a page of 0s must be found, or if one is not available,
            another page frame must be allocated and zeroed on the spot. Finally, the fifth case is a normal
            page fault where page is located and mapped in.

            The actual mechanics of getting and mapping pages is fairly standard, so we will not discuss
            this issue. The only noteworthy feature is that Windows 2000 does not read in isolated pages
            from the disk. Instead, it reads in runs of consecutive pages, usually about 1-8 pages, in
            an attempt to minimize the number of disk transfers. The run size is larger for code pages
            than for data pages.

            12.3.5 Page Replacement Algorithm
            Page replacement works like this. The system makes a serious attempt to maintain a substantial
            number of free pages in the memory so that when a page fault occurs, a free page can be claimed
            on the spot, without the need to first write some other page to disk. As a consequence of this
            strategy, most page faults can be satisfied with at most one disk operation (reading in the page),
            rather than sometimes two (writing back a dirty page and then reading in the needed page).
            Of course, the pages on the free list have to come from somewhere, so the real page replacement
            algorithm is how pages get taken away from processes and put on the free list (actually, there
            are four free lists, but for the moment it is simplest to think of there being just one; we will
            come to the details later). Let us now have a look at how Windows 2000 frees pages. To start
            with, the entire paging system makes heavy use of the working set concept. Each process (not
            each thread) has a working set. This set consists of the mapped-in pages that are in memory
            and can be thus referenced without a page fault. The size and composition of the working set
            fluctuates as the process’ threads run, of course.

            Each process’ working set is described by two parameters: the minimum size and the maximum
            size. Every process starts with the same minimum and maximum, but these bounds can change
            over time. The default initial minimum is in the range 20-50 and the default initial maximum
            is in the range 45-345, depending on the total amount of RAM. The system administrator can
            change these defaults, however.





                                             LOVELY PROFESSIONAL UNIVERSITY                                   365
   367   368   369   370   371   372   373   374   375   376   377