Beruflich Dokumente
Kultur Dokumente
Basic Concepts
Address generation
0 1000
Library Library
Routines Routines
0 100 1100
prog P P:
: : :
: :
push ... : :
: push ...
inc SP, 4 : :
foo() inc SP, x jmp 175 jmp 1175
jmp 75
: jmp _foo : :
:
: : ... ...
75 ... 175 1175
end P foo: ...
4
Program Relocation
MAXsys
MEMORY
EXCEPTION
Logical no Physical
Addresses Addresses 1500 Program
CPU ≤ yes + P’s
physical
address
1000 space
Instructions 500 1000
MAXprog
Limit Base
Program Register Register
P’s
logical
address
space 0
0
6
With base and bounds registers, the OS needs a hole
in physical memory at least as big as the process.
¾AA. True
T
¾ B. False
External fragmentation
¾ Unused memory between units of MAX
allocation
¾ E.g, two fixed tables for 2, but a party of 4
Internal fragmentation
¾ Unused memory within a unit of allocation
¾ E.g., a party of 3 at
Program
a table for 4 Q’s
Program Code PAS
(“text”)
Execution
Data Stack
Execution Stack
Program
0 R’s PAS
8
Simple Memory Management Schemes
Dynamic allocation of partitions
MAX Program
Simple approach:
¾ Allocate a partition when a process is admitted P1
into the system
¾ Allocate a contiguous memory partition to the
process Program
P2
OS keeps track of...
Full-blocks P5
Empty-blocks (“holes”)
2K bytes 2K bytes
10
Rationale & Implementation
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 Disadvantages
Simple Slow allocation
Tends to produce larger External fragmentation
free blocks toward the end
of the address space
11
2K bytes 2K bytes
12
Rationale & Implementation
Requires:
¾ Free block list sorted by size
¾ Allocation requires search for a suitable partition
¾ De-allocation requires search + merge with adjacent free partitions,
if any
Advantages Disadvantages
Works well when most External fragmentation
allocations are of small size Slow de-allocation
Relatively simple Tends to produce many
useless tiny fragments (not
really great)
Doug Lea’s malloc “In most ways this malloc is a best-fit
allocator”
13
2K bytes
14
Rationale & Implementation
Requires:
¾ Free block list sorted by size
¾ Allocation is fast (get the largest partition)
¾ De-allocation requires merge with adjacent free partitions, if any,
and then adjusting the free block list
Advantages Disadvantages
Works
W k best
b t if allocations
ll ti Slow d
Sl de-allocation
ll ti
are of medium sizes 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
Dynamic Allocation of Partitions
Eliminating Fragmentation
MAX Program
Compaction
¾ Relocate programs to coalesce holes
P1
Swapping Program
¾ Preempt processes & reclaim their memory P2
g
Program
Ready Running
P3
ready
queue
? Waiting
Program
Suspended
P4
suspended
queue semaphore/condition queues 0
17
Memory Management
Sharing Between Processes
2n-1
Heap
Schemes so far have considered only a single
dd
address space per process
¾ A single name space per process Run-Time
Program
¾ No sharing P’s
Stack
VAS
Program
How can one share code and data between
Data
programs without paging?
Program
Text
0
Program P’s
VAS 18
Multiple Name Spaces
Example — Protection/Fault isolation & sharing
2n-1 2n -1
4
Heapp Heapp
n3
2 -1 0
Run-Time Run-Time
Stack Stack
2n -12
0
Program Program 2n6-1
Data Data Libraries
2n -1 1 0
Program Program 0 2n5-1
Text Text User
0 0 Code
0
19
n2 0 n1 0 n 0
s addr
s addr
20
Implementing Segmentation
Base + Limit register scheme Physical
Memory
s
STBR 0
Segment Table 21
… but leads to p
poor memory
y utilization
¾ We might not use much of a large segment, but we must keep the
whole thing in memory (bad memory utilization).
¾ Suffers from external fragmentation
¾ Allocation/deallocation of arbitrary size segments is complex
22