Memory Management
1
Disclaimer: some slides are adopted from book authors’ slides with permission
Memory Management Disclaimer: some slides are adopted from book - - PowerPoint PPT Presentation
Memory Management Disclaimer: some slides are adopted from book authors slides with permission 1 Recap: Page Replacement On a page fault Step 1: allocate a free page frame If theres a free frame, use it If theres no free
1
Disclaimer: some slides are adopted from book authors’ slides with permission
2
– Evict the oldest page first. Pros: fair; Cons: can throw out frequently used pages
– Evict the page that will not be used for the longest period – Pros: optimal; Cons: you need to know the future
– Randomly choose a page. Pros: simple. TLB commonly uses this method; Cons: unpredictable
– Look at the past history, choose the one that has not been used for the longest period. Pros: good performance; Cons: complex, requires h/w support
3
4
Page Frame No V M R P 20 bits 2 1 1 1
– Step 1: advance the pointer by one – Step 2: check the reference bit of the page: 1 Used recently. Clear the bit and go to Step 1 0 Not used recently. Selected victim. End.
5
Reference E D H B D E D A E B E Page #1 E E E B B B B A A A A Page #2 D D Page #3 H Mark X for a fault X X X
6
7
Reference E D H B D E D A E B E Page #1 E E E B B B B A A A A Page #2 D D D * E E E * B B Page #3 H H H H D D D D E Mark X for a fault X X X X X X X X X
8
= (1 – p) x 200 + p x 8,000,000 = 200 + p x 7,999,800
EAT = 8.2 microseconds. This is a slowdown by a factor of 40!!
– 220 > 200 + 7,999,800 x p 20 > 7,999,800 x p – p < .0000025 – < one page fault in every 400,000 memory accesses
9
10
11
12
Bash text Physical memory Bash #1 Bash #2
13
14
15
16
parent child
17
parent child
18
Page Frame No V M R P 20 bits 2 1 1 1
19
parent child RO RO RO Page tbl RO RO RO Page tbl
20
parent child RO RO RW Page tbl RO RO RO Page tbl
21
22
23
4KB 8KB 16KB 32KB
24
32 A 32 Free 64 Free 128 Free 32 Free 64 Free 128 Free 32 Free 64 Free 128 Free 64 Free 128 Free 128 Free 256 Free
25
32 A 32 Free 64 Free 128 Free 32 Free 64 Free 128 Free 32 Free 64 Free 128 Free 64 Free 128 Free 128 Free 256 Free
26
27
2nd level
8 bits 8 bits
1st level
8 bits Virtual address format (24bits) Frame #
V
4 bits 3
Unused
1 Page table entry (8bit)
Addr +0 +1 +2 +3 +4 +5 +6 +7 +8 +A +B +C +D +E +F 0x000 31 0x010 0x020 41 .. 0x100 00 01 01 00 01 .. 0x200
Page-table base address = 0x100 Vaddr: 0x0703FE Paddr: 0x3FE Vaddr: 0x072370 Paddr: ??? Vaddr: 0x082370 Paddr: ???
28
2nd level
8 bits 8 bits
1st level
8 bits Virtual address format (24bits) Frame #
V
4 bits 3
Unused
1 Page table entry (8bit)
Addr +0 +1 +2 +3 +4 +5 +6 +7 +8 +A +B +C +D +E +F 0x000 31 0x010 0x020 41 .. 0x100 00 01 01 00 01 .. 0x200
Page-table base address = 0x100 Vaddr: 0x0703FE Paddr: 0x3FE Vaddr: 0x072370 Paddr: 0x470 Vaddr: 0x082370 Paddr: invalid