33 -OutlineWorking Set AlgorithmFrame AllocationLocal AlgorithmsGlobal AlgorithmsOther ConsiderationsSummary of AlgorithmsWorking Set Clock Algorithm (WSClock)AnnouncementsReading:Working Set AlgorithmWorking Set Clock AlgorithmFrame Allocation1)2)3)MOS 3.3 - 3.7PA 5 due Friday.Please use the Makefile to create the zipsubmission.Create your project groups on Canvas.Page ReplacementRecall:Utilize page table entry fields:Algorithm:Pros:We can fix those issues.Keep a circular list of frame entries instead ofpage table entries containing:On a page fault, do approximately the following:Some Pythonic pseudocode:Cons:On a page fault, do (approximately) the following:Note how w(k, t2) = w(k, t3)Working Set algorithm tries to take advantage ofthe relative stability of a working setInstead of a window size in # of references,kernel defines a window size as time threshold T2 6 1 5 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4 3 4 3 4 4 4 1 3 2 3 4 4 4k = 10---time of last usecleared by kernel on clock interruptcandidates = []oldest = (none, 0)for entry in page_table:  if entry.R = 1:    # page was used since last interrupt    # update time, but do not remove    entry.last_time = current_time()  else: # R = 0    # compute page age    age = current_time() - entry.last_time    if age > T:      # not in working set      # page is removal candidate      candidates.append(entry)    else: # age <= T      if age > oldest[1]:        # find the oldest unused page        # in case all are in working set        oldest = (entry, age)            # page still in working set,      # continue      passif candidates:  # remove a random unused page  # that is not in working set  page_table.remove(choice(candidates))elif oldest[0]:  # otherwise remove the oldest page  # in the working set  page_table.remove(oldest[0])else:  # otherwise pick a random page  page_table.remove(choice(page_table))# frames implemented as linked listglobal frames# clock hand is a pointer to a node in framesglobal handvictim = nonewritebacks = []count = 0while count < len(frames) or writebacks:  count += 1  if hand.R == 1:    # page has been used recently and part of working set    hand.last_time = current_time()    hand.R = 0  else:    # page has not been used recently    age = current_time() - hand.last_time    if age > T:      # page is not in working set      if hand.M == 0:        # clean page, replace immediately        victim = hand        hand = hand.next        break      else:        # dirty page, schedule writeback (nonblocking)        # writeback will clear M bit on completion        writebacks.append(hand.page_number)    else:      # page is still in working set, don't consider it      pass  hand = hand.nextif not victim:  # all pages used and in working set  # pick a page at random  victim = choice(frames)evict(victim)R bit (M bit for writeback)MOS Figure 3-19--------------set last time = current timeif page is clean (M==0), replace the pageif page is dirty (M==1), schedule writebackset R = 0advance clock handadvance clock hand--current page numberif R = 1:if R = 0 and age > T:after first pass, if no page was evicted:if a writeback was scheduled:otherwise evict any clean pagecontinue advancing clock hand and evict thefirst clean, unused page encountered.last time usedR and M bits--successfully reduces page faultsinefficiency: scans entire page tableputting a time field in the page table entrytakes up a lot of space...MOS Figure 3-20OptimalNRUFIFO2nd ChanceClockLRUNFUAgingWorking SetWSClockImpossible, but a useful benchmark2 schemes result:Local algorithms expect process to have a fixednumber of frames to use. Since they only examinecurrent process's pages.Processes can be started up under fixedallocation, but global algorithms can replace pagesused by other processes.Need a way to put minimum and maximum on numberof frames a process uses to prevent thrashingacross processes.Relatedly, may want to limit # of processesswap out processes to relieve memory load (e.g.long idle processes go to disk)requires more complex schedulingdeduplicating pages (same page merging)Other strategiesOut of Memory (OOM) KillerFrames can be divided up among processesperiodically in a fixed manner:LRU/Aging and WSClock or combinations/variantsthereof get used most often in practiceEach process needs a minimum number of frames,but exactly how many should be allocated?Replacement algorithms make different assumptionsCrude approximation of LRUMight evict important pagesBig improvement on FIFOEfficient 2nd ChanceExcellent, but exact impl. difficultCrude approximation of LRUEfficient, decent approx. of LRUGood, but impl. expensiveGood, efficient-------------------Local algorithms -> Fixed AllocationEqual allocationProportional allocatione.g. 100 frames, 5 processesExample:64 framesprocess 1 uses 100 kBprocess 1 => (1/4) * 64 = 16 frames=> 20 frames / processprocess 2 => (3/4) * 64 = 48 framesprocess 2 uses 300 kBprocess gets frames proportional to itsrelative sizea process may have many frames taken from it and end upthrashing (fewer frames than its working set size).it may take frames from another process causing the otherprocess to thrash as well...doesn't influence which pages are replacedbased on the observation that page faultrate decreases as more frames are assigned.measures page fault rate and set upper andlower bounds for acceptabilitytoo many processes, may not have enoughRAM for each one, causing thrashingspecial process that runs when availablememory is lowexamines all processes, assigns a badnessscore to each one, and kills high scoring onesscore can be calculated from how much RAMprocess uses, its priority level, etc.too high => allocate more framestoo low => allocate fewer framesi.e. algorithms that only replace current process pagesi.e. algorithms that consider pages from any processGlobal algorithms -> Dynamic AllocationPage Fault Frequency (PFF) AlgorithmPros:Cons:--if a process thrashes, won't influence otherswasted memory if not all frames usedPros:Cons:--uses memory efficiently for varying working setsdomino-style thrashing can occurpage fault rate# of framesupper boundlower boundthrashing# processesCPU utilizationthrashingOptions?Process Swapping