CampusLearn
← CSC 214 Operating Systems

Memory Management and Virtual Memory

Notes

Memory Hierarchy and Swapping Computer memory is structured hierarchically, spanning high-speed CPU registers, cache levels, main RAM, and secondary storage. The primary objective of operating system memory management is to dynamically allocate memory blocks to processes, safeguard process address spaces from unauthorized access, and facilitate efficient reclamation once execution terminates. When physical RAM is exhausted, traditional operating systems employ swapping, moving entire inactive processes to secondary disk partitions to release primary memory. Paging and Page Tables Modern operating systems use paging to overcome external fragmentation caused by dynamic contiguous memory allocation. Physical memory is divided into fixed-size segments called frames, while logical process memory is partitioned into equal-sized units called pages, commonly 4 kilobytes in size. The Memory Management Unit (MMU) uses per-process page tables to translate logical addresses into physical addresses dynamically. The hardware accelerates this translation process using a specialized cache known as the Translation Lookaside Buffer (TLB). Virtual Memory and Demand Paging Virtual memory provides processes with the illusion of an expansive, contiguous memory space that can far exceed the physical RAM installed on the motherboard. Under demand paging, pages are loaded into physical frames only when referenced by the program execution. When a thread accesses a virtual address whose corresponding page is not resident in physical RAM, the MMU triggers a page fault interrupt. The operating system handles the interrupt by locating the required page on backing storage, selecting a physical frame (often using the Least Recently Used algorithm), loading the data, and updating the page table entry. If pages are swapped in and out continuously, the system enters thrashing, causing severe performance degradation. Practical example Consider the Kenya Revenue Authority (KRA) iTax web portal running on Ubuntu Linux servers during the annual June 30 tax return deadline. The server possesses 32 gigabytes of physical RAM, but traffic spikes to 15,000 concurrent user sessions. Each user session requires approximately 8 megabytes of logical memory space, creating an aggregate memory requirement of 120 gigabytes. Because the system uses virtual memory and demand paging, only active forms and validation code pages reside in physical RAM (about 1.5 megabytes per active session). Inactive sessions have their dirty pages written to the Linux swap partition on fast NVMe drives. When an inactive user clicks to submit their P9 form, the MMU encounters an invalid page table bit, generating a page fault. The Linux kernel suspends the user's thread, retrieves the 4-kilobyte P9 data page from NVMe swap space, maps it into an available frame, updates the page table, and resumes the thread, allowing the server to handle the extreme traffic surge without crashing.

Quiz

1. In the KRA iTax server scenario, what event is raised when an accessed page is not currently located in physical RAM?

2. What is the term for the condition where an operating system spends more time moving pages between RAM and swap storage than executing user instructions?

3. What hardware component caches recent virtual-to-physical address mappings to accelerate memory lookups?

Sign in to submit and securely grade your quiz.