Memory page deallocation in case of faults refers to how an operating system handles the removal and cleanup of memory pages when something goes wrong—typically during a page fault or when a page is deemed invalid, corrupted, or no longer needed.
Let’s break it down clearly.
1. What is a page fault?
A page fault occurs when a program tries to access a memory page that is:
-
Not currently in physical RAM (valid but swapped out), or
-
Not mapped at all (invalid access)
The CPU traps into the OS to handle it.
2. What does “page deallocation” mean here?
Page deallocation means the OS:
-
Frees the physical memory frame
-
Removes the page table entry mapping
-
Marks the page as invalid/unusable
-
Returns the frame to the free memory pool
It is essentially:
“This page is no longer needed or is invalid, so reclaim its memory.”
3. When does deallocation happen during faults?
(A) Invalid page fault (segmentation-style fault)
If the fault is caused by accessing an illegal address:
-
OS detects the page is not part of process address space
-
Process is usually terminated (or signal sent)
-
Any partially allocated page structures may be cleaned up
-
Memory is reclaimed immediately
👉 Example: accessing freed pointer
(B) Fault during memory protection violation
If access violates permissions (e.g., write to read-only page):
-
OS does NOT normally deallocate the page
-
Instead, it may terminate or adjust permissions (rare cases like copy-on-write)
So deallocation is not always involved.
(C) Page replacement under memory pressure (related, not fault-triggered)
When RAM is full:
-
OS may evict a page (write to disk if dirty)
-
Then deallocate the frame (free it for reuse)
This is more “page replacement” than fault handling, but closely related.
4. What exactly is freed?
When a page is deallocated, OS updates:
-
Page table entry → invalid
-
Frame table → marked free
-
Cache/TLB entries → invalidated
-
Swap metadata (if used) → cleared or updated
5. Simple mental model
Think of RAM like hotel rooms:
-
Each page = a room occupant
-
Page fault = someone tries to enter a room
-
If invalid guest → they are removed and room is freed (deallocation)
-
If valid guest but room not in hotel → OS brings them in
-
If hotel is full → some guests are evicted and rooms freed
6. Key takeaway
Memory page deallocation during faults is the OS process of reclaiming physical memory frames when a page access is invalid or when recovery/cleanup is required after a fault.