Lecture 18: Virtual Memory 2 Flashcards
Policy #1: First-In-First-Out (FIFO)
Idea: Replace the page that’s been in memory the longest
\+: Easy to implement, understand –: Ignores page usage Suffers from Belady’s Anomaly: Available frames Þhit ratio ¯ e.g.: 1 2 3 4 1 2 5 1 2 3 4 5 What is the hit ratio assuming: a. 3 available frames b. 4 available frames
Policy #2: Optimal
Evict the page that won’t be needed for the longest time
+: can’t get a better hit ratio than this gives
–: there is no way to know future memory references
Policy #3: Least Recently Used (LRU)
Idea:
approximates optimal by predicting that least recently used page is
one that won’t be used for longest time
“Locality”:
principle of program flow that says that consecutive memory references
tend to be close to each other (e.g.: code instructions, looping through
an array)
Policies #4+: Approximations of LRU
“4a. Reference Bits
• add “reference bit” column to page table
• initially, all bits set to 0
• reference to page p sets p’s reference bit to 1
• when all bits are 1, reset all to 0
• when replacing, choose any page with reference bit = 0”
“4b. Reference Bitstrings
• add n-bit column to page table
• initially, all bit strings = 00…0
• reference to page p sets rightmost bit of page p’s bit string to 1 e.g.: 01010010 ® 01010011
• after fixed amount of time, shift all bit strings to the left e.g.: 01010011 ® 10100110
® most assembly langs have “shift left”, “shift right” instructions for registers”
Policy #5: Least Frequently Used
- also tries to approximate optimal.
- predicts that page that will not be accessed for longest time in future is that which has been accessed the fewest time in past
- requires maintaining counter for all pages in page table
”+: reasonable approximation of optimal in some cases
–: requires counter field in page table
requires write of memory for every memory reference likely to evict pages just brought into memory
• less compatible with locality compared to LRU”
Local Allocation
Idea:
• assign a process some number of frames when it is created
• page fault requires evicting a page that the process owns
ISSUE: Thrashing
• must provide minimum frame allocation to each process (as
determined by instruction set). Otherwise, thrashing is
inevitable
Local Allocation +
a. Equitable allocation: Each process gets ëm/nû frames
• Problem: Suppose P1 needs 10 frames, P2 needs 190 frames, 60
are available
• Both get 30 frames and P1 has 20 frames that it doesn’t need, and
that P2 does need
b. Proportional allocation
P2: (190/200) ´ 60 = 57 frames
P1: (10/200) ´ 60 = 3 frames
c. Priority-based allocation
e.g.: Give P1 all 10 frames if it has a higher priority than P2
Global Allocation
Idea: all processes have access to all frames
replacement: a process can replace page owned by another
The Working-Set Model
• based on locality – as process executes, it uses a different set of pages
Working-Set Algorithm
Idea: Allocate enough frames to a process to fit the pages in its “current” locality
Page-Fault Frequency Scheme
Idea: Monitor page-fault rate of every active process. React accordingly
- if page fault rate > UB, allocate more frames
- if page fault rate < LB, deallocate frames
- may need to suspend process if cannot allocate more frames
- increase degree of multi programming if surplus”
Virtual memory
• permits logical address space > number of allocated frames
• permits higher degree of multiprogramming than pure paging
• performance concern: keep page fault frequency (r) low
à disk access :: memory access ~ 10,000 :: 1
page replacement
•essential tradeoff: low page fault frequency vs overhead to ensure
- per memory access (setting reference bits, time stamps…)
- periodic (SHL on reference bit strings)
- per page fault (scanning page table for page to evict)