operating-system-replacing-pages.html
* created: 2025-05-29T16:05
* modified: 2025-06-30T21:36
title
Replacing a page
description
If there is no more space inside our memory, but we still want to load a page into memory, we need to handle this process gracefully.
related notes
What happens if we replace a page?
A simple description of what happens during the replacement would look like this:
- The MMU wants to access a page that is currently not stored inside a page frame and triggers a page fault.
- We recognize that there is currently no unused page frame inside our physical memory. We start the page replacement procedure.
- We decide which page want to replace to free up a page frame.
- We store the content of this page in our drive (see: swapping), so that we can preserve its current state.
- We load the required page in the page frame that was just freed up. The replacement procedure is now completed.
Keep in mind that the procedure of loading and storing a page frame is fairly expensive, because we have to rely on our comparatively slow drive.
Immutable processes
If the page is stateless — meaning it doesn't modify its data during execution — and an identical copy already exists on our drive, we can skip writing it back. Since the content in memory matches the one on the drive, discarding the page won't result in any data loss.
Mutable processes
Can we skip storing the page if our state has changed?
No, if the M-Bit is currently 1 then we cannot skip the page part where we store the page, because we would lose our state and with that important data.
What if our state could possibly change, but hasn't?
Sure, if the state did not change since we last loaded the page into memory – indicated by the M-Bit in the Page Table – then we can just discard that page, because there would not be any new data we needed to store.