A Queue-Based Approach to Page Replacement
So, besides the clock algorithm and its variations, what other page-replacement algorithms are there?
Let's look at the approach used on macOS and BSD (which is similar to what's used in Linux). It's based on the virtual memory design (and kernel design) that came out of CMU called Mach.
Meh. Bet it was in the 1960s.
The Mach operating system was developed at Carnegie Mellon University in the 1980s. It was a research project that was influential in the design of many operating systems that followed. The head of the project, Avie Tevanian, later went on to work at NeXT and then Apple, where he was the chief software architect for the Mac OS X operating system. But the idea of queues for paging predates Mach—it was used in the VAX/VMS operating system in the 1970s.
Meh. I knew it.
Active, Inactive, and Free Queues
Mach's approach was to move pages between three queues:
- Active: Pages that are actively being used.
- Inactive: Pages where we're unsure whether they're being used or not.
- Free: Frames that we think are free and can use for new pages. If a page in the free queue is accessed, it can be reactivated.
How pages can move between these queues is shown in the following diagram:
Whoa! So while a page is on the active list, we actually aren't even checking to see if it's being used!
That's right. After a while of being active, once it hits the front of the active queue, it's moved to the inactive queue. Once it reaches the head of the inactive queue, we look to see if it's been used. If it hasn't, we move it to the free queue. If it has, we move it to the tail of the active queue.
I notice that diagram shows how pages move between the queues, but not when they move. How do we decide when to move a page?
In the original design, the system would try to keep
- About 2/3 of the pages in the active queue,
- About 1/3 of the pages in the inactive queue, and
- 5% of frames in the free queue,
and would perform page movement between the queues to maintain these ratios. In our simulator, we also require that the free queue always has at least two pages. We've also added an option to “bump” pages from the active queue to the inactive queue every k steps (much like the auto-advancing clock), but you can set that option to zero to disable it.
Visualization of Page Replacement
Number of Frames10
Next Page: XX
Status: Message
Total page faults: 0
Disk Write Stalls: 0
You Experiment…
I like it! We're managing to keep the number of disk writes down, and we're not stalling at all because pages spend long enough on the free list that they get written out before they're needed again.
I do like that it performs well, but I have an uneasy feeling. There are all these parameters and settings we can tune. Are they good in general, or just for the
lstrace? Is there one good setting or does it depend on the program?
Or the phase of the moon?
Good question!
(When logged in, completion status appears here.)