Q4Operating Systems (Departmental Elective)
Question
(a) Explain Memory Management techniques. (b) Discuss Paging and Segmentation. (c) Explain the concept of Page Replacement Algorithms (FIFO, LRU, Optimal).
Answer
An exhaustive architectural analysis of Memory Management, mathematically contrasting the fixed block sizes of Paging against the logical divisions of Segmentation, and detailing the eviction mechanics of Page Replacement algorithms.
The OS Memory Management Unit (MMU) is the absolute core hardware/software hybrid responsible for mathematically mapping the logical addresses generated by the CPU (Virtual Memory) into the exact physical hardware addresses of the RAM chips. Early Contiguous Allocation suffered from catastrophic external fragmentation. Modern architectures absolutely demand Non-Contiguous Allocation, allowing a single process to be violently shattered and scattered randomly across physical RAM.
1. Paging (Hardware Driven)
Paging is a highly rigid, mathematically perfect non-contiguous architecture designed to completely annihilate External Fragmentation.
- Architecture: The OS violently slices the Logical Memory of a process into identically sized, strict mathematical blocks called Pages (e.g., exactly 4KB). It slices the physical RAM into identically sized blocks called Frames.
- Mapping: Any Page can be physically loaded into any completely random, non-contiguous Frame in RAM. The OS maintains a massive Page Table to mathematically translate the Page Number into the physical Frame Number.
- Merit/Demerit: It guarantees zero external fragmentation. However, it suffers from Internal Fragmentation (if a process needs 1KB, it still gets a 4KB page, wasting 3KB).
2. Segmentation (User Driven)
Segmentation is an architecture that aligns perfectly with how human programmers actually structure code.
- Architecture: Instead of slicing memory into blind, fixed-size mathematical chunks, Segmentation slices the process into logical, variable-sized segments (e.g., The Main Program, The Stack, The Symbol Table, The Math Library).
- Mapping: The OS maintains a Segment Table tracking the Base Address (where it starts in RAM) and the Limit (its exact physical size) to prevent illegal access.
- Demerit: Because segments are variable in size, when they are swapped in and out of RAM, they mathematically leave behind random-sized holes, severely re-introducing External Fragmentation.
In Virtual Memory, when the CPU demands a Page that is on the Hard Drive (Page Fault), but the RAM is 100% full, the OS must execute a catastrophic decision: which Page gets violently evicted from RAM?
- 1. FIFO (First-In, First-Out): The OS mathematically tracks the exact arrival time of every page. It blindly evicts the absolute oldest page. It is incredibly primitive and suffers from Belady's Anomaly, where physically adding more RAM mathematically causes MORE page faults.
- 2. LRU (Least Recently Used): The industry standard. Utilizing the mathematical principle of Temporal Locality, the OS aggressively tracks the exact microsecond every page was last read by the CPU. It violently evicts the page that has not been touched for the longest time, providing near-optimal performance.
- 3. Optimal Algorithm (OPT): The mathematically perfect benchmark. It dictates that the OS must evict the page that will not be used for the longest period of time in the absolute FUTURE. Because predicting the exact future execution path of the CPU is mathematically impossible, OPT cannot be physically implemented.