memory virtualization basic address translation
play

Memory Virtualization: Basic Address Translation Prof. Patrick G. - PowerPoint PPT Presentation

University of New Mexico Memory Virtualization: Basic Address Translation Prof. Patrick G. Bridges 1 University of New Mexico Address Translation Address spaces are virtual addresses Must be transparently translated to the actual


  1. University of New Mexico Memory Virtualization: Basic Address Translation Prof. Patrick G. Bridges 1

  2. University of New Mexico Address Translation  Address spaces are virtual addresses ▪ Must be transparently translated to the actual physical memory addresses used by the underlying hardware ▪ Typically done by hardware mechanisms (segment tables, page tables, TLBs, etc.) though some software approaches exist  Hardware transforms a virtual address to a physical address. ▪ The desired information is actually stored in a physical address.  The OS must get involved at key points to set up the hardware. ▪ The OS must manage memory to judiciously intervene. 2

  3. University of New Mexico Example: Address Translation  C - Language code void func() int x; ... x = x + 3; // this is the line of code we are interested in ▪ Load a value from memory ▪ Increment it by three ▪ Store the value back into memory 3

  4. University of New Mexico Example: Address Translation(Cont.)  Assembly 128 : movl 0x0(%ebx), %eax ; load 0+ebx into eax 132 : addl $0x03, %eax ; add 3 to eax register 135 : movl %eax, 0x0(%ebx) ; store eax back to mem ▪ Presume that the address of ‘x’ has been place in ebx register. ▪ Load the value at that address into eax register. ▪ Add 3 to eax register. ▪ Store the value in eax back into memory. 4

  5. University of New Mexico Example: Address Translation(Cont.) 0KB 128 movl 0x0(%ebx),%eax Fetch instruction at address 128 • 132 Addl 0x03,%eax 1KB 135 movl %eax,0x0(%ebx) Execute this instruction ( load from address 15KB) • Program Code 2KB Fetch instruction at address 132 • 3KB Execute this instruction ( no memory reference) Heap • Fetch the instruction at address 135 4KB • Execute this instruction (s tore to address 15 KB) • heap (free) stack 14KB 15KB 3000 Stack 16KB 5

  6. University of New Mexico Relocation Address Space  The OS wants to place the process somewhere else in physical memory, not at address 0. ▪ The address space starts at address 0. 6

  7. University of New Mexico A Single Relocated Process 0KB 0KB Program Code Operating System 16KB Heap (not in use) 32KB Code Relocated Process Heap heap (allocated but not in use) (free) Stack 48KB stack (not in use) Stack 64KB 16KB Physical Memory Address Space 7

  8. University of New Mexico Base and Bounds Register  Simple Idea 1: Base to offset virtual to physical, bound to limit access within the address space itself 0KB 0KB Program Code Operating System 16KB Heap (not in use) base register 32KB 32KB Code Heap heap (allocated but not in use) (free) Stack 48KB stack (not in use) Stack bounds register 64KB Physical Memory 16KB 16KB Address Space 8

  9. University of New Mexico Dynamic(Hardware base) Relocation  When a program starts running, the OS decides where in physical memory a process should be loaded. ▪ Set the base register a value. 𝑞ℎ𝑧𝑑𝑏𝑚 𝑏𝑒𝑒𝑠𝑓𝑡𝑡 = 𝑤𝑗𝑠𝑢𝑣𝑏𝑚 𝑏𝑒𝑒𝑠𝑓𝑡𝑡 + 𝑐𝑏𝑡𝑓 ▪ Every virtual address must not be greater than bound and negative. 0 ≤ 𝑤𝑗𝑠𝑢𝑣𝑏𝑚 𝑏𝑒𝑒𝑠𝑓𝑡𝑡𝑤𝑗𝑠𝑢𝑣𝑏𝑚 𝑏𝑒𝑒𝑠𝑓𝑡𝑡 < 𝑐𝑝𝑣𝑜𝑒𝑡 9

  10. University of New Mexico Relocation and Address Translation 0KB 128 movl 0x0(%ebx),%eax 132 128 : movl 0x0(%ebx), %eax Addl 0x03,%eax 1KB 135 movl %eax,0x0(%ebx) Program Code 2KB 3KB Heap ▪ Fetch instruction at address 128 4KB 32896 = 128 + 32𝐿𝐶(𝑐𝑏𝑡𝑓) ▪ Execute this instruction heap ▪ Load from address 15KB (free) 47𝐿𝐶 = 15𝐿𝐶 + 32𝐿𝐶(𝑐𝑏𝑡𝑓) stack 14KB 15KB 3000 Stack 16KB 10

  11. University of New Mexico Two ways of Bounds Register 0KB 0KB Program Code Operating System 16KB Heap (not in use) 32KB Code Heap 𝒒𝒊𝒛𝒕𝒋𝒅𝒃𝒎 𝒃𝒆𝒆𝒔𝒇𝒕𝒕 𝒑𝒈 𝒖𝒊𝒇 𝒕𝒋𝒜𝒇 𝒑𝒈 𝒖𝒊𝒇 𝒇𝒐𝒆 𝒑𝒈 (allocated 𝒃𝒆𝒆𝒔𝒇𝒕𝒕 𝒕𝒒𝒃𝒅𝒇𝒇 𝒃𝒆𝒆𝒔𝒇𝒕𝒕 𝒕𝒒𝒃𝒅𝒇 but not in use) (free) bounds bounds Stack 16KB 48KB 48KB (not in use) Stack 64KB Physical Memory 16KB Address Space 11

  12. University of New Mexico OS Issues for Memory Virtualizing  The OS must take action to implement base-and-bounds approach.  Three critical junctures: ▪ When a process starts running: ▪ Finding space for address space in physical memory ▪ When a process is terminated: ▪ Reclaiming the memory for use ▪ When context switch occurs: ▪ Saving and storing the base-and-bounds pair 12

  13. University of New Mexico OS Issues: When a Process Starts Running  The OS must find a room for a new address space. ▪ free list : A list of the range of the physical memory which are not 0KB in use. Operating System The OS lookup the free list 16KB Free list (not in use) 32KB 16KB Code Heap (allocated but not in use) Stack 48KB 48KB (not in use) 64KB Physical Memory 13

  14. University of New Mexico OS Issues: When a Process Is Terminated  The OS must put the memory back on the free list. Free list 0KB 0KB Free list Operating System Operating System 16KB 16KB 16KB 16KB (not in use) (not in use) 32KB 32KB (not in use) Process A 32KB 48KB 48KB 48KB (not in use) (not in use) 64KB 48KB 64KB Physical Memory Physical Memory 14

  15. University of New Mexico OS Issues: When Context Switch Occurs  The OS must save and restore the base-and-bounds pair. ▪ In process structure or process control block( PCB) Process A PCB … base : 32KB bounds : 48KB 0KB 0KB Context Switching … Operating System Operating System 16KB 16KB (not in use) (not in use) base base 32KB 48KB 32KB 32KB Process A Process A bounds bounds Currently Running 48KB 64KB 48KB 48KB Process B Process B Currently Running 64KB 64KB Physical Memory Physical Memory 15

Recommend


More recommend