THE WSCLOCK POLICY << Model >> o Use-bit and virtual timestamps updated after hard clock interrupt - Update virtual time (VT) of current process - Set timestamp (TS) of every page with U-bit = 1 - Clear every U-bit o Let P Set of pages in a process' virtual address space P = R U R' where R is the resident set (pages in memory) R' is the non-resident set (pages on disk) S Reference string S = ( r1, r2, ... ) where ri = (p, d) p is a page number d is r(ead) or w(rite) W Working set (of pages) W = { p }, the set of pages such that TS(p) <= VT - T where T is a threshhold << Replacement Algorithm >> o Combines ideas of WS and Clock o Clock ptr identifies next frame to examine during page replacement scan o ABSTRACT Frame Table Fn Pn TS U-bit M-bit V-bit PID -------------------------------------------- | | | | | | | | -------------------------------------------- Fn Frame number Pn Page number TS Time Stamp (Virtual time of last reference) U-bit 1 if page was used (read or written); cleared after each clock interrupt M-bit 1 if page is dirty V-bit 1 if frame entry is valid; 0 ==> page is on disk PID Process ID o A page p is replaceable if it is "clean" and either: 1) page p is not in the working set W, or 2) page p is owned by an inactive process (i.e., should be swapped out) o A dirty page must be written to disk before it can be replaced. << Example >> o Given Current VT = 45 Process A: VT(A) = 45 (Active, Running) Process B: VT(B) = 19 (Active) Working set threshhold: T = 4 Fn Pn TS U-bit M-bit V-bit PID ---------------------------------------------------- 0 1 19 0 0 1 B 1 0 43 0 1 1 A 2 3 44 1 1 1 A 3 2 19 0 0 1 B 4 1 40 0 1 1 A 5 0 12 0 1 1 B 6 2 45 1 0 1 A ==> 7 4 43 0 0 1 A o Clock interrupt occurs - Use U-bit to update TS field and then clear U-bit - Update VT(process): VT(A) + 1 --> VT(A) = 46 Fn Pn TS U-bit M-bit V-bit PID ---------------------------------------------------- 0 1 19 0 0 1 B 1 0 43 0 1 1 A 2 3 44->46 1->0 1 1 A 3 2 19 0 0 1 B 4 1 40 0 1 1 A 5 0 12 0 1 1 B 6 2 45->46 1->0 0 1 A ==> 7 4 43 0 0 1 A o Process A references page 5 - Page Fault ! - Need to find a frame to load page 5 ==> Run page replacement algorithm - Scan algorithm trace + Start at frame 7 + Find CLEAN page p that is not in W; i.e., Clean and age(p) >= threshhold T = 4 Clean and VT(process) - TS(p) >= 4 if process A: 46 - TS(p) >= 4 ==> TS(p) <= 42 if process B: 19 - TS(p) >= 4 ==> TS(p) <= 15 + Scan for replacement page: Fn PID 7 A Clean but NOT ( 43 <= 42 ) not replaceable 0 B Clean but NOT ( 19 <= 15 ) not replaceable 1 A Dirty but NOT ( 43 <= 42) not replaceable 2 A Dirty but NOT ( 46 <= 42) not replaceable 3 B Clean but NOT ( 19 <= 15 ) not replaceable 4 A Dirty and ( 40 <= 42 ) schedule for cleaning 5 B Dirty and ( 12 <= 15 ) schedule for cleaning 6 A Clean but NOT ( 46 <= 42 ) not replaceable 7 A ... back to beginning without finding clean, replaceable page ==> Memory is OVERCOMMITTED ==> Need to deactivate a task (e.g., B) Fn Pn TS U-bit M-bit V-bit PID ---------------------------------------------------- 0 1 19 0 0 1 B Deactivated 1 0 43 0 1 1 A 2 3 46 0 1 1 A 3 2 19 0 0 1 B Deactivated 4 1 40 0 1 1 A Cleaning 5 0 12 0 1 1 B Cleaning 6 2 46 0 0 1 A ==> 7 4 43 0 0 1 A + Deactivate: Fn Pn TS U-bit M-bit V-bit PID ---------------------------------------------------- ==> 0 1 19 0 0 1 B Deactivate 1 0 43 0 1 1 A 2 3 46 0 1 1 A 3 2 19 0 0 1 B Deactivate 4 1 40 0 1 1 A Cleaning 5 0 12 0 1 1 B Cleaning 6 2 46 0 0 1 A 7 4 43 0 0 1 A ==> Load page 5 into frame 0 '*' means page is on reclamation list Fn Pn TS U-bit M-bit V-bit PID ---------------------------------------------------- 0 1->5 19->46 0->1 0 1 B->A Loaded ==> 1 0 43 0 1 1 A 2 3 46 0 1 1 A 3 2 19 0 0 1* B Free 4 1 40 0 1 1 A Cleaning 5 0 12 0 1 1 B Cleaning 6 2 46 0 0 1 A 7 4 43 0 0 1 A o Process A terminates without changing the frame table - All of Process A's pages are eligible for replacement - Process B can be activated ==> Reclaim any of B's pages still in memory Fn Pn TS U-bit M-bit V-bit PID ---------------------------------------------------- 0 5 46 1 0 1* A ==> 1 0 43 0 1 1* A 2 3 46 0 1 1* A 3 2 19 0 0 1 B Reclaim 4 1 40 0 1 1 A Cleaning 5 0 12 0 1 1 B Cleaning 6 2 46 0 0 1* A 7 4 43 0 0 1* A << Variations >> o Proactive Cleaning Algorithm and list of available frames A o Special treatment of a LOADING process << Comparison with WS without Clock algorithm >> o Schedule and execute the WS-scan procedure that determines W [[ WSClock scans as needed to determine RW, the resident WS. RW may be a subset of W. ]] o Need to store TS(p) for EVERY page of EVERY process [[ WSClock only nees TS(p) for resident pages of all processes. ]] o Need algorithm to maintain A, the set of available pages. [[ WSClock doesn't need a separate A and can get an available page as needed. ]] << Comparison with Clock algorithm >> o Clock is a global algorithm o Need an adaptive feedback (heuristic) algorithm to adjust each process' memory needs - e.g., PFF (Page Fault Frequency) algorithm