Lecture 28 Virtual Memory Address Translation Review Memory

  • Slides: 17
Download presentation
Lecture 28: Virtual Memory. Address Translation

Lecture 28: Virtual Memory. Address Translation

Review: Memory management for different systems • Processes are known in advance and can

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

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? • Virtual

Virtual memory • What if a single process is larger than memory? • Virtual 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

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 • 64 K Virtual Address Space – Divided into 16

An example of paging • 64 K Virtual Address Space – Divided into 16 pages – 4 K for each page • 32 K Physical Memory – 8 pages of 4 K each

Problems in paging • Address translation • Page fault – When a page that

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 1. Process generates a “virtual address” 2. Virtual address is translated into

Address translation 1. Process generates a “virtual address” 2. Virtual address is translated into a physical address 3. Physical address goes onto the bus

Address translation: Memory Management Unit (MMU)

Address translation: Memory Management Unit (MMU)

Address translation via Page Table • Page table is a data structure • Each

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

Address translation via Page Table

Typical Page Table Entry Present/absent: 1 if the page is in memory Protection: what

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? 1. MMU reports a page

Page Fault What if required page not in memory? 1. MMU reports a page fault to CPU 2. CPU gives control to the OS 3. OS fetches it from the disk 1. Needs to evict an existing page from memory (page replacement policy) 4. Instruction is restarted

Performance • The address translation is done on every memory reference • The translation

Performance • The address translation is done on every memory reference • The translation better be fast!

Question Where is the page table stored? • Registers? • Memory?

Question Where is the page table stored? • Registers? • Memory?

Store in registers • Need many registers • Context switching is slow

Store in registers • Need many registers • Context switching is slow

Store in memory • One register to store the start address of the page

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.