Professional Documents
Culture Documents
Introduction
Swapping
Fragmentation
Paging
Segmentation
Introduction
Introduction
Main memory and registers are only storage CPU can access directly
CPU cache
instructions
Registers
data Process
program image
in memory
Operating
System
Disk
Program addresses and memory
When code is generated (or
assembly program is written) we func variable
use memory addresses for
variables, functions and func variable
branching/jumping.
func variable
main
Those addresses can be physical or
logical memory addresses.
program
44
40
36
32
Cmp 28
Program 2
Sub 24
Program 1 Program 2
20
Jump 12 16
Add 12 Cmp 12 Program 1 Add 12
Mov 8 Sub 8
Mov 8
4 4
4
Jump 8 0 Jump 12 0
Jump 8 0
Logical address space concept
We need logical address space RAM
concept, that is different that phy_max
the physical RAM (main
memory) addresses.
logical base
address Program
Set of logical addresses used by
the program is its logical space
address space
Logical address space can be, 0
for example, [0, max_address]
0
Logical address space has to be
mapped somewhere in physical
memory
Base and Limit Registers
A pair of base and limit registers define the address space of a process
physical addresses
M[28+base] cmp .. 44
IR mov r1, M[28] mov r1, M[28] 40
M[28+24] mov r2, M[24] 36
M[52] add r1, r2, r3
a relocatable program 32
jmp 16 28
28 int x mov .. 24
24 int y;
logical addresses
20
20 cmp ..
16
16 mov r1, M[28]
12
12 mov r2, M[24]
08
08 add r1, r2, r3
04
04 jmp 16
00
00 mov ..
Memory-Management Unit (MMU)
The user program deals with logical addresses; it never sees the
real physical addresses
Dynamic Relocation
Dynamic relocation using a relocation register
Dynamic Loading
Best-fit: Allocate the smallest hole that is big enough; must search
entire list, unless ordered by size
Produces the smallest leftover hole
Worst-fit: Allocate the largest hole; must also search entire list
Produces the largest leftover hole
First-fit and best-fit better than worst-fit in terms of speed and storage
utilization
Fragmentation
Fragmentation
External Fragmentation:
total memory space exists to satisfy a request, but it is not
contiguous
Internal Fragmentation:
Suppose physical memory is divided into fix block sizes then
allocated memory may be slightly larger than requested memory
The different between allocated and required is called internal
fragmentation
Fragmentation (Cont.)
Divide physical memory into fixed-sized blocks called frames (size is power of 2,
between 512 bytes and 8,192 bytes)
To run a program of size n pages, need to find n free frames and load program
Paging Hardware
Paging (Cont.)
Process should share part of memory with other processes, but not
all of memory
Some memory may need to be exported read-only, other memory
exported read/write
Segments:
Program's memory is structured as a set of segments
Source: http://people.csail.mit.edu/rinard/osnotes/h15.html
Segmentation (Cont.)
Example of Segmentation
Suggested Reading