VM Flashcards
issues with sharing pmem
protection, transparency, resource exhaustion
protection
prevent processes from observing other process’ memory
e.g. bug in one process should not affect another
transparency
a process should not require particular physical addresses
but we often need contiguous addresses
resource exhaustion
programmers typically assume the system has enough memory
the sum of all processes is usually greater than pmem
MMU jobs
- translate virtual to physical
- enforce memory protection
- allow programs to see more memory than exists
load-time linking idea
determine where a process will reside in memory and adjust all references within the program
problems with load-time linking
how to protect?
how to relocate?
what if no contiguous free region?
base/bound idea
easy relocation by changing base
must save/restore base/bound on context switches
advantages of base/bound
inexpensive in hardware
inexpensive in cycles
disadvantages of base/bound
growing a process is expensive/impossible
no way to share code/data
segmentation idea
let processes have many base/bounds
segmentation advantages
allows multiple segments per process
allows sharing of code/data
don’t need entire process in memory
disadvantages of segmentation
requires address translation hardware, limits performance
segments not completely transparent e.g. default segment faster
n byte segment needs b contiguous bytes of pmem
fragmentation
hardware lookup algorithm
KMPVRN
paging tradeoffs
eliminates external fragmentation
simplifies allocation, free, and backing storage
avg internal frag of 0.5 pages per “segment”
why is the MIPS UTLB handler separate from general exception handler?
UTLBs very frequent, hand optimized path
64 entry TLB only 256kiB
modern working sets don’t fit
why do we typically not want paging and segmentation?
too much overhead
when is paging + segmentation useful?
detect stack overflow or thread-local storage
what does thread-local storage do?
changes a global var to local for each thread
how is thread-local storage achieved?
global var relative to %fs register, each thread has its own base address stored in %fs
what happens to the TLB on a context switch?
old x86 flushes TLB
MIPS tags each entry with PID, no need to flush
where does the OS live?
kernel addresses are in the same address space as the user process
what’s demand paging?
only loading pages if they are needed
what’s copy on write?
share a reference, (fork, mmap) if a write happens, then make a copy
what do we need zeroed pages for?
stack, heap, anonymously mmapped memory for devices
what’s Belady’s anomaly?
adding more physical memory doesn’t always mean fewer faults
thrashing
application constantly swapping pages in and out, preventing reasonable progress
reasons for thrashing?
memory access does not exhibit temporal locality
working set does not fit in physical memory
each process fits individually, but there are too many for the system
what’s the breakpoint?
top of the heap
addresses between breakpoint and top of the stack are invalid
char * brk(const char * addr);
set and return new value of breakpoint
char * sbrk(int incr)
increment value of the breakpoint and return the old value
void * mmap(void * addr, size_t len, int prot, int flags, int fd, off_t offset)
treat a file as if it were memory
map fd to addr except that changes are backed up to the file
can be shared with other processes
prot specifies protection of region
flags sets who can see modifications
vm tricks at user level
use mprotect and sigaction to set protections and actions
e.g. OO database
bring in objects on demand, keep track of dirty objects, manage memory as a cache for a huge object DB
paging in day to day use
demand paging
copy on write
growing the stack
BSS page allocations
sharing text/library
sharing memory