Академический Документы
Профессиональный Документы
Культура Документы
Operating Systems
Session 12
Address Translation
© 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED 1
Memory Virtualizing with Efficiency and Control
2
Address Translation
• Hardware transforms a virtual address to a physical address.
• The desired information is actually stored in a physical address.
3
Example: Address Translation
• C - Language code
void func()
int x;
...
x = x + 3; // this is the line of code we are interested in
4
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.
5
Example: Address
0KB 128
Translation(Cont.)
• Fetch instruction at address 128
movl 0x0(%ebx),%eax
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 Heap • Execute this instruction (no memory reference)
4KB • Fetch the instruction at address 135
• Execute this instruction (store to address 15 KB)
heap
(free)
stack
14KB
15KB 3000
Stack
16KB
6
Relocation Address Space
• The OS wants to place the process somewhere else in physical
memory, not at address 0.
• The address space start at address 0.
7
A Single Relocated Process
0KB 0KB
16KB
Heap
(not in use)
32KB Code
Relocated Process
Heap
heap
(allocated but
(free) not in use)
Stack
stack 48KB
(not in use)
Stack
64KB
16KB Physical Memory
Address Space
8
Base and Bounds Register
0KB 0KB
16KB
Heap
(not in use) base register
32KB 32KB
Code
Heap
heap
(allocated but not in
(free) use)
Stack
stack 48KB
(not in use)
9
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.
10
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
stack
14KB
15KB 3000
Stack
16KB
11
Two ways of Bounds Register
0KB 0KB
16KB
Heap
(not in use)
32KB Code
Heap
(allocated
(free) but not in use)
bounds bounds
Stack
16KB 48KB 48KB
(not in use)
Stack
64KB
Physical Memory
16KB Address Space
12
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
13
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 in use.
0KB
Operating System
The OS lookup the free list
16KB
Free list
(not in use)
Stack
48KB 48KB
(not in use)
64KB
Physical Memory
14
OS Issues: When a Process Is Terminated
• The OS must put the memory back on the free list.
16KB 16KB
16KB 16KB
(not in use) (not in use)
32KB 32KB
15
OS Issues: When Context Switch Occurs
…
base : 32KB
0KB 0KB
Context Switching bounds : 48KB …
Operating System Operating System
16KB 16KB
16