Lecture 10 - Memory management Flashcards
Why is memory management needed?
Memory is a resource
Processes need protection
Helps progamming if all memory looks the same
What is the memory hierarchy?
Smaller memory = faster = more volatile = more expensive
Larger memory = slower = less volatile = cheaper
What is the difference between logical and physical addresses?
Logical address - virtual address - local to the process, translated by the MMU (memory management unit)
Physical address - what the actual hardware sees
In days of job-at-a-time batch programming, how was virtual memory mapped to physical memory?
Entire physical memory was for the one job, if it didn’t fit program would manually load the next part into memory
Embedded systems use
a) virtual memory
b) physical memory
and hence there may be at most ___________ program(s) running at a time
b) physical
one
What is swapping?>
Saving a programs entire state including memory image onto a disk
Loading another program into memory
What two things does multiprogramming need from memory? Why?
Relocation - mem wont always be in same place so cant use absolute memory locations
Protection - multiple programs must not be able to access other programs memory
What is contiguous memory allocation?
Memory is partitioned into many spaces
When a process wants to run it requests a certain amount of memory
if its available OS allocates it to the process
otherwise process has to wait
What are base and limit registers?
Base register - defines the lowest address (start address) of the memory space of a program
Limit register - defines the size of the memory allocated a process
How does the memory management unit map logical addresses?
Takes offset and compares to limit register. If > limit register, raise protection fault, else add to base register - resulting address is physical memory address
What is segmentation?
A program is a collection of segments
Each segment could be allocated somewhere different in physical memory
Need a segment table with base/limit per segment to map logical to physical addresses
What are the pros and cons of segmentation?
Pros: segments are logical to us and facilitate sharing and reuse
protection can be set per segment
Cons: variable sized partitions need tricky dynamic allocation
What is paging and what problems does it solve?
Process sees memory as one contiguous space
in reality pages are scattered across actual hardware
each page the same size, efficiently uses memory and can have protection per page
Solves external fragmentation problem by using fixed size units in physical and virtual memory
Solves internal fragmentation by making the units small
What is a page table?
Table that maps pages in a process’ virtual memory to page frames in physical memory
How is address translation done with paging?
Virtual address has two parts: page number and offset
Page number corresponds to entry in page table
offset refers to offset from the base address of the page
What are page tables managed by?
The os
Why will every data/instruction access require two memory accesses?
Have to look up page table and then the actual data once the right address is obtained
What is a translation lookaside buffer?
Very fast cache that stores a list of recently translated addresses - if address to be looked up is found it is very quickly returned, otherwise the phyiscal memory must be accessed to find the right page
hardware associative array searched in parallel
Why can logical memory be much larger than physical address space?
Only part of the program needs to be in the memory to run
When a page in the page table has been moved to the disk, it will be marked as _________
invalid
What is a page fault?
When a process tries to access a page marked invalid, either because
a) the page has been moved to the disk and needs to be retrieved
b) the page never existed
What happens when a page fault occurs?
Process suspended, enter kernel mode
os brings requested page into memory:
- find free page frame in memory
- find page on disk
- fetch page into frame
- update page table with page frame
- mark page as valid in page table
restarts the interrupted instruction
process continues none the wiser
What is demand paging?
What are the benefits?
Bring a page into memory only when it is needed
Less I/O needed
Less memory needed
Faster response
More users
What do fetch strategies describe?
When should a page or segment be brought into primary memory from secondary storage (disk)?
- Demand fetch
- Anticipatory fetch
What do placement strategies describe?
When a page or segment is brought into memory where shall it be put?
Trivial with paging
With segmentation, difficult
What do replacement strategies describe?
Which page/segment should be replaced if there is not enough room for a required page/segment?
What is optimal page replacement algorithm?
Try to replace the page that will be used furthest in the future
Not really achievable in real systems since we cant predict which pages will be needed
What is Not-Recently-Used algorithm?
Each page has reference bit and dirty bit
Paged classified into 4 classes: not ref or dirty, not ref dirty, ref not dirty, ref and dirty
Clear reference bit for all pages periodically
Algorithm: remove a page at random from the lowest non-empty class, i.e. preferably not referenced or dirty
Decent performance
What is the FIFO algorithm?
Maintain linked list of all pages
Page at front of list replaced
Very easy to implement
Not always performant - page in memory the longest may be often used, this forces it out regardless
What is second chance page replacement?
Modify FIFO to avoid throwing out heavily used pages
Give each page reference bit
If reference bit is 0 throw it out, if 1 reset it to 0, move to the end of the list, continue to search for a free page
What is Least Recently Used algorithm?
Assume pages recently used will be used again soon
Throw out page that has been unused for the longest time
What is thrashing?
If the page-fault rate on a system is too high because there are not enough pages, a process will spend more time paging than it will executing
Low cpu utilisation
Os thinks it needs to increase the degree of multiprogramming so more cpu is utilised
Even more paging happens
Throughput plummets
How can thrashing be controled?
Establish acceptable page fault rate
If too low, too many frames - give more processes
If too high, too few frames, hold back some processes
What is the resident set of a process?
Number of pages a process is allocated
What is the working set of a process?
The set of pages referenced in the last X memory references
Indicates size of memory locality
What is copy-on-write?
Allows parent and child processes to share pages that are the same
If either one modifies a shared page, only then is it copied elsewhere
What is a memory-mapped file?
Where a disk block is mapped to memory page
So memory accesses on that page are actually I/O processes
Several processes using the file can use the same shared memory block