Chapter 8 Operating System Support

  Willia m St a llings Com put e r Orga niza t ion a nd Arc hit e c t ure t h

  

Ope ra t ing Syst e m Support

  Obje c t ive s a nd Func t ions

  • Convenience

  — Making t he com put er easier t o use

  • Efficiency

  — Allowing bet t er use of com put er resources

  La ye rs a nd V ie w s of a Com put e r Syst e m

  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

  • Account ing

  O/S a s a Re sourc e M a na ge r

  T ype s of Ope ra t ing Syst e m

  • I nt eract ive
  • Bat ch
  • • Single program ( Uni- program m ing)

  • Mult i- program m ing ( Mult i- t asking)

  — Scheduling — Scheduling — Set up t im e

  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:

  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 Monit or handles scheduling •

  M e m ory La yout for Re side nt M onit or

  — $JOB — $FTN — $FTN — ... Som e Fort ran inst ruct ions — $LOAD — $RUN — ... Som e dat a — $END

  J ob Cont rol La ngua ge

  • I nst ruct ions t o Monit or
  • Usually denot ed by $ • e.g.

  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

  — Allows for relinquishing and regaining cont rol

  M ult i-progra m m e d Ba t c h Syst e m s

  I / O devices very slow • When one program is wait ing for I / O, • anot her can use t he CPU

  Single Progra m

  

M ult i-Progra m m ing w it h

T w o Progra m s

  

M ult i-Progra m m ing w it h

T hre e Progra m s

  U t iliza t ion

  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

  Mult i- program m ing allows a num ber of • users t o int eract wit h t he com put er

  Sc he duling

  • • Key t o m ult i- program m ing

  • Long t erm
  • Medium t erm
  • Short t erm
  • I / O • 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 ( or it becom es a swapped out j ob for t he • m edium 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 I f no virt ual m em ory, m em ory • m anagem ent is also an issue

  Short T e rm Sc he dule r

  Dispat cher • Fine grained decisions of which j ob t o • execut e next i.e. which j ob act ually get s t o use t he • processor in t he next t im e slot

  Five St a t e Proc e ss M ode l

  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
  • • Account ing inform at ion

  PCB Dia gra m

  Sc he duling Ex a m ple

  K e y Ele m e nt s of O/S

  Proc e ss Sc he duling

  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

  — “ User” part is sub- divided and shared am ong act ive processes

  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 –

  — Swapping

  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

  U se of Sw a pping

  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 — Leads t o variable sized part it ions

  Fix e d

Pa rt it ioning

  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 Anot her hole •

  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 — Com pact ion - From t im e t o t im e go t hrough m em ory and m ove all hole int o one free block ( c.f. disk de- fragm ent at ion)

  Effe c t of Dyna m ic Pa rt it ioning

  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) Aut om at ic conversion using base address •

  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 Use page t able t o keep t rack •

  Alloc a t ion of Fre e Fra m e s

  Logic a l a nd Physic a l Addre sse s - Pa ging

  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 — Select page t o t hrow out based on recent hist ory

  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 — Fit m ore m em ory

  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 • User/ program m er sees m uch bigger • m em ory - virt ual m em ory

  I nve rt e d Pa ge T a ble St ruc t ure

  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 — TLB

  T LB Ope ra t ion

  T LB a nd Ca c he Ope ra t ion

  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 May be a num ber of program and dat a • segm ent s

  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 • Som e syst em s com bine segm ent at ion • wit h paging

  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

  

Pe nt ium I I Addre ss T ra nsla t ion

M e c ha nism

  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

  32 Unsegm ent ed virt ual m em ory 2 •

  =

  4Gbyt es

  — Can be larger – depends on which process is act ive

  — Half ( 8K segm ent s of 4Gbyt es) is global

  — 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)

  Pe nt ium I I Prot e c t ion

  • Prot ect ion bit s give 4 levels of privilege

  — 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

  — Som e inst ruct ions only work in level 0

  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

  

Pow e rPC 3 2 -bit M e m ory M a na ge m e nt

Form a t s

  Pow e rPC 3 2 -bit Addre ss T ra nsla t ion

  Re quire d Re a ding

  St allings chapt er 8 • St allings, W. [ 2004] Operat ing Syst em s, • Pearson Loads of Web sit es on Operat ing Syst em s •