Вы находитесь на странице: 1из 16

18CS2102R

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

• Memory virtualizing takes a similar strategy known as limited direct


execution(LDE) for efficiency and control.
• In memory virtualizing, efficiency and control are attained by
hardware support.
• e.g., registers, TLB(Translation Look-aside Buffer)s, page-table

2
Address Translation
• 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.

3
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

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

Program Code Operating System

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

Program Code Operating System

16KB
Heap
(not in use) base register
32KB 32KB
Code
Heap
heap
(allocated but not in
(free) use)

Stack
stack 48KB

(not in use)

bounds register Stack


64KB
16KB Physical Memory
16KB Address Space

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

• Fetch instruction at address 128 3KB Heap


4KB

• Execute this instruction heap


• Load from address 15KB
(free)

stack

14KB

15KB 3000
Stack
16KB
11
Two ways of Bounds Register
0KB 0KB

Program Code Operating System

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)

16KB 32KB Code


Heap
(allocated but 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.

Free list 0KB Free list 0KB

Operating System Operating System

16KB 16KB
16KB 16KB
(not in use) (not in use)

32KB 32KB

Process A 32KB (not in use)


48KB
48KB 48KB

(not in use) (not in use)


64KB 48KB 64KB
Physical Memory Physical Memory

15
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
0KB 0KB
Context Switching bounds : 48KB …
Operating System Operating System

16KB 16KB

(not in use) base (not in use) base

32KB 32KB 32KB 48KB


Process A
bounds Process A bounds
Currently Running
48KB 48KB 48KB 64KB
Process B
Process B
Currently Running
64KB 64KB

Physical Memory Physical Memory

16

Вам также может понравиться