1 / 23

Virtual memory

Virtual memory. What is program size>memory available?. Load only the parts of the memory that is needed Do bookkeeping When accessing, make sure that that part of the program is in memory; if not in memory, replace some part by the needed part This is called overlay. Demand paging.

keiran
Download Presentation

Virtual memory

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

  2. What is program size>memory available? • Load only the parts of the memory that is needed • Do bookkeeping • When accessing, make sure that that part of the program is in memory; if not in memory, replace some part by the needed part • This is called overlay

  3. Demand paging • Maintain two tables • Page map table • same as before (add a column: valid) • File map table • For each page i, this table tells where in disk the page is available

  4. Address translation • When converting page number into frame number, check if that valid bit is 1 (means the page is in memory) • If valid bit is 0, it means the page is not in memory (page fault). Now, bring the page from disk into main memory

  5. Policies • Allocation • Fetch • Replacement

  6. Allocation policies • Static allocation • The number of frames allocated to a program does not change when it executes • Dynamic allocation • The number frames allocated to the program changes with time

  7. Fetch policy • Prefetch • Fetch a page from disk before it is needed • Demand fetch: • Fetch a page from disk only when it is needed.

  8. Replacement policy • When no free frame is available and we have a page fault, one of that process’s pages will have to be replaced. • Which page will be replaced?

  9. Three replacement policies • FIFO • LRU • Belady’s optimal

  10. Basis for comparison • Execution time page trace (ETPT) = sequence of pages referenced when a program executes • Reference string w = replace consecutive identical pages numbers by one occurrence • ETPT = 1223343334456 • Corresponding reference string = 12343456

  11. Belady’s optimal rule • Replace the page that will not be needed for the longest time in the future

  12. FIFO • Exhibits anomaly (when the number of frames allocated increases, the page fault rate increases) • Replace the page in the First in First Out manner. (use a queue data structure)

  13. Least Recently Used (LRU) • Replace the page that has not been referenced for the longest time in the past • LRU does not exhibit anomaly • Variations of this are used in practice

  14. Implementation of LRU • Exact implementation is very expensive • Use approximation algorithms

  15. Approximation algorithms • 1. Clock algorithm • Maintain two bits (r,w) per page in mamory • r bit is set to 1 every time is referenced • w bit is set to 1 every time the page is written • periodically, set all r bits to 0 • Replace the page if the two bits are (0,0) • Else look for page with (0,1) or (1,0)

  16. Approximation 2 • Maintain a long bit string (1 bit per page of the program) • Set bit i when page i is referenced • Periodically, save the bit string in a circular buffer and clear all the bits • At time of page fault, choose the page to be replaced based on its bit values in the strings

  17. Thrashing • When we allocate too few frames to a process, the page fault rate is very high (low CPU utilization) • When too many frames are allocated, fewer programs will be accommodated

  18. Demand paging in Unix • Conditions • Memory architecture allows paging • Kernel implements a paging policy • Restartable execution is possible • execute part of an instruction, page fault and restar

  19. Page [map] Table • Contents: • Physical address of page • Protection bits (r/w/x) • 5 bit fields to support demand paging • valid (1=contents valid) • reference (1= recently referenced) • modify (dirty bit) • copy on write • age

  20. Free Frames • The kernel maintains a supply of free frames in two lists (to be allocated to programs when there is a page fault) • a free list (FIFO list) • a hash list (for finding if a process’s page, after page fault on that page, is in free list • Allocate free frames from the free list

  21. Page Stealer Process • Swaps out pages (frames) that are no longer part of the process’s working set • Created during system initialization and invoked whenever the number of free frames is low

  22. Stealer process • Clear the reference bit of each page • Remember how many passes were made since the last time the page was accessed • When a threshold value is reached, make the page ``ready to swap out.’’ and add to free list

  23. Stealer Process • Page stealer is waken up by the kernel when available free frames is lower than a threshold • Page stealer swaps out pages until the number of frames in the free list is larger than a threshold • The threshold is implementation dependent.

More Related