Your backpack only fits 3 books
You've got back-to-back classes all day, and every class needs a different textbook. Your backpack only has room for 3 books at a time. Everything else stays behind in your locker, down the hall.
If the book you need is already in your backpack, you grab it in two seconds and you're ready for class. If it's not, you have to walk all the way to your locker to get it, and that eats up time you don't have between periods.
Long day, lots of classes, only 3 slots in your bag. What do you do when a new book needs to go in and your backpack is already full?
You're packing your own backpack
Your goal: have the right book ready for every class, as fast as possible. You only have 3 slots in your backpack.
Here's everything that can happen, one class at a time:
- A strip at the top shows which book your next class needs.
- Look at your 3 backpack slots. One of three things happens:
- Book's already in your bag: click it. That's a quick grab.
- A slot is still empty: the book goes in by itself. Nothing to click.
- All 3 slots are full: click one of the 3 books in your bag to put it back in your locker and make room.
- A narrator box on the side tells you what just happened, in plain language, after every move.
- First you'll watch a short guided day (you just watch). Then you'll pack your own backpack.
Pack your backpack
3 backpack slots. 14 classes in a row, each needing a book. Watch first, then take over.
Need a quick refresher on the rules?
- Book's already in your bag? Click it. That's a quick grab.
- A slot is empty? The book goes in by itself.
- All 3 slots full? Click one of the 3 books to put it back in your locker.
Live status
Think back on what just happened
No right answers here. Just sit with these for a moment.
You were doing page replacement
Computers face the same squeeze as your backpack. Programs keep requesting small chunks of data called pages, but only a few fit in the fast, close-by memory (RAM) at once. Everything else waits in much slower disk storage. Your 3 backpack slots were RAM frames, each book was a page, a quick grab was a hit, and a trip to the locker was a page fault.
When RAM is full and a needed page isn't there, something resident has to leave. The rule for choosing what goes is called a page replacement policy. The walkthrough's rule swaps out whoever's been there longest, no matter how recently it was touched. Smarter rules track recent use instead, betting a page touched moments ago will be needed again soon. Get the rule right and swaps go unnoticed. Get it wrong and the system keeps re-fetching what it just threw out.
Put it to use
Work through these the way you'd reason about a real page replacement policy.