Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Page Replacement Algorithms in Operating Systems: An Overview - Prof. Geoffrey M. Voelker, Study notes of Computer Science

An overview of page replacement algorithms in operating systems. It covers the concepts of locality, demand paging, page replacement, and various page replacement algorithms such as belady's, fifo, lru, and working set model. The document also discusses the challenges of implementing these algorithms and their trade-offs.

Typology: Study notes

2009/2010

Uploaded on 03/28/2010

koofers-user-jza-1
koofers-user-jza-1 🇺🇸

10 documents

1 / 11

Toggle sidebar

Related documents


Partial preview of the text

Download Page Replacement Algorithms in Operating Systems: An Overview - Prof. Geoffrey M. Voelker and more Study notes Computer Science in PDF only on Docsity! 1 CSE 120 Principles of Operating Systems Fall 2004 Lecture 11: Page Replacement Geoffrey M. Voelker November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 2 © 2004 Geoffrey M. Voelker Memory Management Last lecture on memory management: Goals of memory management To provide a convenient abstraction for programming To allocate scarce memory resources among competing processes to maximize performance with minimal overhead Mechanisms Physical and virtual addressing (1) Techniques: Partitioning, paging, segmentation (1) Page table management, TLBs, VM tricks (2) Policies Page replacement algorithms (3) 2 November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 3 © 2004 Geoffrey M. Voelker Lecture Overview Review paging and page replacement Survey page replacement algorithms Discuss local vs. global replacement Discuss thrashing November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 4 © 2004 Geoffrey M. Voelker Locality All paging schemes depend on locality Processes reference pages in localized patterns Temporal locality Locations referenced recently likely to be referenced again Spatial locality Locations near recently referenced locations are likely to be referenced soon Although the cost of paging is high, if it is infrequent enough it is acceptable Processes usually exhibit both kinds of locality during their execution, making paging practical 5 November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 9 © 2004 Geoffrey M. Voelker Belady’s Algorithm Belady’s algorithm is known as the optimal page replacement algorithm because it has the lowest fault rate for any page reference stream Idea: Replace the page that will not be used for the longest time in the future Problem: Have to predict the future Why is Belady’s useful then? Use it as a yardstick Compare implementations of page replacement algorithms with the optimal to gauge room for improvement If optimal is not much better, then algorithm is pretty good If optimal is much better, then algorithm could use some work » Random replacement is often the lower bound November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 10 © 2004 Geoffrey M. Voelker First-In First-Out (FIFO) FIFO is an obvious algorithm and simple to implement Maintain a list of pages in order in which they were paged in On replacement, evict the one brought in longest time ago Why might this be good? Maybe the one brought in the longest ago is not being used Why might this be bad? Then again, maybe it’s not We don’t have any info to say one way or the other FIFO suffers from “Belady’s Anomaly” The fault rate might actually increase when the algorithm is given more memory (very bad) 6 November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 11 © 2004 Geoffrey M. Voelker Least Recently Used (LRU) LRU uses reference information to make a more informed replacement decision Idea: We can’t predict the future, but we can make a guess based upon past experience On replacement, evict the page that has not been used for the longest time in the past (Belady’s: future) When does LRU do well? When does LRU do poorly? Implementation To be perfect, need to time stamp every reference (or maintain a stack) – much too costly So we need to approximate it November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 12 © 2004 Geoffrey M. Voelker Approximating LRU LRU approximations use the PTE reference bit Keep a counter for each page At regular intervals, for every page do: » If ref bit = 0, increment counter » If ref bit = 1, zero the counter » Zero the reference bit The counter will contain the number of intervals since the last reference to the page The page with the largest counter is the least recently used Some architectures don’t have a reference bit Can simulate reference bit using the valid bit to induce faults What happens when we make a page invalid? 7 November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 13 © 2004 Geoffrey M. Voelker LRU Clock (Not Recently Used) Not Recently Used (NRU) – Used by Unix Replace page that is “old enough” Arrange all of physical page frames in a big circle (clock) A clock hand is used to select a good LRU candidate » Sweep through the pages in circular order like a clock » If the ref bit is off, it hasn’t been used recently What is the minimum “age” if ref bit is off? » If the ref bit is on, turn it off and go to next page Arm moves quickly when pages are needed Low overhead when plenty of memory If memory is large, “accuracy” of information degrades » Use additional hands November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 14 © 2004 Geoffrey M. Voelker Fixed vs. Variable Space In a multiprogramming system, we need a way to allocate memory to competing processes Problem: How to determine how much memory to give to each process? Fixed space algorithms » Each process is given a limit of pages it can use » When it reaches the limit, it replaces from its own pages » Local replacement Some processes may do well while others suffer Variable space algorithms » Process’ set of pages grows and shrinks dynamically » Global replacement One process can ruin it for the rest 10 November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 19 © 2004 Geoffrey M. Voelker Thrashing Page replacement algorithms avoid thrashing When most of the time is spent by the OS in paging data back and forth from disk No time spent doing useful work (making progress) In this situation, the system is overcommitted » No idea which pages should be in memory to reduce faults » Could just be that there isn’t enough physical memory for all of the processes in the system » Ex: Running Windows95 with 4 MB of memory… Possible solutions » Swapping – write out all pages of a process » Buy more memory November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 20 © 2004 Geoffrey M. Voelker Summary Page replacement algorithms Belady’s – optimal replacement (minimum # of faults) FIFO – replace page loaded furthest in past LRU – replace page referenced furthest in past » Approximate using PTE reference bit LRU Clock – replace page that is “old enough” Working Set – keep the set of pages in memory that has minimal fault rate (the “working set”) Page Fault Frequency – grow/shrink page set as a function of fault rate Multiprogramming Should a process replace its own page, or that of another? 11 November 8, 2004 CSE 120 – Lecture 11 – Page Replacement 21 © 2004 Geoffrey M. Voelker Next time… Read Chapters 11, 12
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved