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?

How to play

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:

  1. A strip at the top shows which book your next class needs.
  2. 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.
  3. A narrator box on the side tells you what just happened, in plain language, after every move.
  4. 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.
Quick grab: already in your bag
Had to go to your locker
Not needed yet

Live status

Classes done0 / 14
Quick grabs0
Locker trips0
Quick-grab rateN/A
Narrator
Reflect

Think back on what just happened

No right answers here. Just sit with these for a moment.

The reveal

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.

Hit Rate = Hits รท Total References
A higher hit rate means fewer costly trips back to disk.

Faults (locker trips) on the same 14 classes, by how you choose which book to remove

Remove any book at random
11
Remove the book that's been in your bag longest
10
Remove the book you haven't used in the longest time
9
๐ŸŽฒ
About 11 faults
Removing a random book ignores which books you actually keep needing.
๐Ÿงญ
9 faults
Remembering which books you used recently keeps the ones you're most likely to need again.
Exercises

Put it to use

Work through these the way you'd reason about a real page replacement policy.

Day complete ๐ŸŽ‰
โ€“ locker trips โ€“ quick-grab rate