Professional Documents
Culture Documents
14 MemoryManagement
14 MemoryManagement
MAXsys
Starting at address 0
0, going to address MAXsys
MAXprog
Program
0
2
Basic Concepts
Address generation
1000
Library
Routines
Library
Routines
prog P
:
:
foo()
:
:
end P
P:
:
push ...
inc SP, x
jmp _foo
:
foo: ...
Compilation
0
:
push ...
inc SP, 4
jmp 75
:
...
75
Assembly
1100
100
175
:
:
:
jmp 175
:
...
Linking
1175
:
:
:
jmp 1175
:
...
Loading
4
Program Relocation
MAXsys
MEMORY
EXCEPTION
CPU
Logical
Addresses
Instructions
MAXprog
Program
Ps
logical
address
space
0
no
500
yes
Physical
Addresses
1000
1500 Program
Ps
physical
address
1000 space
Limit
Base
Register Register
0
6
External fragmentation
Unused memory between units of
allocation
E.g, two fixed tables for 2, but a party of 4
MAX
Internal fragmentation
Unused memory within a unit of allocation
E.g., a party of 3 at
a table for 4
Program Code
(text)
Program
Qs
PAS
Execution
Data Stack
Execution Stack
Program
0 Rs PAS
8
Simple approach:
Allocate a partition when a process is admitted
into the system
Allocate a contiguous memory partition to the
process
OS keeps track of...
Full-blocks
Empty-blocks (holes)
MAX Program
P1
Program
P2
P5
Program
P3
Allocation strategies
f
First-fit
Best-fit
Worst-fit
Program
P4
0
9
1K bytes
2K bytes
2K bytes
500 bytes
500 bytes
10
Simplicity of implementation
Requires:
q
Free block list sorted by address
Allocation requires a search for a suitable partition
De-allocation requires a check to see if the freed partition could be
merged with adjacent free partitions (if any)
Advantages
Simple
Tends to produce larger
free blocks toward the end
of the address space
Disadvantages
Slow allocation
External fragmentation
11
1K bytes
1K bytes
2K bytes
2K bytes
500 bytes
12
Disadvantages
Advantages
External fragmentation
Slow de-allocation
Tends to produce many
useless tiny fragments (not
really great)
1K bytes
1K bytes
2K bytes
500 bytes
14
Advantages
Works
W k best
b t if allocations
ll
ti
are of medium sizes
Disadvantages
Slow d
Sl
de-allocation
ll
ti
External fragmentation
Tends to break large free
blocks such that large
partitions cannot be allocated
15
Allocation strategies
First fit, best fit and worst fit all suffer from
external fragmentation.
A. True
B. False
16
Compaction
Relocate programs to coalesce holes
MAX Program
P1
Swapping
Preempt processes & reclaim their memory
Ready
ready
queue
Program
P2
g
Program
P3
Running
Waiting
Program
P4
Suspended
suspended
queue
semaphore/condition queues
0
17
Memory Management
Sharing Between Processes
2n-1
Schemes so far have considered only a single
dd
address
space per process
A single name space per process
No sharing
Heap
Run-Time
Program
Ps
Stack
VAS
Program
Data
Program
Text
0
Program Ps
VAS
18
2n-1
2n -1
4
Heapp
Heapp
n3
2 -1
Run-Time
Stack
0
Run-Time
Stack
2n -1
Program
Data
2n6-1
Program
Data
2n -1
Program
Program 0
Text
Text
1
Libraries
2n5-1
User
Code
19
n2
n1
addr
addr
Implementing Segmentation
Physical
Memory
Program
P
CPU
1500
MEMORY
EXCEPTION
Program
Ps
Segment
o
no
0 32
Logical
Addresses
Limit
Register
base
yes
500
1000
Base
1000 Register
limit
STBR
Segment Table
21
22