University of New Mexico
1
Memory Virtualization: Basic Address Translation
- Prof. Patrick G. Bridges
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
University of New Mexico
1
University of New Mexico
2
Address spaces are virtual addresses
Hardware transforms a virtual address to a physical
The OS must get involved at key points to set up the
University of New Mexico
3
C - Language code
void func() int x; ... x = x + 3; // this is the line of code we are interested in
University of New Mexico
4
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
University of New Mexico
5
(free)
3000
Stack stack heap Heap 14KB Program Code 16KB 15KB 0KB 1KB 2KB 3KB 4KB
128 132 135 movl 0x0(%ebx),%eax Addl 0x03,%eax movl %eax,0x0(%ebx)
University of New Mexico
6
The OS wants to place the process somewhere else in
University of New Mexico
7
(free) Stack stack heap Heap Program Code 16KB 0KB (not in use) (not in use) Operating System 0KB 16KB 32KB 48KB 64KB
Code (allocated but not in use) Heap Stack
Relocated Process Address Space Physical Memory
University of New Mexico
8
Simple Idea 1: Base to offset virtual to physical, bound to limit
(free) Stack stack heap Heap Program Code 16KB 0KB (not in use) (not in use) Operating System 0KB 16KB 32KB 48KB 64KB
Code (allocated but not in use) Heap Stack
Address Space Physical Memory 32KB base register 16KB bounds register
University of New Mexico
9
When a program starts running, the OS decides where in
University of New Mexico
10
▪ Load from address 15KB
(free)
3000
Stack stack heap Heap 14KB Program Code 16KB 15KB 0KB 1KB 2KB 3KB 4KB
128 132 135
32896 = 128 + 32𝐿𝐶(𝑐𝑏𝑡𝑓) 47𝐿𝐶 = 15𝐿𝐶 + 32𝐿𝐶(𝑐𝑏𝑡𝑓)
movl 0x0(%ebx),%eax Addl 0x03,%eax movl %eax,0x0(%ebx)
University of New Mexico
11
(free) Stack Heap Program Code 16KB 0KB (not in use) (not in use) Operating System 0KB 16KB 32KB 48KB 64KB
Code
(allocated but not in use)
Heap Stack
Address Space Physical Memory 48KB 16KB bounds 𝒖𝒊𝒇 𝒕𝒋𝒜𝒇 𝒑𝒈 𝒃𝒆𝒆𝒔𝒇𝒕𝒕 𝒕𝒒𝒃𝒅𝒇𝒇 𝒒𝒊𝒛𝒕𝒋𝒅𝒃𝒎 𝒃𝒆𝒆𝒔𝒇𝒕𝒕 𝒑𝒈 𝒖𝒊𝒇 𝒇𝒐𝒆 𝒑𝒈 𝒃𝒆𝒆𝒔𝒇𝒕𝒕 𝒕𝒒𝒃𝒅𝒇 bounds
University of New Mexico
12
The OS must take action to implement base-and-bounds
Three critical junctures:
▪ Finding space for address space in physical memory
▪ Reclaiming the memory for use
▪ Saving and storing the base-and-bounds pair
University of New Mexico
13
The OS must find a room for a new address space.
0KB 16KB 32KB 48KB 64KB
Code
(allocated but not in use)
Physical Memory The OS lookup the free list (not in use)
Heap Stack
Operating System (not in use)
Free list
16KB 48KB
University of New Mexico
14
The OS must put the memory back on the free list. Operating System
0KB 16KB 32KB 48KB 64KB
Physical Memory (not in use) (not in use) Operating System
0KB 16KB 32KB 48KB 64KB
Physical Memory (not in use) (not in use) (not in use) Process A
Free list
16KB 48KB
Free list
16KB 32KB 48KB
University of New Mexico
15
The OS must save and restore the base-and-bounds pair.
Operating System
0KB 16KB 32KB 48KB 64KB
Physical Memory (not in use) Process A Currently Running Process B 48KB bounds 32KB base Context Switching Operating System
0KB 16KB 32KB 48KB 64KB
Physical Memory (not in use) Process A Process B Currently Running 64KB 48KB Process A PCB
… base : 32KB bounds : 48KB …
bounds base