1 last time
play

1 last time page table review virtual to physical translation - PowerPoint PPT Presentation

1 last time page table review virtual to physical translation two-level page tables how xv6 manages page tables walkpgdir , mappages , etc. x86-32 page table format xv6 memory layout high memory for the kernel, mapping everything


  1. 1

  2. last time page table review virtual to physical translation two-level page tables how xv6 manages page tables walkpgdir , mappages , etc. x86-32 page table format xv6 memory layout high memory for the kernel, mapping everything virtual-to-physical/phyiscal-to-virtual utility functions sbrk to determine end of user memory page fault handling 2

  3. xv6 page faults (now) err special register CR2 contains faulting address 14 = T_PGFLT proc\n", 0x%x--kill addr 0x%x "eip " %d cpu fault from accessing page table entry marked ‘not-present’ on %d 3 cprintf("pid %d xv6: prints an error and kills process: trap *(( int *) 0x800444) = 1; %s: ... %d /* in trap.c: */ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ myproc() − >pid, myproc() − >name, tf − >trapno, tf − >err, cpuid(), tf − >eip, rcr2()); myproc() − >killed = 1; pid 4 processname: trap 14 err 6 on cpu 0 eip 0x1a addr 0x800444 −− kill proc

  4. xv6 page faults (now) err special register CR2 contains faulting address 14 = T_PGFLT proc\n", 0x%x--kill addr 0x%x "eip " %d cpu fault from accessing page table entry marked ‘not-present’ on %d 3 cprintf("pid %d xv6: prints an error and kills process: trap *(( int *) 0x800444) = 1; %s: ... %d /* in trap.c: */ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ myproc() − >pid, myproc() − >name, tf − >trapno, tf − >err, cpuid(), tf − >eip, rcr2()); myproc() − >killed = 1; pid 4 processname: trap 14 err 6 on cpu 0 eip 0x1a addr 0x800444 −− kill proc

  5. xv6 page faults (now) err special register CR2 contains faulting address 14 = T_PGFLT proc\n", 0x%x--kill addr 0x%x "eip " %d cpu fault from accessing page table entry marked ‘not-present’ on %d 3 cprintf("pid %d xv6: prints an error and kills process: trap *(( int *) 0x800444) = 1; %s: ... %d /* in trap.c: */ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ ␣ myproc() − >pid, myproc() − >name, tf − >trapno, tf − >err, cpuid(), tf − >eip, rcr2()); myproc() − >killed = 1; pid 4 processname: trap 14 err 6 on cpu 0 eip 0x1a addr 0x800444 −− kill proc

  6. xv6: if one handled page faults // actual segfault, kill process i.e. immediately after returning from fault if so, setup the page table so it works next time check process control block to see if access okay } } cprintf("..."); } else { returning from page fault handler without killing process // return from fault, retry access setup_page_table_entry_for(myproc(), address); if (is_address_okay(myproc(), address)) { can use to update the page table — “just in time” …retries the failing instruction 4 if (tf − >trapno == T_PGFLT) { void *address = ( void *) rcr2(); myproc() − >killed = 1;

  7. xv6: if one handled page faults // actual segfault, kill process i.e. immediately after returning from fault if so, setup the page table so it works next time check process control block to see if access okay } } cprintf("..."); } else { returning from page fault handler without killing process // return from fault, retry access setup_page_table_entry_for(myproc(), address); if (is_address_okay(myproc(), address)) { can use to update the page table — “just in time” …retries the failing instruction 4 if (tf − >trapno == T_PGFLT) { void *address = ( void *) rcr2(); myproc() − >killed = 1;

  8. xv6: if one handled page faults // actual segfault, kill process i.e. immediately after returning from fault if so, setup the page table so it works next time check process control block to see if access okay } } cprintf("..."); } else { returning from page fault handler without killing process // return from fault, retry access setup_page_table_entry_for(myproc(), address); if (is_address_okay(myproc(), address)) { can use to update the page table — “just in time” …retries the failing instruction 4 if (tf − >trapno == T_PGFLT) { void *address = ( void *) rcr2(); myproc() − >killed = 1;

  9. extra data structures needed OSs can do all sorts of tricks with page tables …but more bookkeeping is required tracking what processes think they have in memory since page table won’t tell the whole story OS will change page table tracking how physical pages are used in page tables multiple processes might want same data = same page 5

  10. space on demand Used by OS 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 6

  11. space on demand Used by OS 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 6

  12. space on demand Used by OS 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 6

  13. allocating space on demand … 0x7FFFE 1 0x12347 0x7FFFF 1 0x12345 … … 1 pushq triggers exception hardware says “accessing address 0x7FFFBFF8 ” OS looks up what’s should be there — “stack” page fault! in exception handler, OS allocates more stack space OS updates the page table then returns to retry the instruction restarted 0x12340 0x7FFFD ... 0x200DF // requires more stack space A: pushq %rbx C: addq %rbx, %rax ... %rsp = 0x7FFFC000 VPN page … … … 0x7FFFB 0 --- 0x7FFFC 1 7 valid? physical B: movq 8(%rcx), %rbx

  14. allocating space on demand … 0x7FFFE 1 0x12347 0x7FFFF 1 0x12345 … … 1 pushq triggers exception hardware says “accessing address 0x7FFFBFF8 ” OS looks up what’s should be there — “stack” page fault! in exception handler, OS allocates more stack space OS updates the page table then returns to retry the instruction restarted 0x12340 0x7FFFD ... 0x200DF // requires more stack space A: pushq %rbx C: addq %rbx, %rax ... %rsp = 0x7FFFC000 VPN page … … … 0x7FFFB 0 --- 0x7FFFC 1 7 valid? physical B: movq 8(%rcx), %rbx

  15. allocating space on demand … 0x7FFFE 1 0x12347 0x7FFFF 1 0x12345 … … 1 pushq triggers exception hardware says “accessing address 0x7FFFBFF8 ” OS looks up what’s should be there — “stack” page fault! in exception handler, OS allocates more stack space OS updates the page table then returns to retry the instruction restarted 0x12340 0x7FFFD ... 0x200DF // requires more stack space A: pushq %rbx C: addq %rbx, %rax ... %rsp = 0x7FFFC000 VPN page … … … 0x7FFFB 1 0x200D8 0x7FFFC 1 7 valid? physical B: movq 8(%rcx), %rbx

  16. xv6: adding space on demand struct proc { uint sz; // Size of process memory (bytes) ... }; adding allocate on demand logic: kill process — out of bounds fjnd virtual page number of address allocate page of memory, add to page table return from interrupt 8 on page fault: if address ≥ sz on page fault: if address < sz

  17. versus more complicated OSes range of valid addresses is not just 0 to maximum need some more complicated data structure to represent will get to that later 9

  18. fast copies recall : fork() (usually, the copy then calls execve — replaces itself with another program) how isn’t this really slow? 10 creates a copy of an entire program!

  19. do we really need a complete copy? Used by OS bash Stack Heap / other dynamic Writable data Code + Constants Used by OS new copy of bash Stack Heap / other dynamic Writable data Code + Constants shared as read-only can’t be shared? 11

  20. do we really need a complete copy? Used by OS bash Stack Heap / other dynamic Writable data Code + Constants Used by OS new copy of bash Stack Heap / other dynamic Writable data Code + Constants shared as read-only can’t be shared? 11

  21. do we really need a complete copy? Used by OS bash Stack Heap / other dynamic Writable data Code + Constants Used by OS new copy of bash Stack Heap / other dynamic Writable data Code + Constants shared as read-only can’t be shared? 11

  22. trick for extra sharing sharing writeable data is fjne — until either process modifjes the copy can we detect modifjcations? trick: tell CPU (via page table) shared part is read-only processor will trigger a fault when it’s written 12

  23. both processes share all physical pages copy-on-write and page tables 0 0x12340 0 1 0x00603 0x12347 0x00602 1 1 0x12345 0 1 0x00601 … 0x00604 0 … 0x200DF 0x00605 1 0 0x200AF … … … … copy operation actually duplicates page table but marks pages in both copies as read-only when either process tries to write read-only page triggers a fault — OS actually copies the page after allocating a copy, OS reruns the write instruction … … VPN 1 0x12347 1 1 0x00602 0x12345 1 0x00601 1 … … … … page valid? write?physical 0x00603 1 page 0x200AF valid? write?physical VPN … … … … 1 0x12340 1 0x00605 0x200DF 1 1 0x00604 13

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend