Agenda

<aside> 📌 Reminders

⬅️ Review

🔄 Swapping

Virtualizing the memory has many advantages; one key one is the ability to give processes the illusion of having a lot more memory available than actually exists in the hardware.

Let us first introduce some key concepts:

<aside> 💡

Swap partition: (also sometimes referred as just “the swap”) a region of the disk that is reserved for temporary storage of data that resides on RAM

</aside>

<aside> 💡

Eviction: (also sometimes referred to as swapping) the process of removing a page from memory and writing it to the swap. Used to make room from another page that is currently needed

</aside>

Now that we have that out of the way, let’s look at an example

Consider a system with 20kB of RAM and 4kB pages (i.e. no more than 5 pages can exist in memory at a time)

Suppose that the running processes (including the kernel) have collectively allocated 5 pages in RAM

A new thread now wishes to run and so it must allocated a page in memory, but there is no more space!

The kernel selects one of the pages currently in memory (how is makes this decision is very important), writes it to the swap, and erases it from memory. The newly started process can now stores its page in this vacated spot.

But now, the process that owned the evicted page is elected to run again, it needs to access the data in that page, so the kernel must again select a victim to evict, and repeats the process

🗳️ Choosing who to evict; The Eviction Policy