Lecture 28: Virtual Memory-Address Translation
Review: Memory management for different systems Processes are known in advance and can fit in memory Embedded systems, e.g., radios, washing machines, and microwaves Processes are unknown in advance, memory might not be large enough Swapping Virtual memory
Review: Swapping Each individual process can fit in memory But memory cannot fit all processes Memory allocation/de-allocation Bitmap Linked list Dynamic address translation Base register in CPU Process isolation Limit register in CPU
Virtual memory What if a single process is larger than memory? Not all parts of the large process are equally possible to be used Put the parts that are less used in disk The process can still run Load a part from disk to memory when needed
Paging: Key idea of virtual memory Divide a program into fixed-size small parts Called virtual pages or pages Divide the memory into fixed-size small blocks Called page frames Load some pages into page frames
An example of paging 64K Virtual Address Space 32K Physical Memory Divided into 16 pages 4K for each page 32K Physical Memory 8 pages of 4K each
Problems in paging Address translation Page fault When a page that the process is trying to use is not in memory, hardware issues page fault Load in the page into a page frame Which page frame goes to disk? This is called page replacement problem
Address translation Process generates a “virtual address” Virtual address is translated into a physical address Physical address goes onto the bus
Address translation: Memory Management Unit (MMU)
Address translation via Page Table Page table is a data structure Each page has an entry in this page table The index of the page is used to find the entry in the page table Each entry stores various information about the page
Address translation via Page Table
Typical Page Table Entry Present/absent: 1 if the page is in memory Protection: what operations to the page are allowed Modified: 1 if the page is modified since it is loaded. Also called “dirty” bit Referenced: 1 if the page is read or written Caching disabled: 1 if disabling caching this page
Page Fault What if required page not in memory? MMU reports a page fault to CPU CPU gives control to the OS OS fetches it from the disk Needs to evict an existing page from memory (page replacement policy) Instruction is restarted
Performance The address translation is done on every memory reference The translation better be fast!
Question Where is the page table stored? Registers? Memory?
Store in registers Need many registers Context switching is slow
Store in memory One register to store the start address of the page table Context switching is fast May do paging for the page table itself. Store some page entries in disk if the page table is too large.