- Index on frame number, not virtual address. ![](/assets/Screen Shot 2018-03-14 at 2.47.16 PM.png)
- Each virtual memory access can cause two physical memory addresses
- Fetch the page table entry
- Fetch the data
- Fix: add caches ![](/assets/Screen Shot 2018-03-14 at 2.50.12 PM.png)
- CPU checks TLB (Translation Lookaside Buffer)
- Check page table entry in TLB?
- If Yes, CPU generates physical address
- If No, access page table and check if page is in main memory
- If page is not found, raise page fault, read page from disk and transfer it to main memory
- If page is found, CPU generates physical address, update the TLB
- Small Page Size
- less internal fragmentation
- more pages per process => larger page tables => large portion of page tables in virtual memory
- more pages benefits from principal of locality => page faults low
- Large Page Size
- secondary memory transfers larger blocks of data better
- pages tend to be farther away from recent reference => higher page faults
- Allows programmer to view memory of multiple address spaces and segments
- Advantages
- Simplifies handling of data structures by having one structure per segment
- Allows programs to be altered and recompiled independently by having code and data contain their own segments
- Shares data among processes by sharing a segment
- Protection by protecting segments
- Starting address corresponds to segment in main memory
- Each entry contains the length of the segment
- 2 bits are needed to determine if segment is in main memory and if it was modified since loading into main memory ![](/assets/Screen Shot 2018-03-14 at 9.40.40 PM.png)
- Each element contains a process, 1 segment table per process, 1 page table per segment
- Segment is visible to programmer, paging is transparent ![](/assets/Screen Shot 2018-03-14 at 10.19.15 PM.png)
- Does the system need virtual memory?
- Paging, segmentation, or both?
- Which algorithms for memory management?
- Fetch policy
- Placement policy
- Replacement policy
- Cleaning policy
- Load control
- Determines when a page should be brought into main memory
- Demand paging: only bringing pages into main memory when a reference is made to location on the page => lots of page faults in the beginning of process
- Prepaging: brings in more pages than needed to improve efficiency
- Determines where in real memory a process piece is to reside
- Important when segmenting a system
- Determines which page to replace
- Should remove the page that is least likely to be referenced in the future -> principle of locality
- Frame locking
- Restricts placement policy
- If frame is locked, cannot be replace
- Tracks locked/unlocked via lock bit w/each frame
- Replaces the page where the time to the next reference is the longest
- Impossible to have perfect knowledge of future events
- Uses principal of locality
- Replaces the page that has not been referenced for the longest time
- By principal of locality, this page is least likely to be referenced in the near future
- Performance is nearly as good as optimal algorithm
- Each page needs to be tagged with the time of last reference => overhead w/clock algorithms
- Page that has been in memory the longest is replaced
- Assumes old page will not be referenced soon again
- Pages are removed in a round-robin style
- Simplest to implement
- Adds an additional bit, the "use bit"
- Use bit = 1 when page first loaded into memory
- Use bit = 1 when page is referenced
- When time to replace a page, first frame encountered with the use bit = 0 is replaced
- Each use bit = 0 when searching for a replacement ![](/assets/Screen Shot 2018-03-14 at 11.20.07 PM.png)
![](/assets/Screen Shot 2018-03-14 at 11.21.56 PM.png)
Number of page faults in increasing order: OPT < LRU < CLOCK < FIFO