Operating System:
Chap8 Memory Management
National Tsing-Hua University
2016, Fall Semester
Overview
Background
Swapping
Contiguous Allocation
Paging
Segmentation
Segmentation with Paging
Background
Main memory and registers are the only storage CPU can access directly
Collection of processes are waiting on disk to be brought into memory and be executed
Multiple programs are brought into memory to improve resource utilization and response time to users
A process may be moved between disk and
memory during its execution
Outline
How to refer memory in a program?
address binding
How to load a program into memory ?
static/dynamic loading and linking
How to move a program between mem. & disk?
swap
How to allocate memory?
paging, segment
Multistep Processing of a User Program
Program is written as symbolic code
Compiler translates symbolic code into absolute code
If starting location changes
Example: MS-DOS .COM format binary
int data;
main( ) {
data = 3 * 7;
print(data);
}
.BASE 0x1000 .START
PUSH AX MOVE AX, 3 MULT AX, 7
MOVE (0x1018), AX CALL print, (0x1018) POP AX
.END
.SPACE (4)
PUSH AX MOVE AX, 3 MULT AX, 7
MOVE (0x1018), AX CALL print, (0x1018) POP AX
0x1000
0x1018 0x1010
Address Binding – Compile Time
Compile Load
recompile
int data;
main( ) {
data = 3 * 7;
print(data);
}
Source Program
.START
PUSH AX MOVE AX, 3 MULT AX, 7
MOVE (.BS+0x18), AX CALL print, (.BS+0x18) POP AX
.END
.SPACE (4)
Disk Image
PUSH AX MOVE AX, 3 MULT AX, 7
MOVE (0x2018), AX CALL print, (0x2018) POP AX
0x2000
0x2018 0x2010
Memory Content
Address Binding – Load Time
Compiler translates symbolic code into relocatable code
Relocatable code:
Machine language that can be run from any memory location
If starting location changes reload the code
Compile Load
Address Binding – Execution Time
Compiler translates symbolic code into logical-address (i.e. virtual-address) code
Special hardware (i.e. MMU) is needed for this scheme
Most general-purpose OS use this method
int data;
main( ) {
data = 3 * 7;
print(data);
}
.START
PUSH AX MOVE AX, 3 MULT AX, 7
MOVE (0x18), AX CALL print, (0x18) POP AX
.END
.SPACE (4)
PUSH AX MOVE AX, 3 MULT AX, 7
MOVE (0x18), AX CALL print, (0x18) POP AX
0x2000
0x2018 0x2010