1 / 26

VIRTUAL MEMORY MANAGEMENT

VIRTUAL MEMORY MANAGEMENT. DEMAND PAGING. Pages loaded on demand is known as demand paging Never bring a page into memory until it is required VM handler loads only one page of a program to start with. Three concepts are important in understanding operation of demand paging Page fault

jerod
Download Presentation

VIRTUAL MEMORY MANAGEMENT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VIRTUAL MEMORY MANAGEMENT

  2. DEMAND PAGING • Pages loaded on demand is known as demand paging • Never bring a page into memory until it is required • VM handler loads only one page of a program to start with. • Three concepts are important in understanding operation of demand paging • Page fault • Page in and page out • Page replacement

  3. Page fault • When a program tries to access locations that are not in memory, the hardware traps to operating system (page fault). • The operating system reads desired page into memory and restarts the process as though the page had always been in memory

  4. Steps handling page fault • Check the page table to determine whether the reference is valid or invalid memory access • If the reference was invalid, terminate the process. If it was valid, but have not yet brought in that page, page in the latter. • Find a free frame(from the free frame list) • schedule a disk operation to read the desired page into the newly allocated frame • When the disk read is complete, modify the internal table kept with the process and the page table to indicate that the page is now in memory. • Restart the instruction that was interrupted by the illegal address trap. The process can now access the page as though it had always been in memory

  5. Page In & Page Out • While initiating execution of a program, an area is allocated on the paging device for its legal address space and its code and data are copied into the space. This space is known as swap space of a program. • When a page fault occurs during reference to a page say Pi, the VM handler finds a free page frame in memory and loads Pi in it. This is known as Page In operation for Pi. • If no free frame exist in memory some page Pk existing in memory is written out into the swap space to free its page frame. This is a Page Out operation for Pk. • Page I/O. • The term Page Traffic is used to describe movements of pages in and out of memory.

  6. Page I/O Swap space of the program Pk Page being Written out Page out operation Pi Page being loadedin Page in operation • A program which encounters a page fault becomes blocked till • The required page is loaded in memory. Hence the execution • Performance of the program suffers

  7. Transfer of a Paged Memory to Contiguous Disk Space

  8. Valid-Invalid Bit • With each page table entry a valid–invalid bit is associated(v in-memory,i  not-in-memory) • Initially valid–invalid bit is set to i on all entries • Example of a page table snapshot:During address translation, if valid–invalid bit in page table entry is I  page fault Frame # valid-invalid bit v v v v i …. i i page table

  9. Page Table When Some Pages Are Not in Main Memory

  10. Page Fault • If there is a reference to a page, first reference to that page will trap to operating system: page fault • Operating system looks at another table to decide: • Invalid reference  abort • Just not in memory • Get empty frame • Swap page into frame • Reset tables • Set validation bit = v • Restart the instruction that caused the page fault

  11. Steps in Handling a Page Fault

  12. Page Replacement • Prevent over-allocation of memory by modifying page-fault service routine to include page replacement • Use modify (dirty) bitto reduce overhead of page transfers – only modified pages are written to disk • Page replacement completes separation between logical memory and physical memory – large virtual memory can be provided on a smaller physical memory

  13. Need For Page Replacement

  14. Basic Page Replacement • Find the location of the desired page on disk • Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select a victim frame • Bring the desired page into the (newly) free frame; update thepage and frame tables • Restart the process

  15. Page Replacement

  16. Page Replacement Algorithms • Want lowest page-fault rate • Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string • In all our examples, the reference string is 0100, 0432, 0101,0612,0102,0103,0104,0101,0611, 0102,0103,0104,0101,0610,0103,0104,0101,0609 100 bytes per page is reduced to following reference string 1,4,1,6,1,6,1,6,1,6

  17. Belady’s anomaly • It is found that under FIFO page replacement, certain page reference pattern cause more page faults when the number of page frames allocated to a process is increased • By Belady, Shedler and Nelson • This phenomenon is known as FIFO anomaly or Belady’s anomaly • Try doing the following eg: • Reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Page fault for 4 frames and 3 frames

  18. Graph of Page Faults Versus The Number of Frames

  19. First-In-First-Out (FIFO) Algorithm • Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 • 3 frames (3 pages can be in memory at a time per process) • 4 frames • Belady’s Anomaly: more frames  more page faults 1 1 4 5 2 2 1 3 9 page faults 3 3 2 4 1 1 5 4 2 2 1 10 page faults 5 3 3 2 4 4 3

  20. FIFO Page Replacement

  21. Optimal Algorithm • The principle of optimality states that to obtain optimum performance, replace the page that will not be used for a longest period of time • 4 frames example 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 • How do you know this? • Used for measuring how well your algorithm performs 1 4 2 6 page faults 3 4 5

  22. Optimal Page Replacement

  23. Least Recently Used (LRU) Algorithm • Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 • Counter implementation • Every page entry has a counter; every time page is referenced through this entry, copy the clock into the counter • When a page needs to be changed, look at the counters to determine which are to change 1 1 1 5 1 2 2 2 2 2 5 4 3 4 5 3 3 4 3 4

  24. LRU Page Replacement

  25. LRU Algorithm- using stack • Stack implementation – keep a stack of page numbers in a double link form: • Page referenced: • move it to the top • requires 6 pointers to be changed • No search for replacement

  26. Use Of A Stack to Record The Most Recent Page References

More Related