u niversity of m assachusetts a mherst department of computer science computer systems principles...
DESCRIPTION
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Memory Pages Programs use memory as individual bytes OS manages groups of bytes: pages –typically 4kB, 8kB –Why? (think Tetris with all squares) –Applies this to virtual and physical memory Physical pages usually called frames ATRANSCRIPT
![Page 1: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/1.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Computer Systems PrinciplesVirtual Memory & Paging
Emery Berger and Mark CornerUniversity of Massachusetts
Amherst
![Page 2: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/2.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 2
Virtual vs. Physical Memory Apps don’t access physical memory
– Well, not directly Apps use virtual memory
– Addresses start at 0– One level of indirection– Address you see is not “real” address
Any ideas why?
![Page 3: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/3.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Memory Pages Programs use memory as individual bytes OS manages groups of bytes: pages
– typically 4kB, 8kB– Why? (think Tetris with all squares)– Applies this to virtual and physical memory
• Physical pages usually called frames
A
![Page 4: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/4.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 4
Mapping Virtual to Physical
Note this is simplified and the data here includes the heap, not the typical data segment…
![Page 5: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/5.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 5
Why Virtual Memory? Why?
– Simpler• Everyone gets illusion
of whole address space
– Isolation• Every process
protected from every other
– Optimization • Reduces space
requirements
![Page 6: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/6.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Typical Virtual Memory Layout Some things grow
– Must leave room! Mmap and heap spaces
– Mmap increases mmap– Brk increases heap
Other layouts possible
![Page 7: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/7.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Quick Quiz! Are arrays contiguous in memory?
– Physical memory?– Virtual memory?
Where does the code for a program live?
![Page 8: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/8.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Memory Management Unit Programs issue loads and stores What kind of addresses are these? MMU Translates virtual to physical addresses
– Maintains page table (big hash table):– Almost always in HW… Why?
MMU
Physical
Address
Virtual Addres
sProgra
mMemor
y
Page Table
![Page 9: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/9.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Page Tables Table of translations
– virtual pages -> physical pages One page table per process One page table entry per virtual page How?
– Programs issue virtual address– Find virtual page (how?)– Lookup physical page, add offset
![Page 10: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/10.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Page Table Entries Do all virtual pages -> physical page?
– Valid and Invalid bits PTEs have lots of other information
– For instance some pages can only be read
![Page 11: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/11.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 11
Address Translation Powers of 2:
– Virtual address space: size 2^m– Page size 2^n
Page#: High m-n bits of virtual address Lower n bits select offset in page
![Page 12: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/12.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Quick Activity How much mem does a page table need?
– 4kB pages, 32 bit address space– page table entry (PTE) uses 4 bytes
2^32/2^12*4=2^22 bytes=4MB– Is this a problem?– Isn’t this per process?– What about a 64 bit address space?
Any ideas how to fix this?
![Page 13: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/13.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Multi-Level Page Tables Use a multi-level page table
A A
A
Level 0 Table
Level 1 Table
Level 1 Table
![Page 14: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/14.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Quick Activity How much mem does a page table need?
– 4kB pages, 32 bit address space– Two level page table– 20bits = 10 bits each level– page table entry (PTE) uses 4 bytes– Only first page of program is valid
2^10*4+2^10*4=2^13 bytes=8kB
Isn’t this slow?
![Page 15: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/15.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 15
Translation Lookaside Buffer (TLB) TLB: fast, fully associative memory
– Caches page table entries– Stores page numbers (key) and frame (value)
in which they are stored Assumption: locality of reference
– Locality in memory accesses =locality in address translation
TLB sizes: 8 to 2048 entries– Powers of 2 simplifies translation
of virtual to physical addresses
![Page 16: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/16.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Virtual Memory is an Illusion! How much memory does a process have?
– Do all processes have this? Key idea: use RAM as cache for disk
– OS transparently moves pages Requires locality:
– Working set must fit in RAM• memory referenced recently
– If not: thrashing (nothing but disk traffic)
![Page 17: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/17.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 17
Paging
![Page 18: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/18.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 18
A
B
AB
Paging + Locality Most programs obey
90/10 “rule”– 90% of time spent
accessing 10% of memory
Exploit this rule:– Only keep “live” parts
of process in memory
![Page 19: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/19.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 19
Key Policy Decisions Two key questions: (for any cache):
– When do we read page from disk?– When do we write page to disk?
![Page 20: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/20.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 20
Reading Pages Read on-demand:
– OS loads page on its first reference– May force an eviction of page in RAM– Pause while loading page = page fault
Can also perform pre-paging:– OS guesses which page will next be needed,
and begins loading it Most systems just do demand paging What about writes?
![Page 21: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/21.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 21
Demand Paging On every reference, check if page is in memory
(resident bit in page table)– Who is doing this?
If not: trap to OS– How does this work in HW?
OS:– Selects victim page to be replaced– Writes victim page if necessary, marks non-resident– Begins loading new page from disk– OS can switch to another process
![Page 22: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/22.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 22
Swap Space Swap space = where victim pages go
– Partition or special file reserved on disk
Size of reserved swap space limits what?
![Page 23: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/23.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Tricks with Page Tables Do all pages of memory end up in swap? Parts of address space mapped into files
– see man pages for mmap
![Page 24: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/24.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 24
Overview A Day in the Life of a Page
– Allocation– Use– Eviction– Reuse
Terms: Resident and Non-resident
![Page 25: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/25.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
char * x = new char[16];
25
virtual memory layout
Allocate some memory
0x40001000
0x40001040 → 0x4000104F
A Day in the Life of a Page
![Page 26: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/26.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
char * x = new char[16];
26
virtual memory layout
Update page tables
0x40001000
0x40001040 → 0x4000104F
physicalmemory
layout
A Day in the Life of a Page
![Page 27: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/27.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
strcpy(x, “hello”);
27
virtual memory layout
Write contents – dirty page
0x40001000
0x40001040 → 0x4000104F
physicalmemory
layout
A Day in the Life of a Page
![Page 28: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/28.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 28
virtual memory layout
Other processes fill up memory…
physicalmemory
layout
A Day in the Life of a Page
![Page 29: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/29.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 29
virtual memory layout
Forcing our page to be evicted (paged out)
physicalmemory
layout
swapspace(disk)
A Day in the Life of a Page
![Page 30: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/30.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 30
virtual memory layout
Now page nonresident & protected
physicalmemory
layout
swapspace(disk)
A Day in the Life of a Page
![Page 31: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/31.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
y[0] = x[0];
31
virtual memory layout
Touch page – swap it in
0x40001000
0x40001040 → 0x4000104F
physicalmemory
layout
swapspace(disk)
A Day in the Life of a Page
![Page 32: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/32.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
y[0] = x[0];
32
virtual memory layout
Touch page – swap it in
0x40001000
0x40001040 → 0x4000104F
physicalmemory
layout
swapspace(disk)
A Day in the Life of a Page
![Page 33: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/33.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 33
Tricks with Page Tables: Sharing Paging allows sharing
of memory across processes– Reduces memory
requirements Shared stuff includes
code, data– Code typically R/O
![Page 34: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/34.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Tricks with Page Tables: COW Copy on write (COW)
– Just copy page tables– Make all pages read-only
What if process changes mem?
All processes are created this way!
![Page 35: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/35.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science
Allocating Pages ultimately from sbrk or mmap Sbrk increases # of valid pages
– Increases the heap Mmap maps address space to file
– Increases the mmap space Oddity:
– Allocators can use either mmap or brk to get pages– You will use mmap
What does mmap /dev/zero mean?– Think about COW
![Page 36: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/36.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 36
Overview
Replacement policies– Comparison
![Page 37: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/37.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 37
A, B, C, D, E, F, G, H, I, J, A...
size of available memory
Cost of Paging Usually in algorithms, we pick algorithm
with best asymptotic worst-case– Paging: worst-case analysis useless!– Easy to construct adversary:
every page requires page fault
![Page 38: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/38.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 38
A A, B, C, D, E, F, G, H, I, J, A...
size of available memory
Cost of Paging Worst-case analysis – useless
– Easy to construct adversary example:every page requires page fault
![Page 39: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/39.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 39
A B A, B, C, D, E, F, G, H, I, J, A...
size of available memory
Cost of Paging Worst-case analysis – useless
– Easy to construct adversary example:every page requires page fault
![Page 40: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/40.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 40
A B C A, B, C, D, E, F, G, H, I, J, A...
size of available memory
Cost of Paging Worst-case analysis – useless
– Easy to construct adversary example:every page requires page fault
![Page 41: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/41.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 41
A B C D A, B, C, D, E, F, G, H, I, J, A...
size of available memory
Cost of Paging Worst-case analysis – useless
– Easy to construct adversary example:every page requires page fault
![Page 42: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/42.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 42
A B C D E A, B, C, D, E, F, G, H, I, J, A...
size of available memory
Cost of Paging Worst-case analysis – useless
– Easy to construct adversary example:every page requires page fault
![Page 43: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/43.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 43
F B C D E A, B, C, D, E, F, G, H, I, J, A...
size of available memory
Cost of Paging Worst-case analysis – useless
– Easy to construct adversary example:every page requires page fault
![Page 44: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/44.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 44
F G H I J A, B, C, D, E, F, G, H, I, J, A...
size of available memory
Cost of Paging Worst-case analysis – useless
– Easy to construct adversary example:every page requires page fault
![Page 45: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/45.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 45
Optimal Replacement (MIN/OPT) Evict page accessed furthest in future
– Optimal page replacement algorithm• Invented by Belady (“MIN”), a.k.a. “OPT”
Provably optimal policy– Just one small problem...
Requires predicting the future– Useful point of comparison
• How far from optimal
![Page 46: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/46.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 46
sequence of page accesses
contents of page frames
Quick Activity: OPT
Page faults: 5
![Page 47: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/47.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 47
Least-Recently Used (LRU) Evict page not used in longest time
(least-recently used)– Approximates OPT
• If recent past ≈ predictor of future– Variant used in all real operating systems
![Page 48: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/48.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 48
Quick Activity: LRU example
Page faults: ?
![Page 49: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/49.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 49
LRU example
Page faults: 5
![Page 50: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/50.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 50
LRU, example II
Page faults: ?
![Page 51: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/51.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 51
LRU, example II
Page faults: 12!– Loop: well-known worst-case for LRU
![Page 52: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/52.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 52
A, B, C, D, A, B, C, D, ...
size of available memory
Most-Recently Used (MRU) Evict most-recently used page Shines for LRU’s worst-case: loop that exceeds RAM size
![Page 53: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/53.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 53
A A, B, C, D, A, B, C, D, ...
size of available memory
Most-Recently Used (MRU) Evict most-recently used page Shines for LRU’s worst-case: loop that exceeds RAM size
![Page 54: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/54.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 54
A B A, B, C, D, A, B, C, D, ...
size of available memory
Most-Recently Used (MRU) Evict most-recently used page Shines for LRU’s worst-case: loop that exceeds RAM size
![Page 55: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/55.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 55
A B C A, B, C, D, A, B, C, D, ...
size of available memory
Most-Recently Used (MRU) Evict most-recently used page Shines for LRU’s worst-case: loop that exceeds RAM size
![Page 56: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/56.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 56
A B D A, B, C, D, A, B, C, D, ...
size of available memory
Most-Recently Used (MRU) Evict most-recently used page Shines for LRU’s worst-case: loop that exceeds RAM size
![Page 57: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/57.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 57
A B D A, B, C, D, A, B, C, D, ...
size of available memory
Most-Recently Used (MRU) Evict most-recently used page Shines for LRU’s worst-case: loop that exceeds RAM size
![Page 58: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/58.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 58
A B D A, B, C, D, A, B, C, D, ...
size of available memory
Most-Recently Used (MRU) Evict most-recently used page Shines for LRU’s worst-case: loop that exceeds RAM size
![Page 59: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/59.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 59
A B D A, B, C, D, A, B, C, D, ...
size of available memory
Most-Recently Used (MRU) Evict most-recently used page Shines for LRU’s worst-case: loop that exceeds RAM size
![Page 60: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/60.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 60
FIFO First-in, first-out: evict oldest page As competitive as LRU, but
performs miserably in practice!– Ignores locality– Suffers from Belady’s anomaly:
• More memory can mean more paging!– LRU & similar algs. do not
• Stack algorithms – more memory means ≥ hits
![Page 61: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/61.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 61
Virtual Memory in Reality Implementing exact LRU Approximating LRU
– Hardware Support– Clock– Segmented queue
Multiprogramming– Global LRU– Working Set
![Page 62: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/62.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 62
A, B, C, B, C, C, D
Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page
= least-recently used
![Page 63: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/63.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 63
A1 A, B, C, B, C, C, D
Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page
= least-recently used
![Page 64: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/64.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 64
A1
B2 A, B, C, B, C, C, D
Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page
= least-recently used
![Page 65: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/65.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 65
A1
B2
C3 A, B, C, B, C, C, D
Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page
= least-recently used
![Page 66: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/66.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 66
A1
B4
C3 A, B, C, B, C, C, D
Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page
= least-recently used
![Page 67: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/67.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 67
A1
B4
C5 A, B, C, B, C, C, D
Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page
= least-recently used
![Page 68: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/68.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 68
A1
B4
C6 A, B, C, B, C, C, D
Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page
= least-recently used
![Page 69: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/69.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 69
A1
B4
C6 A, B, C, B, C, C, DD
7
LRU page
How should we implement this?
Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page
= least-recently used
![Page 70: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/70.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 70
Implementing Exact LRU Could keep pages in order
– optimizes eviction– Priority queue:
update = O(log n), eviction = O(log n)
Optimize for common case!– Common case: hits, not misses– Hash table:
update = O(1), eviction = O(n)
![Page 71: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/71.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 71
Cost of Maintaining Exact LRU Hash tables: too expensive
– On every reference:• Compute hash of page address• Update time stamp
– Unfortunately: 10x – 100x more expensive!
![Page 72: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/72.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 72
Cost of Maintaining Exact LRU Alternative: doubly-linked list
– Move items to front when referenced– LRU items at end of list– Still too expensive
• 4-6 pointer updates per reference
Can we do better?
![Page 73: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/73.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 73
Virtual Memory in Reality Implementing exact LRU Approximating LRU
– Hardware Support– Clock– Segmented queue
Multiprogramming– Global LRU– Working Set
![Page 74: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/74.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 74
A1
B1
C1 A, B, C, B, C, C, D
Hardware Support Maintain reference bits for every page
– On each access, set reference bit to 1– Page replacement algorithm periodically
resets reference bits
![Page 75: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/75.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 75
A0
B0
C0 A, B, C, B, C, C, D
reset reference bits
Hardware Support Maintain reference bits for every page
– On each access, set reference bit to 1– Page replacement algorithm periodically
resets reference bits
![Page 76: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/76.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 76
A0
B1
C0 A, B, C, B, C, C, D
Hardware Support Maintain reference bits for every page
– On each access, set reference bit to 1– Page replacement algorithm periodically
resets reference bits
![Page 77: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/77.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 77
A0
B1
C1 A, B, C, B, C, C, D
Hardware Support Maintain reference bits for every page
– On each access, set reference bit to 1– Page replacement algorithm periodically
resets reference bits
![Page 78: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/78.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 78
A0
B1
C1 A, B, C, B, C, C, D
Hardware Support Maintain reference bits for every page
– On each access, set reference bit to 1– Page replacement algorithm periodically
resets reference bits
![Page 79: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/79.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 79
A0
B1
C1 A, B, C, B, C, C, DD
1
Hardware Support Maintain reference bits for every page
– On each access, set reference bit to 1– Page replacement algorithm periodically
resets reference bits– Evict page with reference bit = 0
–
Cost per miss = O(n)
![Page 80: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/80.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 80
Virtual Memory in Reality Implementing exact LRU Approximating LRU
– Hardware Support– Clock– Segmented queue
Multiprogramming– Global LRU– Working Set
![Page 81: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/81.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 81
B1
C1
A1
D1
A, B, C, D, B, C, E, F, C, G
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 82: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/82.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 82
B1
C1
A1
D1
A, B, C, D, B, C, E, F, C, G
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 83: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/83.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 83
B1
C1
A1
D1
A, B, C, D, B, C, E, F, C, G
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 84: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/84.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 84
B1
C1
A0
D1
A, B, C, D, B, C, E, F, C, G
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 85: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/85.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 85
B0
C1
A0
D1
A, B, C, D, B, C, E, F, C, G
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 86: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/86.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 86
B0
C0
A0
D1
A, B, C, D, B, C, E, F, C, G
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 87: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/87.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 87
B0
C0
A0
D0
A, B, C, D, B, C, E, F, C, G
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 88: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/88.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 88
B0
C0
A0
D0
A, B, C, D, B, C, E, F, C, G
E1
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 89: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/89.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 89
B0
C0
A0
D0
A, B, C, D, B, C, E, F, C, G
E0
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 90: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/90.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 90
B0
C0
A0
D0
A, B, C, D, B, C, E, F, C, G
E0
F1
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 91: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/91.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 91
B0
C0
A0
D0
A, B, C, D, B, C, E, F, C, G
E0
F1
C1
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 92: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/92.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 92
B0
C0
A0
D0
A, B, C, D, B, C, E, F, C, G
E0
F0
C1
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 93: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/93.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 93
B0
C0
A0
D0
A, B, C, D, B, C, E, F, C, G
E0
F0
C1C0
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 94: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/94.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 94
B0
C0
A0
D0
A, B, C, D, B, C, E, F, C, G
E0
F0
C1C0
G1
The Clock Algorithm Variant of FIFO & LRU Keep frames in circle On page fault, OS:
– Checks reference bit of next frame
– If reference bit = 0, replace page, set bit to 1
– If reference bit = 1, set bit to 0, advance pointer to next frame
![Page 95: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/95.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 95
clock exact LRU
Segmented Queue Real systems: segment queue into two
– approximate for frequently-referenced pages• e.g., first 1/3 page frames – fast
– exact LRU for infrequently-referenced pages• last 2/3 page frames; doubly-linked list – precise
How do we move between the two?
![Page 96: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/96.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 96
Enhancing Clock Recall: don’t write back unmodified pages
– Idea: favor eviction of unmodified pages– Extend hardware to keep another bit:
modified bit Total order of tuples: (ref bit, mod bit)
– (0,0), (0,1), (1,0), (1,1)– Evict page from lowest nonempty class
![Page 97: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/97.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 97
Replacement, Enhanced Clock OS scans at most three times
– Page (0,0) – replace that page– Page (0,1) – write out page, clear mod bit– Page (1,0), (1,1) – clear reference bit
Passes:– all pages (0,0) or (0,1)– all pages (0,1) - write out pages– all pages (0,0) – replace any page
Fast, but still coarse approximation of LRU
![Page 98: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/98.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 98
Multiprogramming & VM Multiple programs compete for memory
– Processes move memory from and to disk– Pages needed by one process may get
squeezed out by another process– thrashing - effective cost of memory access
= cost of disk access = really really bad Must balance memory across processes
– avoid thrashing
![Page 99: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/99.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 99
Global LRU Put all pages from all procs in one pool
– Manage with LRU (Segmented Queue)– Used by Linux, BSD, etc.
Advantages:– Easy
Disadvantages:– Many
![Page 100: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/100.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 100
Global LRU Disadvantages No isolation between processes
– One process touching many pages can force another process’ pages to be evicted
Priority ignored, or inverted– All processes treated equally
Greedy (or wasteful) processes rewarded– Programs with poor locality squeeze out
those with good locality– Result: more page faults
![Page 101: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/101.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 101
Global LRU Disadvantages “Sleepyhead” problem
– Intermittent, important process– Every time it wakes up – no pages! – back to sleep...– Think ntpd
Susceptible to denial of service– Non-paying “guest”, lowest priority, marches over
lots of pages – gets all available memory
Alternatives?– Pinning?
![Page 102: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/102.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 102
Working Set Denning: Only run processes whose
working set fits in RAM– Other processes: deactivate (suspend)
Classical definition:working set = pages touched in last references
Provides isolation– Process’s reference behavior only affects
itself
![Page 103: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/103.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 103
Working Set Problems Algorithm relies on key parameter,
– How do we set ?– Is there one correct ?
• Different processes have different timescales over which they touch pages
Not acceptable (or necessarily possible) to suspend processes altogether
Not really used– Very rough variant used in Windows
![Page 104: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/104.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 104
![Page 105: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/105.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 105
Solution: CRAMM New VM management alg:
Cooperative Robust Automatic Memory Management[OSDI 2006, Yang et al.]
Redefine working set size =pages required to spend < n% time paging– CRAMM default = 5%
![Page 106: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/106.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 106
d e f g h i j k l m n c k l m ncb c d e f g h i j k l m n c k l m n
aba abc defghijklmn abc defghijklm n abdefghijckl n m abc defghijk mn l abc defghijlmn k abdefghijklmn c
4
n
321 1
Memory reference sequence
LRU QueuePages in Least Recently
Used order
Hit Histogram
Fault Curve
0000000000 0000
m n
1 14
l m nk l m nc k l m na b c d e f g h i j k l m n c k l m n
5
1
1 14114
Associated with each LRU position
pages
faults
Calculating WSS w.r.t 5%
[ ]∑∞
+=i
i ihistfault 1
![Page 107: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/107.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 107
Computing hit histogram Not possible in standard VM:
– Global LRU queues– No per process/file information or control
• Difficult to estimate app’s WSS / available memory
CRAMM VM:– Per process/file page management:
• Page list: Active, Inactive, Evicted• Add & maintain histogram
![Page 108: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/108.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 108
Active (CLOCK) Inactive (LRU) Evicted (LRU)
Major fault
EvictedRefill & Adjustment
Minor fault
Pages protected by turning off permissions (minor fault)
Pages evicted to disk. (major fault)
Header
Page Des
AVL node
Histogram Pages
faults
Managing pages per process
![Page 109: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/109.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 109
Buffer
Active (CLOCK) Inactive (LRU) Evicted (LRU)
Pages protected by turning off permissions (minor fault)
Pages evicted to disk. (major fault)
Header
Page Des
AVL node
Histogram Pages
faults
control the boundary: 1% of execution time
Controlling overhead
![Page 110: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/110.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 110
Competitive Analysis I removed this slide because I don’t get it. This is
the worst case analysis…
Instead of worst-case, Compare replacement policy (OPT)– How much worse is algorithm than optimal?
Result: LRU & FIFO both “k-competitive”– k = size of queue– Can incur k times more misses than OPT
![Page 111: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/111.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 111
FIFO & Belady’s Anomaly
![Page 112: U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner](https://reader034.vdocument.in/reader034/viewer/2022051405/5a4d1b637f8b9ab0599ae61b/html5/thumbnails/112.jpg)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTS ASSACHUSETTS AAMHERST • MHERST • Department of Computer Science Department of Computer Science 112
LRU: No Belady’s Anomaly
Why no anomaly for LRU?