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