4003-440-02 Operating Systems I
Module 8. Memory Management -- Lecture Notes
Prof. Alan Kaminsky -- Winter Quarter 2012
Rochester Institute of Technology -- Department of Computer Science
Address Mapping
- Goal: Support multiple concurrently running processes (multiprocessing)
- Logical addresses
- Addresses generated and used by a program
- Physical addresses
- Addresses presented to the main memory hardware
- Address mapping
- Conversion of a logical address in the program to a physical address in the main memory
- Address mapping technique: No mapping
- Physical address = Logical address
- Implications for multiprocessing
- Address mapping technique: Relocation
- Base register, limit register
- If logical address >= limit register, error; else physical address = base address + logical address
- Implications for multiprocessing
- Swapping
- Copy a non-running process's memory contents from main memory to secondary memory
- Frees up space in the main memory to load in and run another process
- Problem: Fragmentation
- Address mapping technique: Paging
- Logical address split into (page number, page offset)
- Main memory divided into page frames
- Page table
- Index page table by page number to get page frame number; physical address = (page frame number, page offset)
- Illustrate with 16-bit addresses, 4096-byte pages
- Solves the fragmentation problem
- Problem: Typically too many page table entries to hold the page table in CPU hardware
- Solution: Store the page table in main memory; page table register
- Problem: Reading or writing data requires two memory accesses
- Solution: Cache the page table entries; translation lookaside buffer (TLB)
- Problem: For larger addresses (64-bit or even 32-bit) the page table takes up too much memory
- Address mapping technique: Multi-level paging
- Logical address split into (first level page number, second level page number, page offset)
- Hierarchical page table
- Can have more than two levels of page tables
- Problem: We lost the protection (limit register)
- Address mapping technique: Segmentation
- Divide a process's address space into segments based on what's stored -- code segments, data segments, stack segments, etc.
- Logical address split into (segment number, segment offset)
- Segment table
- Base address (physical address)
- Limit (size)
- Protection -- executable/nonexecutable, read-write/read-only, user/kernel, etc.
- Index segment table by segment number to get base address; physical address = base address + segment offset
- Hierarchical page table
- Can have more than two levels of page tables
- Problem: We're back to needing contiguous memory allocation (fragmentation)
- Address mapping technique: Segmentation plus paging
- The Intel Pentium address mapping scheme:
- Logical address uses segmentation, translates to a linear address
- 213 local segments plus 213 global segments
- Linear address uses paging, translates to a physical address
- Two-level paging
- 10-bit first level page number
- 10-bit second level page number
- 12-bit page offset
- Implementation of inter-process shared memory segments
Virtual Memory
- Demand paging: Don't load in all of a process's pages, only load in the pages the process actually references
- Working set: The set of pages the process is actually referencing at any given time
- Page fault: Generated by the hardware when the process references a logical address that is not loaded
- Page fault processing -- three cases:
- If the process has not yet loaded the full number of page frames allotted by the operating system:
- Read new page from disk into an unused page frame
- Else select a page for page replacement. If the selected page is clean (has not been written into since it was loaded):
- Read new page from disk into the selected page frame
- Else the selected page is dirty (has been written into since it was loaded):
- Write old page from the selected page frame to disk
- Read new page from disk into the selected page frame
- Metrics for measuring virtual memory performance
- Hit ratio = 1 - miss ratio
- Miss ratio = number of page faults / number of memory accesses
- Dirty miss ratio = number of page faults where a dirty page is replaced / number of memory accesses
- Effect of number of available page frames on metrics
- Page replacement algorithms
- Optimal (OPT) -- theoretical baseline
- First In First Out (FIFO) -- practical, easy to program, but tends not to be close to optimal
- Least Recently Used (LRU) -- practical, gives results close to optimal, but time-consuming
- Various other algorithms try to approximate LRU while taking less time
- Second Chance -- practical, results similar to LRU, easier to program and faster
- OPT page replacement algorithm example
- FIFO page replacement algorithm example
- LRU page replacement algorithm example
- Second Chance page replacement algorithm example
- Simulations -- see "Memory Trace Analysis"
|
Operating Systems I
|
|
•
|
|
4003-440-02
|
|
•
|
|
Winter Quarter 2012
|
|
Course Page
|
|
Alan Kaminsky
|
|
•
|
|
Department of Computer Science
|
|
•
|
|
Rochester Institute of Technology
|
|
•
|
|
4486 +
2220 =
6706
|
|
Home Page
|
Copyright © 2013 Alan Kaminsky.
All rights reserved.
Last updated 30-Jan-2013.
Please send comments to ark@cs.rit.edu.
|