ospp: address translation · –resume execution. fill on demand •can i start running a program...
TRANSCRIPT
![Page 1: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/1.jpg)
Address Translation
Chapter 8 OSPP
Part I: Basics
![Page 2: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/2.jpg)
Main Points
• Address Translation Concept– How do we convert a virtual address to a physical address?
• Flexible Address Translation– Base and bound– Segmentation– Paging– Multilevel translation
• Efficient Address Translation– Translation Lookaside Buffers (TLB)– Virtually and physically addressed caches
![Page 3: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/3.jpg)
Address Translation Concept
![Page 4: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/4.jpg)
Address Translation Goals
• Memory protection• Memory sharing
– Shared libraries, IPC
• Sparse addresses– Multiple regions of dynamic allocation (heaps/stacks)
• Efficiency– Memory placement– Runtime lookup– Compact translation tables
• Portability
![Page 5: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/5.jpg)
Bonus Feature
• What can you do if you can (selectively) gain control whenever a program reads or writes a particular virtual memory location?
• Examples:– Copy on write
– Zero on reference
– Fill on demand
– Demand paging
– Memory mapped files
![Page 6: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/6.jpg)
Virtually Addressed Base and Bounds
![Page 7: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/7.jpg)
Question
• With virtually addressed base and bounds, what is saved/restored on a process context switch?
![Page 8: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/8.jpg)
Virtually Addressed Base and Bounds
• Pros?
• Cons?
![Page 9: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/9.jpg)
Segmentation
• Segment is a contiguous region of virtual memory
• Each process has a segment table (in hardware)– Entry in table = segment
• Segment can be located anywhere in physical memory– Each segment has: start, length, access permission
• Processes can share segments– Same start, length, same/different access permissions
– Great for shared libraries
![Page 10: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/10.jpg)
Segmentation
![Page 11: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/11.jpg)
Question
• With segmentation, what is saved/restored on a process context switch?
![Page 12: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/12.jpg)
UNIX fork and Copy on Write
• UNIX fork– Makes a complete copy of a process
• Segments allow a more efficient implementation– Copy segment table into child
– Mark parent and child segments read-only
– Start child process; return to parent
– If child or parent writes to a segment (ex: stack, heap)• trap into kernel
• make a copy of the segment and resume
![Page 13: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/13.jpg)
![Page 14: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/14.jpg)
Zero-on-Reference
• Dynamic segments
– When program uses memory beyond end of stack
– Segmentation fault into OS kernel
– Kernel allocates some memory
• How much?
• Zeros the memory
– avoid accidentally leaking information!
• Modify segment table
• Resume process
![Page 15: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/15.jpg)
Segmentation
• Pros?
• Cons?
![Page 16: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/16.jpg)
Paged Translation
• Manage memory in fixed size units, or pages
• Finding a free page is easy– Bitmap allocation: 0011111100000001100
– Each bit represents one physical page frame
• Each process has its own page table– Stored in physical memory
– Hardware registers• pointer to page table start
• page table length
![Page 17: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/17.jpg)
Paged Translation (Abstract)
![Page 18: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/18.jpg)
Paged Translation (Implementation)
![Page 19: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/19.jpg)
ABCD
EFGH
IJKL
IJKL
EFGH
ABCD
4
3
1
Page Table
Process View Physical Memory
![Page 20: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/20.jpg)
Paging Questions
• With paging, what is saved/restored on a process context switch?
• What if page size is very small?
• What if page size is very large?
![Page 21: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/21.jpg)
Paging and Copy on Write
• Can we share memory between processes?– Set entries in both page tables to point to same page frames
– Need core map of page frames to track which processes are pointing to which page frames (e.g., reference count)
• UNIX fork with copy on write– Copy page table of parent into child process
– Mark all pages (in new and old page tables) as read-only
– Trap into kernel on write (in child or parent)
– Copy page
– Mark both as writeable
– Resume execution
![Page 22: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/22.jpg)
Fill On Demand
• Can I start running a program before its code is in physical memory?
– Set all page table entries to invalid
– When a page is referenced for first time, kernel trap
– Kernel brings page in from disk
– Resume execution
– Remaining pages can be transferred in the background while program is running
![Page 23: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/23.jpg)
Data Breakpoints
• Please trace variable A
• Mark page P containing A as read-only
• If P is changed, trap into kernel, and see if A actually changed
![Page 24: OSPP: Address Translation · –Resume execution. Fill On Demand •Can I start running a program before its code is in physical memory? –Set all page table entries to invalid –When](https://reader034.vdocuments.net/reader034/viewer/2022050323/5f7c3038df2fb42a5e4df09a/html5/thumbnails/24.jpg)
Page Table Issue
• 64 bit machines