Вы находитесь на странице: 1из 91

Chopfer 8: Memory Monogemenf

8ockground
Swopping
Configuous AIIocofion g
Poging
Segmenfofion Segmenfofion
Segmenfofion wifh Poging
CSCI bb73 FoII Z0II Memory 1
Chopfer 8: Memory Monogemenf
8ockground
Swopping
Configuous AIIocofion g
Poging
Segmenfofion Segmenfofion
Segmenfofion wifh Poging
CSCI bb73 FoII Z0II Memory 2
8ockground (I)
Memory
A Iorge orroy of words or byfes, eoch wifh ifs own oddress g y y
Progrom musf be broughf info memory ond pIoced
h f wifhin o process for if fo be run by CPU
Memory monogemenf gooI
Ieep mony processes in memory os possibIe os fo increose Ieep mony processes in memory os possibIe os fo increose
overoII sysfem performonce
Inpuf queue - coIIecfion of processes on fhe disk fhof
ore woifing fo be broughf info memory fo run fhe
progrom.
c. f. Peody queue - in memory
CSCI bb73 FoII Z0II Memory 3
8ock ground (Z) : EssenfioI issues 8ock ground (Z) EssenfioI issues
To ochieve gooI of memory monogemenf: g y g
Ieep mony processes in memory os possibIe os fo
increose overoII sysfem performonce
Which oreos ore free/used, by whom
0ive memory fo which process7
AIIocofion/deoIIocofion
Inferocfion wifh CPU scheduIing
CSCI bb73 FoII Z0II Memory 4
8ockground (Z) LogicoI vs. PhysicoI
Address Spoce Address Spoce
The concepf of o IogicoI oddress spoce fhof The concepf of o IogicoI oddress spoce fhof
is bound fo o seporofe physicoI oddress
spoce is cenfroI fo proper memory
monogemenf
0
monogemenf.
LogicoI oddress - generofed by fhe CPU,
oIso referred fo os virfuoI oddress.
PhysicoI oddress - oddress seen by fhe
memory unif.
LogicoI ond physicoI oddresses ore fhe some
in compiIe-fime ond Iood-fime oddress-
binding schemes, IogicoI (virfuoI) ond physicoI binding schemes, IogicoI (virfuoI) ond physicoI
oddresses differ in execufion-fime oddress-
binding scheme.
CSCI bb73 FoII Z0II Memory 5
8ockground (3): Memory-Monogemenf y
Unif (MMU)
Hordwore device fhof mops virfuoI fo physicoI
oddress.
In MMU scheme, fhe voIue in fhe reIocofion
regisfer is odded fo every oddress generofed regisfer is odded fo every oddress generofed
by o user process of fhe fime if is senf fo
memory. m m ry.
The user progrom deoIs wifh IogicoI oddresses, p g g
if never sees fhe reoI physicoI oddresses.
CSCI bb73 FoII Z0II Memory 6
8ockground (4): Dynomic reIocofion g ( ) y
User progrom
deoIs wifh deoIs wifh
IogicoI oddress
onIy
8ose regisfer
voIue needs fo be voIue needs fo be
odded fo eoch
IogicoI oddress
Memory Mgmf Unif
CSCI bb73 FoII Z0II Memory 7
Hordwore supporf
OverIoys
To enobIe o process fo be Iorger fhon fhe
f f II f d f if omounf of memory oIIocofed fo if.
Ieep in memory onIy fhose insfrucfions ond
d f fh f d d f i fi dofo fhof ore needed of ony given fime.
Lood in differenf informofion fo overIoy
previousIy used memory spoce previousIy used memory spoce
I I f d b i I f ImpIemenfed by user, no specioI supporf
needed from operofing sysfem,
i d i f I f f i progromming design of overIoy sfrucfure is
compIex
CSCI bb73 FoII Z0II Memory 8
ExompIe: W/O OverIoy
Progrom A - 70 I8, Progrom 8 - 80I8
S b I T bI Z0I8 C fi 30I8 SymboI TobIe - Z0I8 , Common roufine - 30I8
Symbol Table
Physical memory size
Common routine
Physical memory size
150 KB
Program A
Program B
Wifh f I
Con'f be Iooded
CSCI bb73 FoII Z0II Memory 9
Wifhouf overIoy
ExompIe: OverIoy(I)
Progrom A - 70 I8, Progrom 8 - 80I8
SymboI TobIe - Z0I8 , Common roufine - 30I8
OverIoy driver - I0 I8
Program A
Symbol Table
Common routine
Physical memory
g
Common routine
150 KB
Overlay driver
Program B
Wifh overIoy
CSCI bb73 FoII Z0II Memory 10
Program B
ExompIe: OverIoy(Z)
Progrom A - 70 I8, Progrom 8 - 80I8
SymboI TobIe - Z0I8 , Common roufine - 30I8
OverIoy driver - I0 I8
Symbol Table
Common routine
Physical memory
Common routine
150 KB
Overlay driver
Program A
Program B
Wifh overIoy
CSCI bb73 FoII Z0II Memory 11
Program B
ExompIe: OverIoy(3)
Progrom A - 70 I8, Progrom 8 - 80I8
SymboI TobIe - Z0I8 , Common roufine - 30I8
OverIoy driver - I0 I8
Program A
Symbol Table
Common routine
Physical memory
g
Common routine
150 KB
Overlay driver
Program B
Wifh overIoy
CSCI bb73 FoII Z0II Memory 12
OverIoys: Summory
Advonfoges
Peduce memory requiremenf
Disodvonfoges
OverIop mop musf be specified by progrommer p p p y p g
Progrommer musf know memory requiremenf
OverIopped moduIes musf be compIefeIy disjoinf pp p y j
CSCI bb73 FoII Z0II Memory 13
Chopfer 8: Memory Monogemenf
8ockground
Swopping
Configuous AIIocofion g
Poging
Segmenfofion Segmenfofion
Segmenfofion wifh Poging
CSCI bb73 FoII Z0II Memory 14
Swopping
A process con be swopped fempororiIy ouf of memory
fo o bocking sfore, ond fhen broughf bock info
memory for confinued execufion memory for confinued execufion.
8ocking sfore - fosf disk Iorge enough fo
occommodofe copies of oII memory imoges for oII p y g
users, musf provide direcf occess fo fhese memory
imoges.
PoII ouf roII in swopping vorionf used for priorify PoII ouf, roII in - swopping vorionf used for priorify-
bosed scheduIing oIgorifhms, Iower-priorify process is
swopped ouf so higher-priorify process con be Iooded pp g p y p
ond execufed.
Mojor porf of swop fime is fronsfer fime, fofoI
fronsfer fime is direcfIy proporfionoI fo fhe omounf fronsfer fime is direcfIy proporfionoI fo fhe omounf
of memory swopped.
Modified versions of swopping ore found on mony
CSCI bb73 FoII Z0II Memory 15
Modified versions of swopping ore found on mony
sysfems, i.e., UMIX, Linux, ond Windows.
Swopping
Move ouf ond bock in Iofer
ExompIe: priorify
k h 8ock fo fhe some memory spoce 7
Overheod: fronsfer fime
SoIufion: execufion fime shouId be Ionger fhon fronsfer fime
CSCI bb73 FoII Z0II Memory 16
g
Who shouId be swopped ouf7
Swopping
Where fo swop bock info7
CompiIe or Iood fime oddress binding fhe some memory spoce mp r o f m o r n ng fh om m m ry poc
Execufion fime oddress binding differenf memory spoce
C f f if hi fi Confexf swifching fime
User process si;e ~ I M8
Tronsfer rofe for hord disk ~ b M8/sec Tronsfer rofe for hord disk b M8/sec
Mo diskheod seek fime buf overoge Iofency of 8 ms
confexf swifching fime ~ Z08 + Z08 ~ 4Io ms
H PP f h Id b I fh 4Io f b ffi i f Hence, PP quonfum shouId be Iorger fhon 4Io ms fo be efficienf
Pending I/O consfroinfs Pending I/O consfroinfs
(SoIufion I) Mever swop o process wifh pending I/O
(SoIufion Z) execufe I/O operofions onIy info OS buffers ond
f h h d
CSCI bb73 FoII Z0II Memory 17
fronsfer fhem fo process memory when o process is swopped in
Memory Monogemenf Techniques
Fragmentation Simple Memory divided into static
!"#$%"&&"& '()"%*(+& ,"&-)./(.0% 1"-+%.23"
Need for compaction to No internal fragmentation Processes get exact partition
D i
Fragmentation
Fixed # of active processes
Simple
Little overhead
Memory divided into static
partitions (fixed or unequal)
Process get partition of equal
or greater size
Fixed Partitioning
Small amount of internal
f t ti
No external fragmentation Memory divided into equal-
i f
Need for compaction to
counter external fragmentation
No internal fragmentation
Efficient use of memory
Processes get exact partition
size at load time
Dynamic
Partitioning
External fragmentation No internal fragmentation Processes divided into
t Simple
fragmentation size frames
Processes use available pages
Simple Page
Overhead of complex
t
No external fragmentation Simple paging
Virtual Memory
Improved memory usage
Reduced overhead
segments
Segments loaded into
dynamic partitions
Simple
Segmentation
Overhead of complex
memory management
No internal fragmentation
Large virtual address space
Simple segmentation
Segments loaded/unloaded as
Virtual Memory
S t ti
memory management
Large virtual address space
Multiprogramming
Pages loaded/unloaded as
necessary
V u e o y
Paging
CSCI bb73 FoII Z0II Memory 18
Protection and sharing
necessary
Segmentation
Chopfer 8: Memory Monogemenf
8ockground
Swopping
Configuous AIIocofion g
Poging
Segmenfofion Segmenfofion
Segmenfofion wifh Poging
CSCI bb73 FoII Z0II Memory 19
Configuous AIIocofion (I)
Moin memory usuoIIy info fwo
porfifions:
Pesidenf operofing sysfem usuoIIy heId
0
OS
Pesidenf operofing sysfem, usuoIIy heId
in Iow memory wifh inferrupf vecfor.
User processes fhen heId in high
memory
OS
memory.
SingIe-porfifion oIIocofion
PeIocofion-regisfer scheme used fo g
profecf user processes from eoch ofher,
ond from chonging operofing-sysfem code
ond dofo.
User
Processes
PeIocofion regisfer confoins voIue of
smoIIesf physicoI oddress
Limif regisfer confoins ronge of IogicoI Limif regisfer confoins ronge of IogicoI
oddresses
eoch IogicoI oddress musf be Iess fhon
fhe Iimif regisfer
CSCI bb73 FoII Z0II Memory 20
fhe Iimif regisfer.
A bose ond o Iimif regisfer define
o IogicoI oddress spoce o IogicoI oddress spoce
CSCI bb73 FoII Z0II Memory 21
Hordwore Supporf for PeIocofion ond Limif
Pegisfers Pegisfers
CSCI bb73 FoII Z0II Memory 22
Configuous AIIocofion (Z)
I I II MuIfipIe-porfifion oIIocofion
Fixed porfifions
M di id d i fi d I h
OS
Memory divided info fixed-Iengfh
porfifions
A process is oIIocofed fo I or more
PI
p
porfifions
SimpIe buf inefficiency
PZ
Process Pequesf
Memory
Wosfed
(frogmenf) P3
PI 40 Z0+40
PZ 80 Ib+b
P3 II0 90
P4 I30 I00
CSCI bb73 FoII Z0II Memory 23
Eoch porfifion I00
P4 I30 I00
Configuous AIIocofion (3)
dynomic oIIocofion (VoriobIe si;e Porfifion)
When o process orrives, OS oIIocofes memory fo if from o
free chunk big enough free chunk big enough
HoIe
bIock of ovoiIobIe memory
II b d b Too smoII fo be used by ony processes
OS moinfoins informofion
Ieep frock of oIIocofed / free porfifions (hoIes) p p ( )
OS
5
OS
5
OS
5
OS
5 process 5
process 8
process 5 process 5 process 5
process 9 process 9
process 10
process 8
process 2 process 2 process 2 process 2
process 10
CSCI bb73 FoII Z0II Memory 24
Dynomic Sforoge-AIIocofion ProbIem
Firsf-fif
How fo sofisfy o requesf of si;e n from o Iisf of free hoIes7
F f
Find fhe firsf hoIe fhof is big enough
Eosy, fosf, IikeIy fo hove Iorge chunk of memory
8 f fif 8esf-fif
Find fhe smoIIesf hoIe fhof big enough
Lorge chunk of memory ovoiIobIe Lorge chunk of memory ovoiIobIe
A Iof of seorch fime
Lofs of smoII frogmenf useIess
f Worsf-fif
Find fhe Iorgesf hoIe ond oIIocofe
A Iof of seorch fime A Iof of seorch fime
LikeIy Iorgesf Ieff hoIes
Firsf-fif ond besf-fif beffer fhon worsf-fif in ferms of speed ond
CSCI bb73 FoII Z0II Memory 25
p
sforoge ufiIi;ofion. Firsf-fif is generoIIy fosfer
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
I0 k
4 k
I0 k
4 k
I0 k
4 k
I0 k
4 k
I0 k
4 k
I0 k
4 k
I0 k
4 k
I0 k
4 k
I0 k
4 k
Z0 k
Z0 k
I k
Z0 k
I k
Z0 k
I8 k
Z0 k
I k
Z0 k
I8 k
Z0 k
I8 k
Z0 k
I8 k
Z0 k
I8 k
I8 k
7 k
9 k
I8 k
7 k
9 k
I8 k
7 k
9 k
I8 k
7 k
9 k
I8 k
7 k
9 k
I8 k
7 k
9 k
I8 k
7 k
9 k
I8 k
7 k
9 k
I8 k
7 k
9 k
9 k
IZ k
9 k
IZ k
9 k
IZ k
9 k
IZ k
9 k
IZ k
9 k
IZ k
9 k
IZ k
9 k
IZ k
9 k
IZ k
Worsf fif
Firsf fif
8esf fif
Ib k
Currenf
Ib k Ib k
Ib k
Ib k
Ib k
Ib k Ib k
Ib k
CSCI bb73 FoII Z0II Memory 26
Worsf fif
Firsf fif
8esf fif Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $
7 $
45 $
85 $
85 $
49 $
49 $
: $
; $
49 $
: $
; $
; $
48 $
; $
48 $
Firsf fif
4< $
Currenf
4< $
CSCI bb73 FoII Z0II Memory 27
Firsf fif
Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $
7 $
45 $
85 $
85 $
49 $
48 $
9 $
49 $
: $
; $
49 $
: $
; $
; $
48 $
; $
48 $
Firsf fif
4< $
Currenf
4< $
CSCI bb73 FoII Z0II Memory 28
Firsf fif
Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $
7 $
45 $
85 $
85 $
49 $
48 $
9 $
; $
49 $
: $
; $
49 $
: $
; $
; $
; $
48 $
; $
48 $
Firsf fif
4< $
Currenf
4< $
CSCI bb73 FoII Z0II Memory 29
Firsf fif
Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $
7 $
45 $
85 $
85 $
49 $
48 $
9 $
; $
49 $
: $
; $
49 $
: $
; $
; $
; $
48 $
; $
48 $
Firsf fif
4< $
Currenf
4< $
CSCI bb73 FoII Z0II Memory 30
Firsf fif
Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $
7 $
45 $
85 $
85 $
49 $
48 $
9 $
; $
Can allocate
49 $
: $
; $
49 $
: $
; $
; $
20K ?
; $
48 $
; $
48 $
Firsf fif
4< $
Currenf
4< $
CSCI bb73 FoII Z0II Memory 31
Firsf fif
Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $
7 $
45 $ 45 $
7 $
85 $
85 $
49 $
48 $
9 $
; $
85 $
49 $
49 $
: $
; $
49 $
: $
; $
; $
49 $
: $
; $
; $
48 $
; $
48 $
; $
48 $
Firsf fif
4< $
Currenf
4< $ 4< $
8esf fif
CSCI bb73 FoII Z0II Memory 32
Firsf fif
Currenf
8esf fif
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $
7 $
45 $ 45 $
7 $
45 $
85 $
85 $
49 $
48 $
9 $
; $
85 $
49 $
49 $
: $
; $
49 $
: $
; $
; $
49 $
: $
; $ ; $
; $
48 $
; $
48 $
; $
48 $ 48 $
; $
Firsf fif
8esf fif
4< $
Currenf
4< $ 4< $
CSCI bb73 FoII Z0II Memory 33
Firsf fif
8esf fif Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $
7 $
45 $ 45 $
7 $
45 $
85 $
85 $
49 $
48 $
9 $
; $
85 $
49 $
49 $
: $
; $
49 $
: $
; $
; $
49 $
: $
; $
; $
48 $
; $
48 $
; $
48 $ 48 $
Firsf fif
8esf fif
4< $
Currenf
4< $
4< $
CSCI bb73 FoII Z0II Memory 34
Firsf fif
8esf fif Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $
7 $
45 $ 45 $
7 $
45 $
85 $
85 $
49 $
48 $
9 $
; $
85 $
49 $
49 $
: $
; $
49 $
: $
; $
; $
49 $
: $
; $ ; $
; $
48 $
; $
48 $
; $
48 $ 48 $
; $
Firsf fif
8esf fif
4< $
Currenf
4< $ 4< $
CSCI bb73 FoII Z0II Memory 35
Firsf fif
8esf fif Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $
7 $
45 $ 45 $
7 $
45 $
85 $
85 $
49 $
48 $
9 $
; $
85 $
49 $
49 $
: $
; $
49 $
: $
; $
; $
49 $
: $
; $ ; $
; $
48 $
; $
48 $
; $
48 $ 48 $
; $
Firsf fif
8esf fif
4< $
Currenf
4< $ 4< $
CSCI bb73 FoII Z0II Memory 36
Firsf fif
8esf fif Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $
7 $
45 $ 45 $
7 $
45 $
85 $
85 $
49 $
48 $
9 $
; $
85 $
49 $
49 $
: $
; $
49 $
: $
; $
; $
49 $
: $
; $ ; $
; $
48 $
; $
48 $
; $
48 $ 48 $
; $
Firsf fif
8esf fif
4< $
Currenf
4< $ 4< $
CSCI bb73 FoII Z0II Memory 37
Firsf fif
8esf fif Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $ 45 $
7 $
45 $
7 $
45 $
45 $
7 $
85 $
49 $
85 $
49 $
85 $
49 $
48 $
9 $
; $
85 $
49 $
49 $
: $
; $ ; $
49 $
: $
; $
49 $
: $
; $
; $
49 $
: $
; $
; $
48 $ 48 $
; $ ; $
48 $
; $
48 $
; $
48 $
Worsf fif
Firsf fif
8esf fif
4< $ 4< $ 4< $
4< $
Currenf
CSCI bb73 FoII Z0II Memory 38
Worsf fif
Firsf fif
8esf fif Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $ 45 $
7 $
45 $
7 $
45 $
45 $
7 $
85 $
49 $
85 $
49 $
45 $
45 $
85 $
49 $
48 $
9 $
; $
85 $
49 $
49 $
: $
; $ ; $
49 $
: $
; $
49 $
: $
; $
; $
49 $
: $
; $
; $
48 $ 48 $
; $ ; $
48 $
; $
48 $
; $
48 $
Worsf fif
Firsf fif
8esf fif
4< $ 4< $ 4< $
4< $
Currenf
CSCI bb73 FoII Z0II Memory 39
Worsf fif
Firsf fif
8esf fif Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $ 45 $
7 $
45 $
7 $
45 $
45 $
7 $
85 $
49 $
85 $
49 $
45 $
45 $
48 $
85 $
49 $
48 $
9 $
; $
85 $
49 $
49 $
: $
; $ ; $
49 $
: $
; $
= $
49 $
: $
; $
; $
49 $
: $
; $
; $
48 $ 48 $
; $ ; $
48 $
; $
48 $
; $
48 $
Worsf fif
Firsf fif
8esf fif
4< $ 4< $ 4< $
4< $
Currenf
CSCI bb73 FoII Z0II Memory 40
Worsf fif
Firsf fif
8esf fif Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $ 45 $
7 $
45 $
7 $
45 $
45 $
7 $
85 $
49 $
85 $
49 $
45 $
45 $
48 $
85 $
49 $
48 $
9 $
; $
85 $
49 $
49 $
: $
; $ ; $
49 $
: $
; $
= $
49 $
: $
; $
; $
49 $
: $
; $
; $
48 $ 48 $
; $ ; $
48 $
; $
48 $
; $
48 $
Worsf fif
Firsf fif
8esf fif
4< $ 4< $
; $
= $
4< $
4< $
Currenf
CSCI bb73 FoII Z0II Memory 41
Worsf fif
Firsf fif
8esf fif Currenf
Free memory spoce oIgorifhms exercise
Memory Pequesf order : I0I, IZI, 9I, IbI, Z0I
45 $
7 $
45 $ 45 $
7 $
45 $
7 $
45 $
45 $
7 $
85 $
49 $
85 $
49 $
45 $
45 $
48 $
85 $
49 $
48 $
9 $
; $
85 $
49 $
49 $
: $
; $ ; $
49 $
: $
; $
= $
49 $
: $
; $
; $
49 $
: $
; $
; $
48 $ 48 $
; $ ; $
48 $
; $
48 $
; $
48 $
Worsf fif
Firsf fif
8esf fif
4< $ 4< $
; $
= $
4< $
4< $
Currenf
CSCI bb73 FoII Z0II Memory 42
Worsf fif
Firsf fif
8esf fif Currenf
15K ? 20K?
Commenfs on PIocemenf AIgorifhm
Firsf-fif fovors oIIocofion neor fhe beginning: fends fo
creofe Iess frogmenfofion fhen Mexf-fif creofe Iess frogmenfofion fhen Mexf-fif.
Mexf-fif offen Ieods fo oIIocofion of fhe Iorgesf bIock
of fhe end of memory. of fhe end of memory.
8esf-fif seorches for smoIIesf bIock: fhe frogmenf
Ieff behind is smoII os possibIe - p
moin memory quickIy forms hoIes foo smoII fo hoId ony process:
compocfion generoIIy needs fo be done more offen.
Firsf/Mexf-fif ond 8esf-fif beffer fhon Worsf-fif
(nome is fiffing) in ferms of speed ond sforoge
fiIi fi ufiIi;ofion.
CSCI bb73 FoII Z0II Memory 43
PepIocemenf AIgorifhm p g
When oII processes in moin memory
ore bIocked, fhe OS musf choose
which process fo repIoce: p p
A process musf be swopped ouf (fo o
8Iocked-Suspend sfofe) ond be repIoced 8Iocked Suspend sfofe) ond be repIoced
by o process from fhe Peody-Suspend
queue or o new process queue or o new process.
CSCI bb73 FoII Z0II Memory 44
InfernoI Frogmenfofion g
Hove some "empfy" spoce for eoch processes
OS
A sfock
OS
A d f
Poom for growfh
AIIocofed fo A
A progrom
A dofo
InfernoI Frogmenfofion - oIIocofed memory fo o process moy be InfernoI Frogmenfofion oIIocofed memory fo o process moy be
sIighfIy Iorger fhon requesfed memory ond nof being used.
e.g. requesf I0I0 byfes, oIIocofe I0Z4 byfes (II8)
P d f i
CSCI bb73 FoII Z0II Memory 45
Peduce free spoce moinfenonce cosf
ExfernoI Frogmenfofion
ExfernoI Frogmenfofion - fofoI memory g y
spoce exisfs fo sofisfy requesf buf if is nof
configuous g
OS
50k
OS
process 3
Process 9 125k ?
process 8
100k
process 2
CSCI bb73 FoII Z0II Memory 46
AnoIysis of ExfernoI Frogmenfofion AnoIysis of ExfernoI Frogmenfofion
Assume:
sysfem of equiIibrium
process in middIe p
if M processes, I/Z fime process, I/Z hoIe
~~ I/Z M hoIesl
Fiff f I Fiffy-percenf ruIe
FundomenfoI:
odjocenf hoIes combined odjocenf hoIes combined
odjocenf processes nof combined
CSCI bb73 FoII Z0II Memory 47
Compocfion
ShuffIe memory confenfs fo pIoce oII free
memory fogefher in one Iorge bIock m mory fog fh r n on org oc
OnIy if reIocofion dynomicl
(a) (b)
OS
process 3
OS
50k
OS
(a) (b)
OS OS OS
Process 9
125k
process 3
process 8
process 3
50k
90k
process 8 process 8 60k
process 2 process 2
100k
process 2
process 3
CSCI bb73 FoII Z0II Memory 48
p p p
Cosf of Compocfion
50k
process1 process 1
process 3
process 3
50k
90k
process 3
process 8
process 8 60k
process 2
process 2
100k
p
IZ8 M8 PAM, I00 nsec/occess
I.b seconds fo compocfl
Disk much sIowerl
CSCI bb73 FoII Z0II Memory 49
Disodvonfoges of Porfifioning
Frogmenfofion is unovoidobIe
Wonf fo minimi;e exfernoI frogmenfofion Wonf fo minimi;e exfernoI frogmenfofion
Lorge 8Iocks
8uf infernoI frogmenfofionl
Trodeoff Trodeoff
Socrifice some infernoI frogmenfofion for reduced exfernoI
frogmenfofion
SoIufion: use poging ond/or segmenfofion p g g g
Musf Iood enfire process info memory
Limifs fhe number of ocfive processes Limifs fhe number of ocfive processes
Why sfudy porfifioning
HisforicoI reosons
Poging ond segmenfofion ore bosed on if
Moy sfiII be used for dynomic (heop) oIIocofion
CSCI bb73 FoII Z0II Memory 50
SoIufion7
Wonf fo minimi;e exfernoI frogmenfofion
Lorge 8Iocks
8uf infernoI frogmenfofionl
Trodeoff
Socrifice some infernoI frogmenfofion for g
reduced exfernoI frogmenfofion
Poging, segmenfofion
CSCI bb73 FoII Z0II Memory 51
Chopfer 8: Memory Monogemenf
8ockground
Swopping
Configuous AIIocofion g
Poging
Segmenfofion Segmenfofion
Segmenfofion wifh Poging
CSCI bb73 FoII Z0II Memory 52
Poging: Mofivofion og ng Mof of on
Mofivofion
Avoids fhe considerobIe probIem of fiffing fhe
vorying-si;ed memory chunks onfo fhe bocking
sf sfore
Frogmenfofion in bocking sfore
SoIufion:
LogicoI oddress is oIwoys configuous, buf physicoI
oddress con be nonconfiguous
divide IogicoI oddress, memory oddress, ond
bocking sfore info fixed-Iengfh bIocks
CSCI bb73 FoII Z0II Memory 53
Poging Pog ng
Poges & fromes
Divide IogicoI oddress info poges
Main Memory Frame
0
1
D v de Iog coI oddress nfo poges
Divide physicoI memory info
fromes
2
3
4
>#*" &.?" @ A)#B" &.?"
si;e is power of Z byfes of [bIZ,
8I9Z] for efficienf oddress
4
5
6
7
8I9Z] for efficienf oddress
fronsIofion
For o progrom occupying n poges n
7
8
9
For o progrom occupying n poges, n
fromes need fo be oIIocofed
A poge fobIe is used fo sfore fhe
b & f
10
11
12
moppings befween poges & fromes
InfernoI frogmenfofion exisfs
M f I f f fi
13
14
15
CSCI bb73 FoII Z0II Memory 54
Mo exfernoI frogmenfofion
Poging
0ooI: EIiminofe exfernoI frogmenfofion
Ideo: Divide memory info fixed-si;ed poges
Z E I 4I8 Si;e: Z
n
, ExompIe: 4I8
PhysicoI poge: poge frome
e
w
a
l

V
i
e
P
h
y
s
i
c
Process 1
P
Process 2
Process 3
CSCI bb73 FoII Z0II Memory 55
Logical View
Poging Hordwore
Address generofed by CPU divided info:
Poge number (p) - index fo poge fobIe g (p) p g
poge fobIe confoins bose oddress of eoch poge in physicoI
memory (frome)
P ff (d) ff i /f Poge offsef (d) - offsef info poge/frome
CPU
p
d f d
LogicoI oddress physicoI oddress
CPU
p
d f d
physicoI
p
f memory
p
CSCI bb73 FoII Z0II Memory 56
poge fobIe
Poging ExompIe (I)
Progrom hos 4 poges
P i 4 b f
Poge 0
0
I
Poge si;e 4 byfes
Memory si;e 3Z byfes (8 poges)
oge 0
I
Z
I 0
Poge 0
Poge I
Poge Z
3
4 I
Poge I
P Z
Poge I
4
b
3
7
Z
3
Poge Z
Poge 3
o
7 3
Poge TobIe LogicoI
Memory
PhysicoI Memory
Poge 3
7
CSCI bb73 FoII Z0II Memory 57
Memory
y y
Poging ExompIe (Z)
Off
o
g
e

0
000
000
00I
Offsef
P
o
I
00I
0I0
00I
0I0
0 0 I 0 I I
Poge Frome
P
o
g
e

0I 00
0II
0II
Poge Frome
P
o
g
e

Z
II
00
0I
I0
I00
I0I
I00
I0I
P
e

3
00
I0
I0
II
I0I
II0
I0I
II0
P
o
g
e
Poge TobIe
III
Ph i I M
III
CSCI bb73 FoII Z0II Memory 58
LogicoI Memory
PhysicoI Memory
Poging ExompIe (3)
Assumpfion: Poge si;e ~ frome si;e ~ 4 byfes
CSCI bb73 FoII Z0II Memory 59
Poging ExompIe (4) - Hordwore
oddress spoce Z
m
poge offsef Z
n
poge number Z
m-n
physicoI
poge number
memory
Z
m
byfes
poge number
p
poge offsef
d p d
m-n n
nofe: nof Iosing ony byfesl
m bifs
CSCI bb73 FoII Z0II Memory 60
nofe: nof Iosing ony byfesl
Poging Trodeoffs
Advonfoges
no exfernoI frogmenfofion (no compocfion) no exfernoI frogmenfofion (no compocfion)
reIocofion (now poges, before were processes)
Disodvonfoges Disodvonfoges
infernoI frogmenfofion
consider: Z048 byfe poges, 7Z,7oo byfe proc cons der 0 8 byfe poges, 7 ,7oo byfe proc
3b poges + I08o byfes ~ 9oZ byfes
ovg: I/Z poge per process
II l smoII pogesl
overheod
poge fobIe / process (confexf swifch + spoce) poge fobIe / process (confexf swifch spoce)
Iookup (especioIIy if poge fo disk)
CSCI bb73 FoII Z0II Memory 61
Free Fromes
OS moinfoins o
free frome Iisf
A new process
hos 4 poges
OS creofes o
poge fobIe wifh 4
f i enfries
OS oIIocofes 4
free fromes from free fromes from
fhe free-frome-
Iisf ond fiIIs fhe Iisf ond fiIIs fhe
poge fobIe
8 f II i
Aff II fi
CSCI bb73 FoII Z0II Memory 62
8efore oIIocofion
Affer oIIocofion
ImpIemenfofion of Poge TobIe
Poge fobIe kepf in regisfers
F fl Fosfl
OnIy good when number of fromes is smoII
Expensivel Expensivel
Pegisfers
MMemory
Disk
CSCI bb73 FoII Z0II Memory 63
ImpIemenfofion of Poge TobIe
Eoch process hos ifs own poge fobIe
Poge fobIe kepf in moin memory og fo pf n mo n m m ry
Poge TobIe 8ose Pegisfer (PT8P)
0
I 3
Poge 0
P I
I
3
0
I
Poge 0 I
Z
Poge I 3 I
Poge TobIe
LogicoI
Poge I
Z
3
PT8P
Poge TobIe
Memory
PhysicoI
Memory
Poge TobIe Lengfh
Two memory occesses per dofo/insf occess.
SoIufion7 Associofive Pegisfers
CSCI bb73 FoII Z0II Memory 64
SoIufion7 Associofive Pegisfers
Poge TobIe Sforoge Poge TobIe Sforoge
In moin memory In moin memory
Advonfoge
UnIimifed poge fobIe si;e p g
Swopping overheod Iow since onIy chonge PT8P
Disodvonfoge
E d / d Every dofo/insfrucfion occess needs Z memory
occesses
One on poge fobIe for frome # p g
One for reoI oddress
CSCI bb73 FoII Z0II Memory 65
Poge TobIe Sforoge
Associofive memory
TronsIofion Iook-oside buffers TronsIofion Iook oside buffers
(TL8s)
Fosf Iookup hordwore coche
Advonfoge Advonfoge
Coche musf fosfer occess speed
Sove fhe firsf round fime
Disodvonfoge
Poge # Frome #
Disodvonfoge
Expensive hordwore
Lood poge fobIe porfs fo TL8s
If missed, sfiII need fo occess If missed, sfiII need fo occess
moin memory
Address fronsIofion (A, A)
If A is in ossociofive regisfer If A is in ossociofive regisfer,
gef frome # ouf.
Ofherwise gef frome # from poge
fobIe in memory
CSCI bb73 FoII Z0II Memory 66
y
Poging hordwore wifh TL8
d
IogicoI
oddress
CPU
p d
f d
poge frome
oddress
physicoI
oddress
CPU
f d
physicoI
p g
number number
physicoI
memory
TL8 hif
TL8
p
f
TL8 miss
p
CSCI bb73 FoII Z0II Memory 67
poge fobIe
Effecfive Access Time
Associofive Lookup ~ fime unif
A I fi i I i d Assume memory cycIe fime is I microsecond
Hif rofio - percenfoge of fimes fhof o poge
number is found in fhe ossociofive regisfers, number is found in fhe ossociofive regisfers,
rofion reIofed fo number of ossociofive regisfers.
Hif rofio ~ Hif rofio ~
Effecfive Access Time (EAT)
EAT ~ (I + ) + (Z + )(I ) EAT ~ (I + ) + (Z + )(I - )
~ Z + -
CSCI bb73 FoII Z0II Memory 68
TL8 Performonce
Hif Pofio - percenfoge of fimes fhof o poge
b i f d i i fi i f number is found in ossociofive regisfers
Effecfive occess fime ~ Effecfive occess fime ~
hif rofio hif rofio xx hif fime + miss rofio hif fime + miss rofio xx miss fime miss fime
hif fime ~ reg fime + mem fime g
miss fime ~ reg fime + mem fime ^ Z
ExompIe: E mp
807 hif rofio, reg fime ~ Z0 nonosec, mem fime
~ I00 nonosec
.80 ^ IZ0 + .Z0 ^ ZZ0 ~ I40 nonoseconds
CSCI bb73 FoII Z0II Memory 69
Advonced Poge TobIe Sfrucfure
HierorchicoI Poging HierorchicoI Poging
For Iorge poge fobIe
Hoshed Poge TobIes Hoshed Poge TobIes
For very Iorge poge fobIe
I d P T bI Inverfed Poge TobIes
One frome fobIe for fhe whoIe memory spoce
CSCI bb73 FoII Z0II Memory 70
HierorchicoI Poge TobIes
TypicoI IogicoI oddress spoces:
4 0byfes ~ Z
3Z
oddress bifs (4-byfe oddress) 4 0byfes Z oddress bifs (4 byfe oddress)
TypicoI poge si;e:
4 Ibyfes ~ Z
IZ
bifs
Poge fobIe moy hove:
Z
3Z
/ Z
IZ
~ Z
Z0
~ I miIIion enfries
E h f 4 b f s 4M8 ssl Eoch enfry 4 byfes ~ 4M8 per processl
Do nof wonf fhof oII in PAM
SoIufion7 SoIufion7
Divide fhe poge info smoIIer pieces
MuIfiIeveI poging p g g
Poge fobIe ifseIf becomes poged
CSCI bb73 FoII Z0II Memory 71
Two-LeveI Poging
A IogicoI oddress
3Z-bif mochine
4I poge si;e
o poge #: Z0 bifs (Z
3Z
/ Z
IZ
)
ff f IZ bif (4I Z
IZ
) o poge offsef: IZ bifs (4I ~ Z
IZ
)
Poge fobIe is poged, fhe poge # is furfher divided info
I0 bif poge number I0-bif poge number
I0-bif poge offsef
poge number poge offsef
p
i
p
Z
d
I0 I0 IZ
d
CSCI bb73 FoII Z0II Memory 72
Two-LeveI Poge-TobIe Scheme
CSCI bb73 FoII Z0II Memory 73
MuIfiIeveI Poging TronsIofion
poge number poge offsef
Address-fronsIofion scheme for o fwo-IeveI 3Z-bif poging orchifecfure
poge number
pI
poge offsef
d pZ
Z
pI
f
d
pZ
oufer poge
fobIe inner poge
fobIe
desired
poge
CSCI bb73 FoII Z0II Memory 74
fobIe
MuIfiIeveI Poging
b ff poge number
pI
poge offsef
d
I0 IZ
pZ
I0
...
I0 IZ I0
Poge 0
...
...
...
...
O f P
LogicoI
Oufer Poge
TobIe
g
Memory
...
CSCI bb73 FoII Z0II Memory 75
Poge TobIe
Hoshed Poge TobIes Hoshed Poge TobIes
Very Iorge IogicoI oddress Very Iorge IogicoI oddress
3Z bifs
The virfuoI poge # is hoshed info o poge The virfuoI poge # is hoshed info o poge
fobIe
Eoch enfry confoins o choin of eIemenfs hoshing y g
fo fhe some physicoI Iocofion
VirfuoI poge # is compored in fhis choin
seorching for o mofch
CSCI bb73 FoII Z0II Memory 76
Hoshed Poge TobIe
A Iinked Iisf
CSCI bb73 FoII Z0II Memory 77
A Iinked Iisf
Inverfed Page Table
Mofivofion Mofivofion
Poge fobIes occupy foo much memory
SoIufion
OnIy one poge fobIe for fhe whoIe sysfem
Eoch enfry refIecfs eoch frome y
Which process fhof uses if
Poge # of fhe process
CSCI bb73 FoII Z0II Memory 78
Inverfed Poge TobIe g
Poge fobIe mops fo physicoI oddresses
CPU pid d p p p
i d
e
o
r
c
h
pid p
i
PhysicoI
s
e
p p
y
Memory
Memory occesses Iongerl (seorch + swop)
(Used by PowerPC ond UIfro Sporc)
CSCI bb73 FoII Z0II Memory 79
Chopfer 8: Memory Monogemenf
8ockground
Swopping
Configuous AIIocofion g
Poging
Segmenfofion Segmenfofion
Segmenfofion wifh Poging
CSCI bb73 FoII Z0II Memory 80
Segmenfofion
Memory-monogemenf scheme fhof supporfs user
view of memory view of memory.
A progrom is o coIIecfion of segmenfs. A segmenf
is o IogicoI unif such os: is o IogicoI unif such os:
moin progrom,
procedure, p ,
funcfion,
mefhod,
objecf,
IocoI voriobIes, gIoboI voriobIes,
common bIock common bIock,
sfock,
symboI fobIe, orroys
CSCI bb73 FoII Z0II Memory 81
y y
Memory View Users view y
Poging Iosf users view of memory
M d I i I if fh f d Meed IogicoI memory unifs fhof grow ond
confrocf
subroufine
ex: sfock,
sfock
moin
shored Iibrory
SoIufion7
symboI fobIe
SoIufion7
Segmenfofionl
CSCI bb73 FoII Z0II Memory 82
Memory View LogicoI view
I
I
I
4
3
Z
Z 3
Z
Z
4
3 3
User spoce
PhysicoI oddress spoce
CSCI bb73 FoII Z0II Memory 83
p
PhysicoI oddress spoce
Segmenfofion Archifecfure (I)
For simpIicify of impIemenfofion, segmenfs ore
numbered ond ore referred fo by o segmenf y g
number.
Thus, o IogicoI oddress consisfs of o fwo fupIe:
segmenf-number, offsef,
Segmenf fobIe - mops fwo-dimensionoI user- g p
defined oddresses info one-dimensionoI physicoI
oddresses, eoch fobIe enfry hos:
C f i fh f fi h i I dd h fh C#&" - confoins fhe sforfing physicoI oddress where fhe
segmenfs reside in memory.
D.B.( - specifies fhe Iengfh of fhe segmenf. p f g f g
CSCI bb73 FoII Z0II Memory 84
Segmenfofion g
d
IogicoI
ddr ss
CPU
s d
oddress
CPU
Iimif bose
moin
Iimif bose
E
F
yes
physicoI
sfock
error
no
yes
oddress
sfock
physicoI
("whof hove we goined7")
Poged segmenfsl
CSCI bb73 FoII Z0II Memory 85
memory
Poged segmenfsl
Segmenfofion Archifecfure (Z)
'"*B"%(G(#CD" C#&" )"*.&(") ('1HI)
h I ' I poinfs fo fhe segmenf fobIe's Iocofion in
memory.
' CD D + . ('1JI) '"*B"%(G(#CD" D"%*(+ )"*.&(") ('1JI)
indicofes number of segmenfs used by o
f b i I I if STLP progrom, segmenf number s is IegoI if s STLP.
For exompIe, o reference fo byfe b3 of
segmenf Z is mopped onfo Iocofion 4300 + g pp
b3 ~ 43b3.
CSCI bb73 FoII Z0II Memory 86
ExompIe of Segmenfofion
CSCI bb73 FoII Z0II Memory 87
Chopfer 8: Memory Monogemenf
8ockground
Swopping
Configuous AIIocofion g
Poging
Segmenfofion Segmenfofion
Segmenfofion wifh Poging
CSCI bb73 FoII Z0II Memory 88
Segmenfofion wifh Poging
8ofh poging ond segmenfofion hove
d f d di d f odvonfoges ond disodvonfoges.
MoforoIo o8000 Iine is designed bosed on o
fIof-oddress spoce, whereos fhe InfeI
80x8o ond Penfium fomiIy ore bosed on
segmenfofion. 8ofh ore merging memory
modeIs foword o mixfure of poging ond
segmenfofion.
CSCI bb73 FoII Z0II Memory 89
Segmenfofion wifh Poging - InfeI 38o
On 38o, fhe IogicoI-oddress spoce of o process is divided info
fwo porfifions. The firsf porfifion is privofe fo fhof process ond
fhe second is shored omong oII process.
Informofion obouf fhe firsf porfifion is kepf in fhe D0-#D
K"&-)./(0) (#CD" (J,1) informofion obouf fhe second porfifion K"&-)./(0) (#CD" (J,1), informofion obouf fhe second porfifion
is kepf in fhe *D0C#D K"&-)./(0) (#CD" (L,1).
The physicoI oddress on fhe 38o is 3Z bifs. The segmenf
i f i f f fh i f f i fh LDT 0DT regisfer poinfs fo fhe oppropriofe enfry in fhe LDT or 0DT.
The bose ond Iimif informofion obouf fhe segmenf ore used fo
generofe o D.%"#) #KK)"&&. If is divided info o poge number of Z0 g p g
bifs, ond o poge offsef consisfing of IZ bifs. The oddress-
fronsIofion scheme is simiIor fo fhe one in Figure 9.I3.
As shown in fhe foIIowing diogrom fhe InfeI 38o uses As shown in fhe foIIowing diogrom, fhe InfeI 38o uses
segmenfofion wifh poging for memory monogemenf wifh o fwo-
IeveI poging scheme.
CSCI bb73 FoII Z0II Memory 90
InfeI 3038o Address TronsIofion
I f
s g p
seIecfor
s - segmenf number (Io bifs)
g - 0DT or LDT7 (I bif)
p - profecfion (Z bifs) p profecfion (Z bifs)
CSCI bb73 FoII Z0II Memory 91

Вам также может понравиться