SystemsOperating Systems
Memory Management
Summary of Virtual Memory, Paging, and Fragmentation
Memory Management (Quick Summary)
The OS is responsible for managing main memory (RAM) so that multiple processes can run concurrently safely and efficiently.
1. Virtual Memory
A technique that gives a process the illusion that it has a large contiguous block of memory, while in reality, that memory may be scattered across RAM or temporarily moved to the Hard Drive (Swap Space).
- Advantages: Processes can use memory exceeding the actual capacity of RAM, prevents processes from interfering with each other's memory (Security Isolation).
2. Paging & Segmentation
Mechanisms for partitioning memory to prevent gaps (Fragmentation).
- Paging: Divides a process's Logical Memory into equal-sized blocks called
Pagesand divides RAM intoFrames, allowing the OS to fit a Page into any available Frame.- Solves: External Fragmentation
- Segmentation: Divides memory according to the actual size of Logical Units (e.g., Text, Data, Stack).
- Problem created: External Fragmentation (gaps between Segments).
3. Page Fault
An event that occurs when the CPU attempts to access Data in Virtual Memory, but that Data has not actually been loaded into RAM yet.
- Mechanism: The OS stops execution (Trap), fetches Data from Disk (Swap) into RAM, and updates the Page Table before allowing the CPU to resume.
- Thrashing: A condition where the system has excessive Page Faults, causing the OS to spend more time swapping Pages in and out of Disk than allowing the CPU to actually process, making the system freeze or become extremely slow.