Willia m St a llings
Com put e r Orga niza t ion a nd Arc hit e c t ure
7t h Edit ion
Cha pt e r 8 Cha pt e r 8
Obje c t ive s a nd Func t ions
• Convenience
—Making t he com put er easier t o use • Efficiency
Ope ra t ing Syst e m Se rvic e s
• Program creat ion
• Program execut ion
• Access t o I / O devices
• Cont rolled access t o files
• Syst em access
• Syst em access
• Error det ect ion and response
T ype s of Ope ra t ing Syst e m
• I nt eract ive
• Bat ch
• Single program ( Uni- program m ing)
Ea rly Syst e m s
• Lat e 1940s t o m id 1950s
• No Operat ing Syst em
• Program s int eract direct ly wit h hardware
• Two m ain problem s:
—Scheduling
—Scheduling
Sim ple Ba t c h Syst e m s
• Resident Monit or program
• Users subm it j obs t o operat or
• Operat or bat ches j obs
• Monit or cont rols sequence of event s t o process bat ch
process bat ch
• When one j ob is finished, cont rol ret urns t o Monit or which reads next j ob
J ob Cont rol La ngua ge
• I nst ruct ions t o Monit or
• Usually denot ed by $
• e.g.
—$JOB
—$FTN
—$FTN
—... Som e Fort ran inst ruct ions
—$LOAD
—$RUN
—... Som e dat a
De sira ble H a rdw a re Fe a t ure s
• Mem ory prot ect ion
—To prot ect t he Monit or • Tim er
—To prevent a j ob m onopolizing t he syst em • Privileged inst ruct ions
• Privileged inst ruct ions
—Only execut ed by Monit or
—e.g. I / O • I nt errupt s
M ult i-progra m m e d Ba t c h Syst e m s
• I / O devices very slow
T im e Sha ring Syst e m s
• Allow users t o int eract direct ly wit h t he com put er
—i.e. I nt eract ive
Sc he duling
• Key t o m ult i- program m ing
• Long t erm
• Medium t erm
• Short t erm
• I / O
Long T e rm Sc he duling
• Det erm ines which program s are subm it t ed for processing
• i.e. cont rols t he degree of m ult i-program m ing
• Once subm it t ed, a j ob becom es a process for t he short t erm scheduler
for t he short t erm scheduler
M e dium T e rm Sc he duling
• Part of t he swapping funct ion ( lat er…)
• Usually based on t he need t o m anage m ult i- program m ing
Short T e rm Sc he dule r
• Dispat cher
• Fine grained decisions of which j ob t o execut e next
Proc e ss Cont rol Bloc k
• I dent ifier
• St at e
• Priorit y
• Program count er
• Mem ory point ers
• Mem ory point ers
• Cont ext dat a
• I / O st at us
M e m ory M a na ge m e nt
• Uni- program
—Mem ory split int o t wo
—One for Operat ing Syst em ( m onit or)
—One for current ly execut ing program • Mult i- program
Sw a pping
• Problem : I / O is so slow com pared wit h CPU t hat even in m ult i- program m ing
syst em , CPU can be idle m ost of t he t im e
• Solut ions:
—I ncrease m ain m em ory
– Expensive
– Expensive
– Leads t o larger program s
Wha t is Sw a pping?
• Long t erm queue of processes st ored on disk
• Processes “ swapped” in as space becom es available
• As a process com plet es it is m oved out of m ain m em ory
m ain m em ory
• I f none of t he processes in m em ory are ready ( i.e. all I / O blocked)
—Swap out a blocked process t o int erm ediat e queue
—Swap in a ready process or a new process
Pa rt it ioning
• Split t ing m em ory int o sect ions t o allocat e t o processes ( including Operat ing Syst em )
• Fixed- sized part it ions
—May not be equal size
—Process is fit t ed int o sm allest hole t hat will t ake it ( best fit )
t ake it ( best fit )
—Som e wast ed m em ory
Fix e d
V a ria ble Size d Pa rt it ions (1 )
• Allocat e exact ly t he required m em ory t o a process
• This leads t o a hole at t he end of m em ory, t oo sm all t o use
—Only one sm all hole - less wast e
• When all processes are blocked, swap out
• When all processes are blocked, swap out a process and bring in anot her
• New process m ay be sm aller t han swapped out process
V a ria ble Size d Pa rt it ions (2 )
• Event ually have lot s of holes ( fragm ent at ion)
• Solut ions:
—Coalesce - Join adj acent holes int o one large hole
—Com pact ion - From t im e t o t im e go t hrough
Re loc a t ion
• No guarant ee t hat process will load int o t he sam e place in m em ory
• I nst ruct ions cont ain addresses
—Locat ions of dat a
—Addresses for inst ruct ions ( branching)
• Logical address - relat ive t o beginning of program
• Physical address - act ual locat ion in m em ory ( t his t im e)
Pa ging
• Split m em ory int o equal sized, sm all chunks - page fram es
• Split program s ( processes) int o equal sized sm all chunks - pages
• Allocat e t he required num ber page fram es t o a process
t o a process
• Operat ing Syst em m aint ains list of free fram es
• A process does not require cont iguous page fram es
V irt ua l M e m ory
• Dem and paging
—Do not require all pages of a process in m em ory
—Bring in pages as required • Page fault
—Required page is not in m em ory
—Required page is not in m em ory
—Operat ing Syst em m ust swap in required page
—May need t o swap out a page t o m ake space
T hra shing
• Too m any processes in t oo lit t le m em ory
• Operat ing Syst em spends all it s t im e swapping
• Lit t le or no real work is done
• Disk light is on all t he t im e
• Disk light is on all t he t im e
• Solut ions
—Good page replacem ent algorit hm s
—Reduce num ber of processes running
Bonus
• We do not need all of a process in m em ory for it t o run
• We can swap in pages as required
• So - we can now run processes t hat are bigger t han t ot al m em ory available!
• Main m em ory is called real m em ory
T ra nsla t ion Look a side Buffe r
• Every virt ual m em ory reference causes t wo physical m em ory access
—Fet ch page t able ent ry
—Fet ch dat a
• Use special cache for page t able
—TLB
Se gm e nt a t ion
• Paging is not ( usually) visible t o t he program m er
• Segm ent at ion is visible t o t he program m er
• Usually different segm ent s allocat ed t o program and dat a
program and dat a
Adva nt a ge s of Se gm e nt a t ion
• Sim plifies handling of growing dat a st ruct ures
• Allows program s t o be alt ered and
recom piled independent ly, wit hout re-linking and re- loading
• Lends it self t o sharing am ong processes
• Lends it self t o sharing am ong processes
• Lends it self t o prot ect ion
Pe nt ium I I
• Hardware for segm ent at ion and paging
• Unsegm ent ed unpaged
— virt ual address = physical address
— Low com plexit y
— High perform ance
• Unsegm ent ed paged
— Mem ory viewed as paged linear address space
— Prot ect ion and m anagem ent via paging
— Prot ect ion and m anagem ent via paging
— Berkeley UNI X
• Segm ent ed unpaged
— Collect ion of local address spaces
— Prot ect ion t o single byt e level
— Translat ion t able needed is on chip when segm ent is in m em ory
• Segm ent ed paged
— Segm ent at ion used t o define logical m em ory part it ions subj ect t o access cont rol
— Paging m anages allocat ion of m em ory wit hin part it ions
Pe nt ium I I Se gm e nt a t ion
• Each virt ual address is 16- bit segm ent and 32- bit offset
• 2 bit s of segm ent are prot ect ion m echanism
• 14 bit s specify segm ent
• Unsegm ent ed virt ual m em ory 232 = 4Gbyt es
• Segm ent ed 246= 64 t erabyt es
—Can be larger – depends on which process is act ive
—Half ( 8K segm ent s of 4Gbyt es) is global
Pe nt ium I I Prot e c t ion
• Prot ect ion bit s give 4 levels of privilege
—0 m ost prot ect ed, 3 least
—Use of levels soft ware dependent
—Usually level 3 for applicat ions, level 1 for O/ S and level 0 for kernel ( level 2 not used)
—Level 2 m ay be used for apps t hat have
—Level 2 m ay be used for apps t hat have int ernal securit y e.g. dat abase
Pe nt ium I I Pa ging
• Segm ent at ion m ay be disabled
—I n which case linear address space is used • Two level page t able lookup
—First , page direct ory
– 1024 ent ries m ax
– Split s 4G linear m em ory int o 1024 page groups of
– Split s 4G linear m em ory int o 1024 page groups of 4Mbyt e
– Each page t able has 1024 ent ries corresponding t o 4Kbyt e pages
– Can use one page direct ory for all processes, one per process or m ixt ure
– Page direct ory for current process always in m em ory
—Use TLB holding 32 page t able ent ries
Pow e rPC M e m ory M a na ge m e nt H a rdw a re
• 32 bit – paging wit h sim ple segm ent at ion
—64 bit paging wit h m ore powerful segm ent at ion
• Or, bot h do block address t ranslat ion
—Map 4 large blocks of inst ruct ions & 4 of m em ory t o bypass paging
—e.g. OS t ables or graphics fram e buffers • 32 bit effect ive address
—12 bit byt e select or
– = 4kbyt e pages
—16 bit page id
– 64k pages per segm ent
—4 bit s indicat e one of 16 segm ent regist ers
Re quire d Re a ding
• St allings chapt er 8
• St allings, W. [ 2004] Operat ing Syst em s, Pearson