110 likes | 139 Views
Mechanism: Address Translation. Jiwoong Park(jwpark@dcslab.snu.ac.kr) School of Computer Science and Engineering Seoul National University. Overview. Virtualizing Memory Similar strategy to Limited Direct Execution (or LDE ) Efficiency + Control + Flexibility Goal
E N D
Mechanism: Address Translation Jiwoong Park(jwpark@dcslab.snu.ac.kr) School of Computer Science and Engineering Seoul National University
Overview • Virtualizing Memory • Similar strategy to Limited Direct Execution (or LDE) • Efficiency + Control + Flexibility • Goal • To create a beautiful illusionthat Program has its ownprivate memory • How to Efficiently and Flexibly virtualize memory? • Address Translation(Hardware-based address translation) • Virtual-to-Physical address translation by Hardware • Memory management by OS
Assumptions Address Space A Address Space B Address Space C Address Space A Address Space B Address Space C Address Space B Address Space A (O) (X) Physical Memory Address Space … Address Space Address Space Physical Memory (O) (X) Address Space A Address Space B Address Space C Address Space A Address Space B Address Space C (O) (X) • Address Space • It must be placed contiguouslyin physical memory • Its size is less than the size of physical memory • Each address space is exactly the same size
A Simple Example Presumption: ebx has address of x 1 void func () 2 { 3 int x; 4 … 5 x = x + 3; 6 } … 128movl 0x0 (%ebx), %eax ; load 0+ebx into eax 132addl $0x03, %eax ; add 3 to eax register 136movl %eax. 0x0 (%ebx) ; store eax back to mem … 0x00000000 Program Code 0x00000080 128 movl 0x0 (%ebx), %eax 132 addl $0x03, %eax 136 movl %eax. 0x0 (%ebx) Process’s point of view 0x00000084 2KB 0x00000088 • Fetch instruction at address 0x00000080 • Execute instruction (Load from address 0x00003C00) • Fetch instruction at address 0x00000084 • Execute instruction (no memory reference) • Fetch instruction at address 0x00000088 • Execute instruction (store to address 0x00003C00) 0x00000800 Heap 2KB 0x00001000 (Free) 16KB 0x00003800 Stack 2KB 0x00003C00 3000 0x00004000 Short code
A Simple Example 0x00000000 Operating System 16KB 0x00004000 (Not in use) 16KB 0x00008000 Code Heap 16KB (allocated but not in use) Stack 0x0000C000 (Not in use) 16KB 0x00010000 • From program’s perspective, its address space starts at address 0 • OS wants to place the process somewhere else in physical memory • How can we relocatethis process in memory in a transparentway? • How can provide the illusion of a virtual address space starting at 0?
Dynamic (Hardware-based) Relocation • Base and Bounds (Dynamic Relocation) • Two hardware registers within each CPU (Base register & Bounds register) • Apart of Memory Management Unit (MMU) • Functionality • Allows us to place address space anywhere in physical memory • Ensures that the process can onlyaccessits own address space • Essential prerequisite • Privileged accessto the base / bounds registers
Dynamic (Hardware-based) Relocation 0x00008000 Program Code Process’s point of view In real 0x00008080 128 movl 0x0 (%ebx), %eax 132 addl $0x03, %eax 136 movl %eax. 0x0 (%ebx) 0x00008084 0x00008088 • Fetch instruction at address 0x00000080 • Execute instruction (Load from address 0x00003C00) • Fetch instruction at address 0x00000084 • Execute instruction (no memory reference) • Fetch instruction at address 0x00000088 • Execute instruction (store to address 0x00003C00) • Logical Base • 0x0080 + 0x8000 • 0x3C00 + 0x8000 • 0x0084 + 0x8000 • … • 0x0088 + 0x8000 • 0x3C00 + 0x8000 0x00008800 Heap 0x00009000 (Free) 0x0000B800 Stack 0x0000BC00 3000 • Base Register • Role • Whenprogram start running • OS decideswherein physical memory it should be loaded • OS then setsthe baseregister to that value • Example (Base register: 0x8000) 0x0000C000
Dynamic (Hardware-based) Relocation Base register: 0x4000 Bounds register: 0x1000 • Virtual Address 0x0000 • Virtual Address 0x0400 • Virtual Address 0x0BB8 • Virtual Address 0x1130 • 0x0000 + 0x4000 • 0x0400 + 0x4000 • 0x0BB8 + 0x4000 • 0x1130 + 0x4000 • Physical Address 0x4000 • Physical Address 0x4400 • Physical Address 0x4BB8 • Fault (Out of bound) 0x1130 > Bounds • Bound Register • Two types • Holds the sizeof the address space • Holds the physical address of the endof the address space • Role • Forevery memory reference • Checksif the virtual address is too big or negative • If so, causesan exceptionto be raised and the process to be terminated • Example • Address space of size 4KB loaded at physical address 16KB
OS Issues • When a process is created • Finds / Allocates room for new address space in memory • When a process is terminated • Deallocates all of its memory for use in other processes or the OS • When a context switch occurs • Saves and restores the base / bounds pair in to the process structure or process control block (PCB) • When OS wants to move a process’s address space • Deschedules the process • Copies the address space • Updates the saved base register to point to the new location
Summary • With address translation • OS can control each and every memory access from a process • OS can ensure that every memory access stay within the boundsof the address space • Hardware Support is the key to the efficiency • Quick translation from virtual addresses into physical addresses • Goal • Transparencyto the process • Beautiful illusion that Program has its ownprivate memory • BaseandBounds (Dynamic Relocation) • What it offers • Efficiency & Protection • Limitation • Internal fragmentation (The next chapter will cover this)