You are on page 1of 5

Virtual Memory

Virtual memory is the use oI space on a hard disk drive (HDD) to simulate additional main
memory. Memory is used to hold portions oI the operating system, programs and data that are
currently in use or that are Irequently used. Physically, main memory consists oI random access
memory (RAM) chips that are combined into modules which, in turn, are inserted into slots on
the motherboard on a computer. vlrLual Memory ls a feaLure of an operaLlng sysLem LhaL enables a
process Lo use a memory address space LhaL ls lndependenL of oLher processes runnlng ln Lhe same
sysLem and use a space LhaL ls larger Lhan Lhe acLual amounL of 8AM presenL Lemporarlly relegaLlng
some conLenLs from 8AM Lo a dlsk wlLh llLLle or no overhead
1he slze of Lhe vlrLual memory on a sysLem ls smaller Lhan Lhe sum of Lhe physlcal 8AM and Lhe swap
area slnce pages LhaL are swapped ln are noL erased from Lhe swap area and so Lake up Lwo pages of
Lhe sum of slzes
Support Needed for V|rtua| Memory
ardware musL supporL paglng and segmenLaLlon CperaLlng sysLem musL be able Lo managemenL Lhe
movemenL of pages and/or segmenLs beLween secondary memory and maln memory


vlrLual memory LhaL ls larger Lhan physlcal memory vlrLualaddress space




emand paging
n compuLer operaLlng sysLems demand pag|ng ls an appllcaLlon of vlrLual memory n a sysLem LhaL
uses demand paglng Lhe operaLlng sysLem coples a dlsk page lnLo physlcal memory only lf an aLLempL ls
made Lo access lL ( lf a page faulL occurs) L follows LhaL a process beglns execuLlon wlLh none of lLs
pages ln physlcal memory and many page faulLs wlll occur unLll mosL of a processs worklng seL of pages
ls locaLed ln physlcal memory
dvantages
Demand paging, as opposed to loading all pages immediately:
O nly loads pages that are demanded by the executing process.
O As there is more space in main memory, more processes can be loaded reducing context
switching time which utilizes large amounts oI resources.
O ess loading latency occurs at program startup, as less inIormation is accessed Irom
secondary storage and less inIormation is brought into main memory.
O Does not need extra hardware support than what paging needs, since protection Iault can
be used to get page Iault.
9age rep|acement a|gor|thm
Jhen a page faulL occurs Lhe operaLlng sysLem has Lo selecL a page Lo remove from memory Lo make
room for Lhe page LhaL has Lo broughL ln 1he algorlLhm LhaL ls used Lo selecL a page Lo be swapped ouL
ls called page replacemenL algorlLhm" An algorlLhm ls consldered beLLer for page replacemenL LhaL has
lowesL page faulL raLe

1he lmporLanL and commonly used page replacemenL algorlLhms are
O |rst|n f|rstout (% 1reaLs page frames allocaLed Lo a process as a clrcular buffer ages are
removed ln roundrobln sLyle SlmplesL replacemenL pollcy Lo lmplemenL age LhaL has been ln
memory Lhe longesL ls replaced 1hese pages may be needed agaln very soon
O east kecent|y Used (kU% 8eplaces Lhe page LhaL has noL been referenced for Lhe longesL
Llme 8y Lhe prlnclple of locallLy Lhls should be Lhe page leasL llkely Lo be referenced ln Lhe near
fuLure Lach page could be Lagged wlLh Lhe Llme of lasL reference 1hls would requlre a greaL
deal of overhead
O pt|ma| po||cy SelecLs for replacemenL LhaL page for whlch Lhe Llme Lo Lhe nexL reference ls
Lhe longesL mposslble Lo have perfecL knowledge of fuLure evenLs
O |ock 9o||cy AddlLlonal blL called a use blL Jhen a page ls flrsL loaded ln memory Lhe use blL ls
seL Lo 1Jhen Lhe page ls referenced Lhe use blL ls seL Lo 1Jhen lL ls Llme Lo replace a page
Lhe flrsL frame encounLered wlLh Lhe use blL seL Lo 0 ls replaced uurlng Lhe search for
replacemenL each use blL seL Lo 1 ls changed Lo 0




Secondhance |gor|thm
8aslcally lL's a llC algorlLhm Jhen a page has been selecLed we lnspecL lLs reference blLf Lhe value
ls 0 we proceed Lo replace Lhls page oLherwlse we glve Lhe page a second chance and move on Lo
selecL Lhe nexL llC page Jhen a page geL a second chance lL's reference blL ls cleared and lLs arrlval
Llme ls reseL Lo Lhe currenL Llme Jhen a page geL a second chance lL's reference blL ls cleared and lLs
arrlval Llme ls reseL Lo Lhe currenL Llmef a page ls used ofLen enough Lo keep lLs reference blL seL lL wlll
never be replaced
||ocat|on of rames
Jhen we have more Lhan one processor we need Lo allocaLe frames Lo each processorLach process
needs number of pages
Lxample 8M 370 6 pages Lo handle SS MCvL lnsLrucLlon
O nsLrucLlon ls 6 byLes mlghL span 2 pages
O 2 pages Lo handle
O 2 pages Lo handle
1wo ma[or allocaLlon schemes
1 llxed allocaLlon
2 rlorlLy allocaLlon
|xed ||ocat|on
Lqua| a||ocat|on lor example lf Lhere are 100 frames and 3 processes glve each process 20 frames
9roport|ona| a||ocat|on AllocaLe accordlng Lo Lhe slze of process








9r|or|ty ||ocat|on
2
$
8
5 ,
2
8 $
5 8

Ior allocation
Irames oI number total
process oI size
59 64
137
127
5 64
137
10
127
10
64
2
1
2
L
L

,
,
8
8
2

Dse a proporLlonal allocaLlon scheme uslng prlorlLles raLher Lhan slze


f process 9

generaLes a page faulL SelecL for replacemenL one of lLs frames SelecL for replacemenL a
frame from a process wlLh lower prlorlLy number
|oba| vs oca| ||ocat|on
|oba| rep|acement process selecLs a replacemenL frame from Lhe seL of all frames one process can
Lake a frame from anoLher
oca| rep|acement each process selecLs from only lLs own seL of allocaLed frames
1hrash|ng
1hrashlng ls a process ls busy swapplng pages ln and ouL f a process does noL have enough" pages Lhe
pagefaulL raLe ls very hlgh 1hls leads Lo low CD uLlllzaLlon operaLlng sysLem Lhlnks LhaL lL needs Lo
lncrease Lhe degree of mulLlprogrammlng anoLher process added Lo Lhe sysLem


1he flgure shows Lhe CD uLlllzaLlon agalnsL Lhe degree of mulLlprogrammlng 1he degree of
mulLlprogrammlng ls dlrecLly relaLed Lo Lhrashlng Jhen Lhe Lhrashlng condlLlon occurs Lhe CD
uLlllzaLlon drops very qulckly 1hls problem can be handled by decreaslng Lhe degree of
mulLlprogrammlng

You might also like