0% found this document useful (0 votes)
69 views16 pages

Operating Systems Session 12 Address Translation

Uploaded by

mine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views16 pages

Operating Systems Session 12 Address Translation

Uploaded by

mine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 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()
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

• 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
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

Program Code Operating System


Program Code Operating System
16KB
Heap
Heap
(not in use)
(not in use)
32KB Code

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

Program Code Operating System


Program Code Operating System
16KB
Heap
Heap
(not in use) base register
(not in use)
32KB 32KB
Code 32KB
Code
Heap
Heap
heap
(allocated but not in
(allocated use) but not in
(free) use)
(free)
Stack
stack 48KB Stack

(not in use)
(not in use)

bounds register Stack


Stack 64KB
16KB Physical Memory
16KB 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 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

• Execute this instruction heap


• Load from address 15KB
(free)
(free)

stack

14KB

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

Program Code Operating System


Program Code Operating System
16KB
Heap
Heap (not in use)
(not in use)
32KB Code
Code
Heap
Heap
(allocated but
(allocated but
(free) not in use)
bounds (free) not in use)
bounds
Stack
16KB 48KB Stack 48KB
16KB 48KB

(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)

16KB 32KB Code


16KB Code
Heap
Heap
(allocated but not in use)
(allocated but not in use)
Stack
48KB 48KB Stack
48KB
(not in use)
(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


Operating System Operating System
16KB 16KB
16KB 16KB
16KB 16KB
(not in use) (not in use)
(not in use) (not in use)
32KB 32KB

Process A 32KB (not in use)


48KB Process A 32KB (not in use)
48KB
48KB 48KB

(not in use) (not in use)


(not in use) (not in use)
64KB 48KB 64KB
48KB
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
Operating System Operating System
16KB 16KB

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


(not in use) (not in use)
32KB 32KB 32KB 48KB
32KB 48KB
Process A
Process A bounds Process A bounds
Currently Running Process A
Currently Running
48KB 48KB 48KB 64KB
48KB 64KB
Process B
Process B Process B
Process B Currently Running
Currently Running
64KB 64KB

Physical Memory Physical Memory

16

You might also like