Aar}   p  @  P`HH $ @d HHHH̀̀̀ff@  d Footnote TableFootnote**.\t.\t/ - :;,.!?/8 cN-0d;TOCHeading1Heading2   PEquationVariablesBV ;`<<=7=P=i=;B;D;F;HAyIATAY <$lastpagenum><$monthname> <$daynum>, <$year>"<$monthnum>/<$daynum>/<$shortyear>J<$hour>:<$minute00> <$ampm> on <$dayname>, <$monthname> <$daynum>, <$year>"<$monthnum>/<$daynum>/<$shortyear><$monthname> <$daynum>, <$year>"<$monthnum>/<$daynum>/<$shortyear> <$fullfilename> <$filename> <$paratext[Title]> <$paratext[Heading1]> <$curpagenum> <$marker1> <$marker2> (Continued)+ (Sheet <$tblsheetnum> of <$tblsheetcount>)Heading & Page <$paratext> on page<$pagenum>Pagepage<$pagenum>See Heading & Page%See <$paratext> on page<$pagenum>. Table All7Table<$paranumonly>, <$paratext>, on page<$pagenum>Table Number & Page'Table<$paranumonly> on page<$pagenum>Heading <$paratext>EHTML Headings++A33557iA<<>>@@A;b;d;f;h;j;l;n;p;r;t;v;x;z;|;~;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<<<<<< < <<<<<<<<<<< <"<$<&<(<*<,<.<0<2<4<6<8<:<<<>nB?nB@nBAnBBnBCidq5+dA> d;]d;L HmR;MHmRHRHRFootnote Hr@;NHr@HzHz Single LineH;O Footnote ;P  HD;Q HDHH Double LineH;R Double Line;S ;T H;U  Single Line;V HZ;W  TableFootnoted5p77 EGxR;XEGxREPwEPw TableFootnoted;^dEl d;_d1QRUX[^adgjmpsvy| %).1W/Bm }d ;ad WaHTML Mapping Table }Hd ;cHd Wa }Hd ;eHd Wa }Hd ;gHd Wa }Hd ;iHd Wa }H;kH! FrameMaker PA Source Item }H ;mH Wa HTML Item }H ;oH Wa }H;qH W aInclude Auto# } H;s H W a Comments }H;uH W a }HH;w HH W aElement }H;y#H W a New Topic? }H;{H Wa } H;} H Wa }H ; $H Wa P:Date Line }HH ;#%HH WaP }H ;$&H WaN }H ;%'H WaN } H ;&( H Wa }EH ;')EH Wa P:Reading }HEH ;(*HEH WaP }EH ;)+EH WaN }EH ;*,EH WaN } EH ;+- EH Wa }QH ;,.QH WaP:Title }HQH ;-/HQH WaH* }QH ;.0QH WaN }QH ;/1QH WaN } QH ;02 QH Wa }]H ;13]H WaP:Body }H]H ;24H]H W aP }]H ;35]H W!aN }]H ;46]H W"aN } ]H ;57 ]H W#a }iH(;68iH( W$a P:Numbered1 }HiH(;79HiH((%aLI &a Parent = OL Q'a Depth = 0 }iH(;8:iH( W(aN }iH(;9;iH( W)aY } iH(;:< iH( W*a }H ;;=H  W+a P:Heading1 }HH ;<>HH  W,aH* }H ;=?H  W-aN }H ;>@H  W.aN } H ;?A H  W/a }H(;@BH(  W0a P:Numbered }HH(;ACHH(( 1aP 2a Parent = OL Q3a Depth = 0 }H(;BDH(  W4aN }H(;CEH(  W5aY } H(;DF H(  W6a }H ;EGH  W7a P:CellBody }HH ;FHHH  W8aP }H ;GIH  W9aN }H ;HJH  W:aN } H ;IK H  W;a }H ;JLH  W<aP:CellHeading }HH ;KMHH  W=aP }H ;LNH  W>aN }H ;MOH  W?aN } H ;NP H  W@a }H ;OQH  WAa P:Footnote }HH ;PRHH  WBaP }H ;QSH  WCaN }H ;RTH  WDaN } H ;SU H  WEa }H(;TVH( WFa P:Bulleted }HH(;UWHH((GaLI Ha Parent = UL QIa Depth = 0 }H(;VXH( WJaN }H(;WYH( WKaN } H(;XZ H( WLa }H ;Y[H WMa P:Heading2 }HH ;Z\HH WNaH* }H ;[]H WOaN }H ;\^H WPaN } H ;]_ H WQa }H;^`HR! P:HeadingRuPAnIn }HH;_aHH WSaP }H<`bH WTaN }H<acH WUaN } H<bd H WVa }7H <ce7H WWa P:Indented }H7H < dfH7H WXaP }7H < eg7H WYaN }7H < fh7H WZaN } 7H <gi 7H W[a }CH<hjCH\! P:TableFootPAnote }HCH<ikHCH W]aP }CH<jlCH W^aN }CH<kmCH W_aN } CH<ln CH W`a }]H(<mo]H( Waa P:TableTitle }H]H(<npH]H((baLI ca Parent = OL Qda Depth = 0 }]H( H "W4a }©H <=?©H #W5a }H©H <>@H©H #W6a }©H <?A©H #W7a }©H <@B©H #W8a } ©H <AC ©H #W9a }»d <BF»d $W:aHTML Options Table }D»d <D»d $W;a }D»d <D»d $W<a }D <CGD %W=a }DH <FHDH %W>a }H <GIH %W?a }D <HJD &W@a Image Format }DH <IKDH &WAaIMAGGIF }H <JLH &WBa }D <KMD 'WCaBanners }DH <LNDH 'WDaN }H <MOH 'WEa }D<NPD(F! Banner ReferPA ence Frame }DH<OQDH (WGa }H<PH (WHa }D(<DSD((F)I! Copy Files  Imported by PA Rerefernce }DH(<DRTDH( F)WJa }H(<DSUH( F)WKa }DD <DTVDD F*WLa }DDH <DUWDDH F*WMa }DH <DVXDH F*WNa }Vd <DW[Vd F+WOaSystem Macros }?Vd <D?Vd F+WPa }?Vd <D?Vd F+WQa }f? <DX\f? F,WRa Macro Name }?fH <D[]?fH F,WSa Replace With }fH <D\^fH F,WTa Comments }r? =D]_r? F-WUa StartOfDoc }?rH =D^`?rH F-WVa }rH =D_arH F-WWa }~? =D`b~? F.WXa EndOfDoc }?~H = Dac?~H F.WYa }~H = Dbd~H F.WZa }?= Dce?F/[! StartOfSubPADoc }?H=Ddf?H F/W\a }H=DegH F/W]a }?=Dfh?F0^! EndOfSubPADoc }?H=Dgi?H F0W_a }H=DhjH F0W`a }?=Dik?F1a! StartOfFirstPASubDoc }?H=Djl?H F1Wba }H=DkmH F1Wca }?=Dln?F2d! EndOfFirstPASubDoc }?H=!Dmo?H F2Wea }H=#DnpH F2Wfa }?=%Doq?F3g! StartOfLastPASubDoc }?H='Dpr?H F3Wha }H=)DqsH F3Wia } ?=+Drt ?F4j! EndOfLastPASubDoc }? H=-Dsu? H F4Wka } H=/Dtv H F4Wla }&? =1Duw&? F5Wma }?&H =3Dvx?&H F5Wna }&H =5Dwy&H F5Woa }8d =8Dx|8d F6WpaCross-Reference Macros }?8d =:D?8d F6Wqa }?8d =<D?8d F6Wra }H? =>Dy}H? F7Wsa Macro Name }?HH =@D|~?HH F7Wta Replace With }HH =BD}HH F7Wua Comments }T?=DD~T? F8Wva See Also }?TH=FD?THF8w! See Also: PA <$paratext> }TH=HDTH F8Wxa }n? =JDn? F9Wya }?nH =LD?nH F9Wza }nH =NDnH F9W{a }d =QD d F:WaGeneral Macros }?d =SD?d F:Wa }?d =UD?d F:Wa }?d =WD?d F:Wa }? =YD"? F;Wa Macro Name d= d= d l d= do  WBm }d = d  <W|aHeadings Table }Hd = Hd  <W}a }Hd = Hd  <W~a }H= H =!Paragraph ForPAmat }HH= HH  =WaHeading Level }H= H  =Wa Comments }H= H >W aTitle }HH= HH  >Wa }H= H  >Wa }KH = KH  ?Wa Heading1 }HKH = HKH  ?Wa }KH = KH  ?Wa }WH = WH  @Wa Heading2 }HWH = HWH  @W a }WH = WH  @W a }cH = cH  AW a }HcH = HcH  AW a }cH = cH  AW a HHˆA?HHˆ€33 ^ dThe Stages of Compilation _,e Introduction `eOThis describes the basic stages of compilation in a very non-traditional way cIe fWe*From: Mateo.Burtch@Eng.Sun.COM (Room 101) ke.Subject: YADFH (Yet Another D*** Friday Hack) e !%OHi. This isn't exactly a hack, and thus probably doesn't deserve to be called Ia "Friday Hack," but SOOOOO many people have been coming up to me in the Kshower, saying, Please, tell us the secrets of how the compilation process EKworks, that I finally decided to share with you the old family recipe for: e eTHE STAGES OF COMPILATION  e ! %OSOURCE FILE: This is the basic "code" that the engineer writes. The compiler Ewill take code such as  e  edweeble(flab, krimjaw)  e&sneet flab *(**smicknat[])(blugnut); eblook krimjaw; e{ e!blark snapdaddle liederhosen ; e eif (fleb <= OAK_TREE) e!while (trousers(liederhosen)) e thud; eelse ebrick(flab); e} e !%Pand turn it into output that means, roughly, "point the hose away from yourself Ewhile watering." e e6Obviously, the compiler is a lot smarter than we are. e !%LPREPROCESSOR: The preprocessor takes all sorts of special directives, like L#ifdefs, and converts them into conditional statements (known as "#ifdefs") Pthat the compiler uses to prepare the file (or "#ifdef") for processing. (This EKis a technical simplification that is in most, if not all, aspects wrong.) e !%MThe preprocessor also strips the source file of comments (not to be confused Owith #ifdefs), leaving it a shaken husk of its former self. These comments are Pthen pieced together by a separate function and used for insulation in Building E12.  e !!%LCOMPILER: The heart of the whole process. The compiler takes the language Owords, such as "if," "for," and "help!" and turns it into the bits, bytes, and EPsubroutines that give employment to a whole host of socially challenged people. "e a#%NOPTIMIZATION: This stage makes the generated code as efficient as possible. NThe optimizer does this by carefully trimming the odd and dangly parts off of HHˆAAHHˆL9 ldAB99 }?H =[D #?H F;Wa Replace With }H =]D"$H F;W aHead }H =_D#%H F;W!a Comments }? =aD$&? FCW"a }?H =cD%'?H FCW#a }H =eD&(H FCW$a }H =gD')H FCW%a }d =jD(.d FDW&aCharacter Macros HHˆ;"HHˆ+Ge HHˆ;$3HHˆ**l}?d =lD?d FDW'a }?d =nD?d FDW(a }? =pD)/? FEW)a Macro Name }?H =rD.0?H FEW*a Replace With }H =tD/1H FEW+a Comments }? =vD0B? FFW,a HUV ;.HUV 3Ge HUV ;05+HUV 22l H$ ;1H$ 5Ge H$ ;33H$ 44l HHˆ;4HHˆ€L337 `Memory Management  vGoal:   CPU gains related to scheduling require that many processes be in memory; so, memory must be shared. @kThe selection of which memory management algorithm(s) to use depends especially on the hardware available. 2Bt`"How Programs Interact With Memory 3`compile, assemble, link, load [D>`absolute (physical) addresses `Ebare machine, resident monitor, fence addresses, and fence registers 5s` Relocation 6`0binding program addresses to absolute addresses `transient monitor code 0`0monitor and user stacks grow towards each other 1`dynamic relocation 4`dswapping: swap device (backing store), swapped processes, effect of swap time on switching contexts !n koptimizations: swapping part of the job, speeding up the backing stores performance, overlap with process @ execution o`when you can and cannot swap 8*`!Simple Memory Management Schemes 9`multiple partitions 7wa`bounds registers p`base and limit registers ;+`Fixed Regions (MFT) <`job scheduling :)`memory allocation =`roll in-roll out >A]`Variable Regions (MVT) ?`Dallocation schemes: best fit, worst fit, first fit, next fit, buddy @Y`job scheduling q`$internal vs. external fragmentation r` compaction s` swapping t` reducing external fragmentation BP`Paging C`&page numbers and offsets, page frames DD`job scheduling effects A`page table implementation FƐ`Optimizations E`cache, hit ratio uݮ`effective memory access time v`.sharing, protection, illegal address handling H*x`Views of Memory I`'program  vs . operating system GwB`address translation J`global frame table K' ` Segmentation L`.segments: segment name, offset, segment table M@`.implementation: registers  vs . table P`#sharing, protection, fragmentation NX]`"Combining Segmentation and Paging O`*segmented paging (segment the page table) wpj`'paged segmentation (page the segments) QQ|5`What Is Virtual Memory HHˆ;6HHˆL66 l HHˆAC!HHˆ59#@Inumerals like "5" and "9" until all the numbers are either "1"s or "0"s. $` 1% OASSEMBLER: The assembler takes "machine code" (low-level instructions done by Kpoorly-paid workers in windowless sweatshops called "assembler lines") and @does something with it. &` !' OLINKER: Before we're done, we must link together all the various object files Pwith libraries containing macros and canned routines. Don't ask why--it's like @4salmon swimming upstream to spawn. You just do it. (` !) LThese libraries perform a special job in the grand pageant known as programNming. The pre-written macros and functions they contain allow the programmer Nto save valuable time when writing a program, while the arcane linker options Oand obscure environment variables slow the programmer down just as much. This Nis known as "run-time equilibrium" and is rather similar to horizontal bungee-@ jumping. *` !+ OEXECUTABLE: This is the final product, the finished masterpiece, the piece de Mresistance of the whole process. This file is what the engineer had in mind @when he or she started out. ,` -`It's called "core." .` /`--Mateo 0` A1` HHˆAE!HHˆ H88 ldAkHH d;;<@H$ ;<;>H$ == l H$ ;=;H$ <Wh9February 9, 2000ECS 150 Winter 2000Page 13  HUV ;>;<@HUV ?? l HUV ;?;HUV >Wh@Last modified at  2:48 pm on Wednesday, March 1, 2000  HHˆ;@;>HHˆAA l HHˆ;A;HHˆ@W` }?H =xD1C?H FFW-a }H =zDBH FFW.a d=~EEd=DdFF l d=DdRCERUX[^adgjmpsvy| %).1 HHˆAl:HHˆ &&H2 `Static and Dynamic Relocation 3,` Introduction 4 pThis shows the basic hardware instruction cycle for a machine that uses static relocation and for one that uses I@dynamic relocation. 5b`Static Relocation 6t uStatic relocation refers to address transformations being done before execution of a program begins. A typical hard@(ware instruction cycle looks like this: 7`loop 8`N w  :=  M [ instr_ctr ];(* fetch instruction *) 9`0 oc  :=  Opcode ( w ); :`2 adr  :=  Address ( w ); ;`1 instr_ctr  :=  instr_ctr  + 1; <`% case   oc   of =`L1: reg  :=  reg + M [ adr ];(* add *) >`@2: M [ adr ] :=  reg ;(* store *) ?`:3: instr_ctr  :=  adr ;(* branch *) @` A`  end B`end  (* loop *) C)`Dynamic Relocation D; uDynamic relocation refers to address transformations being done during execution of a program. In what follows, the Gzfunction  NL_map  (for Name Location map) maps the relocatable (virtual) address va given in the program into the @.real (physical) storage address  pa : E`*pa  :=  NL_map ( va ) F`:So, a typical hardware instruction cycle looks like this: G`loop H`` w  :=  M [ NL_map ( instr_ctr )];(* fetch instruction *) I`0 oc  :=  Opcode ( w ); J`2 adr  :=  Address ( w ); K`1 instr_ctr  :=  instr_ctr  + 1; L`% case   oc   of M`_1: reg  :=  reg + M [ NL_map ( adr )];(* add *) N`S2: M [ NL_map ( adr )] :=  reg ;(* store *) O`M3: instr_ctr  :=  NL_map ( adr );(* branch *) P` Q`  end R`end  (* loop *) CS` HHˆAn:HHˆ9PGG lcCAzNMMO d@LL HHˆ@JHHˆ""LRd-executing processes not completely in memory xd overlays yd/demand paging, page faults, pure demand paging zdperformance issues {d,page replacement and victims and dirty bits SBqdpage replacement algorithms |]dfirst in first out }[D;doptimal ~dleast recently used d;stack algorithms, inclusion property, used (reference) bit dclock dsecond chance dleast and most frequently used dnot used recently dssecond-chance cyclic: (1,1)  (0,1); (1,0)  (0,0); (0,1)  (0,0)*; (0,0)  victim ad,Ad Hoc Techniques for Improving Performance bd frame pool ddPage Allocation Algorithms edreserve some free frames Tw_duse all before replacing Ud$minimum number of pages per process Vd&global  vs . local allocation Wdequal, proportional allocation g'dWorking Set Policies h_Rd!thrashing, principle of locality i5dCworking set model: working set, window size, working set principle j@d@approximations: WSCLOCK, Working Set Size, Page Fault Frequency lM]d Other Considerations for Paging mR?Kd prepaging XedI/O interlock Y_dchoosing page size Zdprogram restructuring [ddata structures and paging A\d%arrangement of routines when loading HHˆ@JHHˆ7 KK l A{I =QuickDraw PICT #%v ,,NMSWDO N 48& , Geneva .N(*CPUa{j0"t4Si8 i 4i4"Si#### ### #&(p"b `&(&o&@(E{pa7R0!`"%ae0!aV10"t"`vK!4SWF8&( physical ?+ Bmemory& (?y page table&3@(frameT=X&*(V+48&}(PTBRaj0"t"ba*C}0!SG &( frame4;$z8&w@(qAframe";K&)o&4@(physical address4=8& @(Qp o"K& (virtual ѯ(address =EndInset dAPP HHˆANHHˆ|IIPT `Paging and Address Translation U,` Introduction V qThis shows the function used to map a logical address to a physical address for some paging schemes. Throughout Ithis handout, an address in virtual memory is a pair ( logical_page ,  offset ) where  logical_page  is the page number 0Wwithin the logical address space and  offset  the offset into that page. Also,  page_size  is the size of the page (which is a tmultiple of 2). We will assume the entire program is in memory, so no error handling is given; were this assumption sfalse, the situation where the requested address were not in memory would need to be handled (by generating a page @'fault and loading the necessary page): W`-Paging Address Translation by Direct Mapping X vThis method stores the page table in main memory and the address of this table in the process control block, in a register called the page table base register. Let the page table base register be called  pt_base_register , and let memory @0represent the main store of the computer. Then: Y`hfunction   NL_map (( logical_page ,  offset )):  physical_address ; Z`begin [` NL_map  :=  memory [ pt_base_register  +  logical_page ] *  page_size  +  offset ; \`end  (* NL_map *) ]"h,In pictures, here is what is going on:  ^`2Paging Address Translation by Associative Mapping _ zIn this algorithm,  assoc_page_table  represents an associative memory. This function can check a type of memory ocalled "associative memory" (or "cache" or "lookaside memory") which stores both a frame number and a page num0UUT{ber. The search is done in parallel, and is much faster than a linear (or binary) search. The function returns the frame @%number associated with its argument: ``^function  NL_map(( logical_page ,  offset )):  physical_address ; a`begin b`r NL_map  :=  assoc_page_table ( logical_page ) *  page_size  +  offset ; c`end  (* NL_map *) dg`HPaging Address Translation with Combined Associative and Direct Mapping Wey {This combines the above two methods. The array  page_table  is a small associative store that can hold only a few HHˆANHHˆHSOO ldASS HHˆAQHHˆSeypage numbers; there is also a page table kept in memory. For this method, we shall assume that if there is no entry for logical_page  in the associative memory,  assoc_page_table  returns 1. Taking everything else as in the previous two @ sections: f`hfunction   NL_map (( logical_page ,  offset )):  physical_address ; g`4var  frame_number :  integer ; h`begin i`O frame_number  :=  assoc_page_table ( logical_page ); j`^ if   frame_number  = -1  then (* not in associative memory *) k`\ NL_map  :=  memory [ pt_base_register  +  logical_page ] l`1*  page_size  +  offset ; m`  else n`W NL_map  :=  frame_number  *  page_size  +  offset ; o`end  (* NL_map *) p`NThis is the most common method, and is used in modern computers with paging. Aq` HHˆAQHHˆPXRR lc7AVUUW AT =QuickDraw PICT #%v ,, MSWD    4;8& , Geneva . (q*CPUa6j0"`t&(qM(s,d)4i?8 i i ;"i### # ### #&(js&+dqbase&](qlimit"; #p#K"gCK"CKK"KK&(,7<aq0#)&( trap&@(d&؀(&s"iaq0!C&(wXnoaE 0 & (yesTkzX&V@(,+ +aX0!+a1d0";t"vK!;4W8&(q physical ?+ Bmemory&,(G segment table&(Klimit&@(baseTbX&;@({+48&(STBRa{=0 A"#"ӵ"=K"ZK&({>aC80#t& +S&yesa*b}0"&(Eno& (>Qtrap488&7@(STLRa8j0"t =EndInset dAXX HHˆAVHHˆTTXr `%Segmentation and Address Translation s,` Introduction t lThis shows the function used to map a logical address to a physical address for some segmentation schemes. IThroughout this handout, an address in virtual memory is a pair ( segment ,  offset ) where  segment  is the segment num0Wber within the logical address space and  offset  the offset into that segment. We will assume the entire program is in vmemory, so no error handling is given; were this assumption false, the situation where the requested address were not @fin memory would need to be handled (by generating a segment fault and loading the necessary segment): u` Segmentation v tAs with paging address translation with direct mapping, the segment table is stored in memory, and a pointer to its base in a register called the segment table base register. Let the segment table base register be called  st_base_register , @?and let memory represent the main store of the computer. Then: w`cfunction   NL_map (( segment ,  offset )):  physical_address ; x`begin y`j NL_map  :=  memory [ st_base_register  +  segment ] +  offset ; z`end  (* NL_map *) {"hIn pictures: Q|` HHˆAVHHˆS]WW l^QA^ZZ_ AџY =QuickDraw PICT #%v ,,MSWD a;90"eu, Geneva .((s,d) 4C8    ? "#### ### #(s"?  (s"a?%0!eaS0 W4x8(a physical ?+Bmemory,(P segment tableTX(+4^ 8(STBRa^0 b"^""^K"^K(4>ae=0#u +X&yesa.0"(Ano(?Rtrap4 =8 7@(!STLRa9=0"u"(PTBR4 8     k k" #### ### #(gp@(RV(p,o)apN0 FFTX)+@(-p!(q page table"kq!#+f)(f,o)"  (wdapU0"FO4 8(u6CPU =EndInset dA]] HHˆA[HHˆF++] } `!Segmentation and Paging Combined ~,` Introduction  qThis shows the function used to map a logical address to a physical address for schemes combining paging and segImentation. Throughout this handout,  page_size  is the size of the page (which is a multiple of 2),  seg_tbl_base_reg  0W~contains the address of the base of the segment table, and  memory  is the main store of the computer. We will assume tthe entire program is in memory, so no error handling is given; were this assumption false, the situation where the qrequested address were not in memory would need to be handled (by generating a fault and loading the appropriate @data structure). `Segmented Paging  In this algorithm, the page tables are segmented. The virtual address is represented as a pair ( logical_page ,  offset ), but the  logical_page  consists of a pair ( seg_number ,  seg_offset ) indicating which segment number  seg_number  of the 0 page table the frame number  frame_no  is stored in, and the offset  seg_offset  from the base of that segment table. As {usual, an associative memory is first checked; this will be represented by the funcetion  assoc_page_table , which @Areturns the frame number if that is in the table, and 1 if not: `hfunction   NL_map (( logical_page ,  offset )):  physical_address ; `Jvar  frame_no :  integer ;(* number of frame *) `Q pg_tbl_base :  integer ;(* addr. of page table segment *) `begin `K frame_no  :=  assoc_page_table ( logical_page ); `@ if   frame_no  = -1  then   begin `` pg_tbl_base  :=  memory [ seg_tbl_base_reg  +  seg_number ];  `X frame_no  :=  memory [ pg_tbl_base  +  seg_offset ];  ` end ;  `R NL_map  :=  frame_no  *  page_size  *  offset ;  `end  (* NL_map *)  q`Paged Segmentation  In this algorithm, the segments are paged. The virtual address is represented as a pair ( seg_number ,  offset ), but the  offset consists of a pair ( page_number ,  page_offset ), indicating which page number  page_number  of the segment ‡U\seg_number  the frame number  frame_no  is stored in, and the offset  page_offset  from the base of that page. As usual, "an associative memory is first checked; this will be represented by the funcetion  assoc_page_table , which returns the @oframe number if that is in the table, and 1 if not. Note it takes the segment number as an argument as well: `ffunction   NL_map (( seg_number ,  offset )):  physical_address ; `Jvar  frame_no :  integer ;(* number of frame *) `Q pg_tbl_base :  integer ;(* addr. of page table segment *) `begin `` frame_no  :=  assoc_page_table ( seg_number ,  page_number ); `@ if   frame_no  = -1  then   begin `` pg_tbl_base  :=  memory [ seg_tbl_base_reg  +  seg_number ]; `Y frame_no  :=  memory [ pg_tbl_base  +  page_number ]; ` end ; `W NL_map  :=  frame_no  *  page_size  *  page_offset ; `end  (* NL_map *) C` In pictures: HHˆA[HHˆX`\\ ldA`` HHˆA^HHˆ YYY` W"h HHˆA^HHˆ]c__ ldBFcc HHˆBGaHHˆ~--c  `Page Replacement Algorithms ,` Introduction  sThis handout shows how the various page replacement algorithms work. We shall call the pages of the program a, b, I@5c, to distinguish them from the time (1, 2, 3, ). b`Fixed Number of Frames  t |We shall demonstrate these algorithms by running them on the reference string  w  = cadbebabcd and assume that, initialy, pages a, b, c, and d occupy frames 0, 1, 2, and 3 respectively. When appropriate, the little arrow    indicates the @\location of the pointer which indicates where the search for the next victim will begin. !`First In/First Out (FIFO) "`>This policy replaces pages in the order of arrival in memory. #`time012345678910 $ت`w cadbebabcd %``frame 0  a  a  a  a  aeeee  ed &`?frame 1bbbbb  b  baaa  a '`)frame 2ccccccc  cbbb (`)frame 3dddddddd  dcc )`page fault12345 *`page(s) loadedeabcd +` page(s) removedabcde ,:`Optimal (OPT, MIN) -J`mThis policy selects for replacement the page that will not be referenced for the longest tile in the future. .V`time012345678910 /UE`w cadbebabcd 0`frame 0aaaaaaaaaad 1`frame 1bbbbbbbbbbb 2`frame 2ccccccccccc 3`frame 3dddddeeeeee 4`page fault12 5`page(s) loadeded 6`page(s) removedda 7`Least Recently Used (LRU) 8ߪ`dThis policy selects for replacement the page that has not been used for the longest period of time. 9몐`time012345678910 :ŅU/`w cadbebabcd ;`frame 0aaaaaaaaaaa <`frame 1bbbbbbbbbbb =`frame 2ccccceeeeed >`frame 3dddddddddcc ?`page fault123 @`page(s) loadedecd A`page(s) removedcde B`!stack (top)cadbebabcd C`cadbebabc D`caddeeab AE`$stack (bottom)caaddea HHˆBIaHHˆ`fbb ldBJff HHˆBKdHHˆw00f Fa2Not-Recently-Used or Not Used Recently (NRU, NUR) G!tThis policy selects for replacement a random page from the following classes (in the order given): not used or modi0vfied, not used but modified, used and not modified, used and modified. In the following, assume references 2, 4, and Ae7 are writes. The two numbers written after each page are the use and modified bits, respectively.) Hatime012345678910 Iaw ca*db*eba*bcd Ja: . f@   $.H.l..... .D.h. CodePseudo. f@   $.H.l..... .D.h. CodePseudo. f@ QBody. @@ QHeader Double Line. f@ Q CellFooting. f@ Q CellHeading. f@ Q CellBody. @@ QMapping Table Cell. @@/Mapping Table Cell. @@ /Mapping Table Cell. @@ QMapping Table Cell. f@ QBody. f@ Q BodySpaced. f@ Q Bulleted\t. f@ Q...Date. mf@ Ql. DateProject. @@ QHeader Double Line. f@T QHeading1Body. f@ Q NumberedSpaced.\t. f@ Q.Reading.  f@PQTitleBody. f@$Q.Line Single Line. f@ QCellBody. f@ Q CellHeading. f@ Q Footnote. f@T QHeading2Body. f@T Q HeadingRunInBody. f@ Q Indented. f@ Q TableFootnote. f@T Q TableTitleT:Table : .   f@PQTitleBody. f@NE Q Numbered1 N:.Numbered. L̀Lf@N Q Numbered N:.< =1>. $f@L Q$. Lettereda L:.. $f@L Q$. LetteredL:.. f@NE Q Numbered1 N:.Numbered. $f@L Q$. Lettereda L:.. $f@L Q$. LetteredL:.. L̀Lf@N Q Numbered N:.< =1>. 6$f@R Q6. Romani R:.. 6$f@R Q6. RomanR:.. 6$f@R Q6. Romani R:..  f@T QHeading1Body. f@  Body. f@  HlBody.  f@T QHeading2Body. f@ Q Z .~ . . . . .2 .V .z . . .Body. f@ Q BodyIndent. f@  $.6.Z.u..CodeASM. Hf@ QH.. CodeComment.  Q Q Q / Q ڝQQEmphasisQEquationVariables ڝQ /  BoldItalic QItalic QBold Q/ Q Q Q Q M SymbolM  Symbol     Computer     M ZZThinMediumDoubleThick@ Very Thin HHHHHFormat AH Mapping Table HHHHHFormat BH Mapping Tableh*|#HHHHHf$*DHH+5?HH&69?HH :C?HHH DF?HH*6 ? @ h( A B C D E h  F G H I J h  K L M N O h  P Q R S T h( UVWXYh Z[\]^h_`abc7h defghChijklm]h(nopqrh stuvwh xyz{|h(}~h h    h  h h h)h  !"#$5h%&'()Oh  *+,-.[h!/ 0 1 2 3 uh "4!5!6!7!8!h!#9":";"<"="©h ">#?#@#A#B#» %C$D$E$ $&F%G%H% %'I&J&K& &(L'M'N'')O(P(Q(((*FR)S)T)D )FU*V*W*V ,FX+Y+Z+f +-F[,\,],r ,.F^-_-`-~ -/Fa.b.c..0Fd/e/f//1Fg0h0i002Fj1k1l113Fm2n2o224Fp3q3r3 35Fs4t4u4& 4Fv5w5x58 7Fy6z6{6H 68F|7}7~7T79F888n 8F999 ;F:::: :CF ;";#;$; =  <<<<> ====? >>>K >@ ???W ?A @@@c @ AAA ;F%C&C'C(C EF)D,D-D DFF.E/E0E EF1FBFCFComment ;C ;Gd BlackT!WhiteddARedddGreendd BluedCyandMagentad YellowHeader/Footer $1Header/Footer $1Header/Footer $2Header/Footer $2IndexIndexCommentCommentSubjectSubjectAuthorAuthorGlossaryGlossaryEquationEquation Hypertext Hypertext  Cross-Ref Cross-Ref Conditional TextConditional TextPositionFMPrivatePositionFMPrivateRangeEndFMPrivateRangeEndFMPrivate HTML Macro HTML Macro M.Times.P Times-Roman FrameRoman M.Courier.B Courier-Bold FrameRoman M.Courier.PCourier FrameRoman M.Times.B Times-Bold FrameRoman M.Helvetica.BHelvetica-Bold FrameRomanM.Helvetica.BIHelvetica-BoldOblique FrameRoman M.Times.I Times-Italic FrameRoman M.Symbol.PSymbol FrameRoman FrameRoman FrameRoman M.Courier.ICourier-Oblique FrameRomanbCourier. HelveticaLSymbolPTimes!Regular$Roman MediumBoldRegular ObliqueItalic` ޒSǬ,K7_xи7 0W#7];G]۱!Dm.tVU'O'5&]R4DP; EWn-owK7J$y`s؇ֈc28'дuOOo.鵃Qd !@2^9:51\s|PA^]˚չK (7ʥЯMۥך{6a8du?\;2{T;a[M?r'RΊWRQW4;