Page 181 - DCAP103_Principle of operating system
P. 181

Principles of Operating Systems



                   Notes
                                 this value indicates that the associated page is both legal and in memory. If the bit is set to
                                 “invalid,” this value indicates that the page either is not valid (that is, not in the logical address
                                 space of the process), or is valid but is currently on the disk. The page-table entry for a page that
                                 is brought into memory is set as usual, but the page-table entry for a page that is not currently
                                 in memory is simply marked invalid, or contains the address of the page on disk. This situation
                                 is depicted in figure given below. Notice that marking a page invalid will have no effect if the
                                 process never attempts to access that page. Hence, if we guess right and page in all and only
                                 those pages that are actually needed, the process will run exactly as though we had brought in
                                 all pages. While the process executes and accesses pages that are memory resident, execution
                                 proceeds normally. But what happens if the process tries to access a page that was not brought
                                 into memory? Access to a page marked invalid causes a page-fault trap. The paging hardware,
                                 in translating the address through the page table, will notice that the invalid bit is set, causing
                                 a trap to the operating system. This trap is the result of the operating system’s failure to bring
                                 the desired page into memory (in an attempt to minimize disk-transfer overhead and memory
                                 requirements), rather than an invalid address error as a result of an attempt to use an illegal
                                 memory address (such as an incorrect array subscript). We must therefore correct this oversight.
                                 The procedure for handling this page fault is straightforward (Figure 5.24).


                                            Figure 5.24: Page Table when Some Pages are not in Main Memory


                                                                        0
                                                                        1
                                    0     A                             2
                                                          Valid- invalid
                                    1     B          frame    bit       3
                                    2     C                             4     A
                                                        0  4  v
                                    3     D             1     i         5
                                                        2  6  v         6     C                 A     B
                                    4     E
                                                        3     i
                                                                        7
                                    5     F             4     i                            C    D     E
                                                        5  9  v         8
                                    6     G
                                                        6     i                            F
                                                                        9     F
                                    7     H             7     i
                                                                       10
                                                        Page table
                                        Logical
                                       memory                          11
                                                                       12
                                                                       13
                                                                       14
                                                                       15
                                                                        Physical memory

                                    1.  We check an internal table (usually kept with the process control block) for this process,
                                      to determine whether the reference was a valid or invalid memory access.
                                    2.  If the reference was invalid, we terminate the process. If it was valid, but we have not yet
                                      brought in that page, we now page it in.
                                    3.  We find a free frame (by taking one from the free-frame list, for example).




        174                               LOVELY PROFESSIONAL UNIVERSITY
   176   177   178   179   180   181   182   183   184   185   186