page table entries are 8 bytes (room for expansion, metadata) Virtual Memory (2) top 16 bits of address not used for translation bytes?? (512GB??) would take up page table entries are 8 bytes (room for expansion, metadata) exercise: how large are physical page numbers? exercise: how many page table entries? 4096 byte pages my desktop: 39-bit physical addresses; 48-bit virtual addresses exercise: 64-bit system 2 top 16 bits of address not used for translation bytes?? (512GB??) would take up exercise: how large are physical page numbers? 1 exercise: how many page table entries? 4096 byte pages my desktop: 39-bit physical addresses; 48-bit virtual addresses exercise: 64-bit system 1 condition on when we swap out 21 November 2017: swapping components: add “(if modifjed)” as memory regions between copies 21 November 2017: do we really need a complete copy?: even size of 21 November 2017: two-level example: answer was 0x0A not 0xBA value, not just location 21 November 2017: 1-level example: added fjnal answer of memory Changes made in this version not seen in fjrst lecture: Changelog 2
page table entries are 8 bytes (room for expansion, metadata) page table entries are 8 bytes (room for expansion, metadata) my desktop: 39-bit physical addresses; 48-bit virtual addresses 2 top 16 bits of address not used for translation 4096 byte pages my desktop: 39-bit physical addresses; 48-bit virtual addresses exercise: 64-bit system 2 top 16 bits of address not used for translation bytes?? (512GB??) would take up exercise: 64-bit system 3 bytes?? (512GB??) 4096 byte pages exercise: how many page table entries? exercise: how large are physical page numbers? would take up top 16 bits of address not used for translation 2 exercise: 64-bit system my desktop: 39-bit physical addresses; 48-bit virtual addresses 4096 byte pages exercise: how many page table entries? 2 48 / 2 12 = 2 36 entries exercise: how large are physical page numbers? 39 − 12 = 27 bits exercise: how many page table entries? 2 48 / 2 12 = 2 36 entries exercise: how large are physical page numbers? 39 − 12 = 27 bits page table entries are 8 bytes (room for expansion, metadata) would take up 2 39 bytes?? (512GB??)
exam and confmicts space on demand } 5 page table tricks page tables let operating systems do ‘magic’ with memory instead: change page tables and rerun memory access similar idea to trap-and-emulate 6 Used by OS for ( int j = ...) Program Memory Stack Heap / other dynamic Writable data Code + Constants used stack space (12 KB) wasted space? (huge??) OS would like to allocate space only if needed f(i + 1, j); f(i, j); fjnal exam 7 December 2017 for ( int j = ...) Gilmer 130 fjll out confmict form (today, please?) if you can’t make it linked ofg schedule also Collab announcement 4 rotate HW and cache blocking many of you seemed to think you were doing just loop unrolling… but generally changed the order of memory accesses in the process // unroll + cache blocking for ( int i = ...; i += 2) for ( int j = ...) { f(i + 0, j); f(i + 1, j); } // unroll loop in i only // (probably not very helpful) for ( int i = ...; i += 2) { 7 basically cache blocking key idea: OS doesn’t need to crash on a fault!
space on demand ... … … … page VPN %rsp = 0x7FFFC000 ... A: pushq %rbx // requires more stack space allocating space on demand 0 8 restarted then returns to retry the instruction OS updates the page table in exception handler, OS allocates more stack space page fault! OS looks up what’s should be there — “stack” hardware says “accessing address 0x7FFFBFF8 ” pushq triggers exception … 0x7FFFB --- … … restarted then returns to retry the instruction OS updates the page table in exception handler, OS allocates more stack space page fault! OS looks up what’s should be there — “stack” hardware says “accessing address 0x7FFFBFF8 ” pushq triggers exception … … 0x12345 0x7FFFC 1 0x7FFFF 0x12347 1 0x7FFFE 0x12340 1 0x7FFFD 0x200DF 1 Used by OS … 0x12345 Program Memory ... allocating space on demand 7 OS would like to allocate space only if needed wasted space? (huge??) used stack space (12 KB) Code + Constants Writable data Heap / other dynamic Stack Used by OS A: pushq %rbx space on demand 7 OS would like to allocate space only if needed wasted space? (huge??) used stack space (12 KB) Code + Constants Writable data Heap / other dynamic Stack Program Memory // requires more stack space 8 1 0 0x7FFFF 0x12347 1 0x7FFFE 0x12340 1 0x7FFFD 0x200DF 1 0x7FFFC --- 0x7FFFB … … … page VPN %rsp = 0x7FFFC000 ... valid? physical valid? physical B: movq 8(%rcx), %rbx B: movq 8(%rcx), %rbx C: addq %rbx, %rax C: addq %rbx, %rax
allocating space on demand deliberately make program trigger page/protection fault page fault! in exception handler, OS allocates more stack space OS updates the page table then returns to retry the instruction restarted 8 allocating space on demand note: the space doesn’t have to be initially empty only change: load from fjle, etc. instead of allocating empty page everything else can be handled in response to page faults no time/space spent loading/allocating unneeded space 9 page tricks generally but don’t assume page/protection fault is an error hardware says “accessing address 0x7FFFBFF8 ” have seperate data structures represent logically allocated memory e.g. “addresses 0x7FFF8000 to 0x7FFFFFFFF are the stack” might talk about Linux data structures later (book section 9.7) page table is for the hardware and not the OS 10 hardware help for page table tricks information about the address causing the fault e.g. special register with memory address accessed harder alternative: OS disassembles instruction, look at registers (by default) rerun faulting instruction when returning from exception precise exceptions: no side efgects from faulting instruction or after e.g. pushq that caused did not change %rsp before fault e.g. instructions reordered after faulting instruction not visible OS looks up what’s should be there — “stack” pushq triggers exception ... … // requires more stack space A: pushq %rbx ... %rsp = 0x7FFFC000 VPN page … … … 0x7FFFB 1 0x200D8 0x7FFFC 1 0x200DF … … 0x12345 1 0x7FFFF 11 0x12347 1 0x7FFFE 0x12340 1 0x7FFFD valid? physical B: movq 8(%rcx), %rbx loading program can be merely creating empty page table C: addq %rbx, %rax
swapping check where page actually is (from virtual address) historical reason why pages are as big as they are page fault handler is going switch to another program designed for writes/reads of kilobytes (not much smaller) SSD writes and writes: hundreds of microseconds writing tens of kilobytes basically as fast as writing 512 bytes minimum size: 512 bytes HDD reads and writes: milliseconds to tens of milliseconds HDD/SDDs are slow 14 copy to disk (if modifjed) OS marks as invalid in the page table(s) “swap out” a page eventually restart process read from disk OS gets page fault — invalid in page table our textbook presents virtual memory to support swapping “swap in” a page — exactly like allocating on demand! swapping components 13 common case that needs to be fast normal cache hits happen without OS replacement is managed by the OS every virtual page can be stored in any physical page fully associative swapping versus caching 12 DRAM is a cache for disk OS allocates space on disk using disk (or SSD, …) as the next level of the memory hierarchy 15 “cache block” ≈ physical page
loaded evicted program B pages fjrst step of replacement: mark evicted page invalid in page table other processes can run while reading page OS will get interrupt when disk is done process A’s page table updated and restarted from point of fault 16 swapping timeline … program A pages … HDD/SDDs are slow hopefully copy on disk is already up-to-date? page fault OS start read interrupt OS needs to choose page to replace hopefully copy on disk is already up-to-date? fjrst step of replacement: mark evicted page invalid in page table other processes can run while reading page OS will get interrupt when disk is done process A’s page table updated and restarted from point of fault program A OS needs to choose page to replace HDD reads and writes: milliseconds to tens of milliseconds page fault handler is going switch to another program minimum size: 512 bytes writing tens of kilobytes basically as fast as writing 512 bytes designed for writes/reads of kilobytes (not much smaller) page fault handler is going switch to another program historical reason why pages are as big as they are 15 HDD/SDDs are slow HDD reads and writes: milliseconds to tens of milliseconds minimum size: 512 bytes interrupt SSD writes and writes: hundreds of microseconds historical reason why pages are as big as they are … start read OS page fault program A program B pages program A pages … swapping timeline 15 16 writing tens of kilobytes basically as fast as writing 512 bytes SSD writes and writes: hundreds of microseconds designed for writes/reads of kilobytes (not much smaller) loaded evicted
Recommend
More recommend