Operating Systems Session 12 Address Translation
Operating Systems Session 12 Address Translation
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()
void func()
int x;
int x;
...
...
x = x + 3; // this is the line of code we are interested in
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
128 : movl 0x0(%ebx), %eax ; load 0+ebx into eax
132 : addl $0x03, %eax ; add 3 to eax register
132 : addl $0x03, %eax ; add 3 to eax register
135 : movl %eax, 0x0(%ebx) ; store eax back to mem
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 Program Code • Fetch instruction at address 132
3KB Heap • Execute this instruction (no memory reference)
Heap
4KB • Fetch the instruction at address 135
• Execute this instruction (store to address 15 KB)
heap
(free)
(free)
stack
14KB
15KB 3000
3000
Stack
16KB Stack
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
Relocated Process
Code
Heap
Heap
heap
(allocated but
(allocated
not in use) but
(free) not in use)
(free)
Stack
stack 48KB Stack
(not in use)
(not in use)
Stack
Stack
64KB
16KB Physical Memory
Address Space
8
Base and Bounds Register
0KB 0KB
(not in use)
(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 Addl 0x03,%eax
128
128 :: movl
movl 0x0(%ebx),
0x0(%ebx), %eax
%eax 1KB 135 movl %eax,0x0(%ebx)
Program Code
2KB Program Code
3KB Heap
• Fetch instruction at address 128 Heap
4KB
stack
14KB
15KB 3000
3000
Stack
16KB Stack
11
Two ways of Bounds Register
0KB 0KB
(not in use)
(not in use)
Stack
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
Operating System
The OS lookup the free list
16KB
Free list
(not in use)
(not in use)
15
OS Issues: When Context Switch Occurs
…
base : 32KB
0KB 0KB
Context Switching bounds : 48KB …
Operating System Operating System
Operating System Operating System
16KB 16KB
16