Responsibilities of VM system:
(1) manages virtual-to-physical mapping of memory
(2) presents a simple memory programming model to applications so that application developers need not know how the underlying memory hardware is arranged <- memory is abstracted; user applications deal with virtual addresses and virtual address spaces
(3) allows processes to see linear ranges of bytes in their address space regardless of the physical layout or fragmentation of real memory
(4) efficient allocation of physical memory to processes & kernel subsystems
VM system uses slower storage medium (disk) to store data that doesn't fit within the physical memory (RAM) of the system, thus accomodating programs larger than the size of physical memory
(5) keeps most frequently used portions of memory in the RAM, to make the application run faster; manages swapping of memory between primary and secondary storage to optimize performance
(6) handles requirements of shared images between multiple users & processes
Quick Notes:
Address space:
linear range of memory
Every process will have an address space; each address space isbroken into several segments that represent mapping of the executable, heap, shared libraries & a program stack
Each segment is divided into equal sized pieces of VM known as pages. Hardware MMU (Memory Management Unit) does the mapping of VM pages to physical memory
Demand Paging:
VM system implements demand paging; pages of memory are allocated on demand
Page Fault:
MMU raises an event to tell the kernel that an access has occured to an area of memory that doesn't have the physical memory mapped to it. Heap of a process is also allocated in a similar way.
Initially only VM space (address space) is allocated to the process. When the memory is first referenced, a page fault occurs and the memory is allocated one page at a time
Most of the kernel's memory is not pageable; i.e., it is allocated from physical memory which cannot be stolen by page scanner
Each page of physical memory is associated with a file and an offset; the file and offset identify the backing store for the page
Anonymous memory:
pages used for regular process heap and stack; swapfs takes care of that. Anon memory doesn't have a vnode attached to it
Dirty page:
A page that has had its contents modified
Heap:
scratch memory aka temporary processing space for a process
Hardware Memory Management Unit (MMU) maps pages into physical memory by using a platform specific set of translation tables called Translation Lookaside Buffer (TLB) & Translation Software Buffer (TSB)