Lecture 10 - Virtual Memory Flashcards
What’s the solution to this problem:
Problem: Waste of memory, because a program only needs a small amount of memory at any given time
Virtual memory; a program can run with only some of its virtual address space in main memory
Explain the principle of locality of reference
The key principle is locality of reference, which recognizes that a significant percentage of memory accesses in a running program are made to a subset of its pages. Or simply put, a running program only needs access to a portion of its virtual address space at a given time.
With virtual memory, a logical (virtual) address translates to:
(3)
- Main memory (small but fast), or
- Paging device (large but slow), or
- None (not allocated, not used, free.)
What happens when an executing program references an address that is not in main memory?
The page table is extended with an extra bit, present. Initially, all the present bits are cleared (H/W and S/W).
While doing the address translation, the MMU checks to see if this bit is set. Access to a page whose present bit is not set causes a special hardware trap, called page fault (H/W).
When a page fault occurs the operating system brings the page into memory, sets the corresponding present bit, and restarts the execution of the instruction (S/W).
Explain how page fault handling works.
When a page fault occurs, the operating system:
- marks the current process as blocked (waiting for a page),
- finds an empty frame or make a frame empty in main memory,
- determines the location of the requested page on paging device,
- performs an I/O operation to fetch the page to main memory,
- triggers a “page fetched” event (e.g., special form of I/O completion interrupt) to wake up the process
Consider the following instruction:
Fetch (instruction);
decrement D0;
if D0 is zero, set PC to “Next” else increment PC.
What if the instruction itself and the address Next are on two different pages and the latter page was not in memory?
From where and how to restart the instruction? (give 3 solutions)
Page fault…
- Partial effects of the faulted instruction are undone and the instruction is restarted after servicing the fault (VAX-11/780)
- The instruction resumes from the point of the fault (IBM-370)
- Before executing an instruction make sure that all referenced addresses are available in the memory (for some instructions, CPU generates all page faults!)
What are 4 policies the operating system implements for virtual memory?
- Allocation—how much real memory to allocate to each (ready) program?
- Fetching—when to bring the pages into main memory?
- Placement—where in the memory the fetched page should be loaded?
- Replacement—what page should be removed from main memory?
What are the 3 conflicting requirements that Allocation policy deals with?
The fewer the frames allocated for a program, the higher the page fault rate.
The fewer the frames allocated for a program, the more programs can reside in memory; thus, decreasing the need of swapping.
Allocating additional frames to a program beyond a certain number results in little or only moderate gain in performance.
The number of allocated pages (also known as ___) can be fixed or can be variable during the execution of a program.
resident set size
fixed
variable
What are the 3 paging methods in Fetching policy?
- Demand paging (pure)
Start a program with no pages loaded; wait until it references a page; then load the page (this is the most common approach used in paging systems.) - Request paging
Similar to overlays, let the user identify which pages are needed (not practical, leads to over estimation and also user may not know what to ask for.) - Pre-paging
Start with one or a few pages pre-loaded. As pages are referenced, bring in other (not yet referenced) pages too.
What are overlays?
Additional modules that can be dynamically loaded when a program runs.
What are the 4 Replacement policies?
- FIFO—the frames are treated as a circular list; the oldest (longest resident) page is replaced.
- LRU—the frame whose contents have not been used for the longest time is replaced.
- OPT—the page that will not be referenced again for the longest time is replaced (prediction of the future; purely theoretical, but useful for comparison.)
- Random—a frame is selected at random.
Count the number of page faults in FIFO,
3 frames
Reference string
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
9
What’s Belady’s Anomaly?
Belady’s Anomaly:
in some cases more frames can result in more page faults rather than fewer!
Example: LRU algorithm
4 frames
Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
# page faults?
8 page faults
v
6 page faults