In simple terms
A friendly intro before the formal notes — no formulas yet.
The Library of Memory
Your computer's operating system acts like a clever librarian, managing a small desk (RAM) for active tasks. It uses a vast library (hard disk) to store everything else, swapping items back and forth so you can work on big projects without running out of desk space.
Imagine you're a researcher at a library with a very small desk (your computer's RAM). You can only have a few books on your desk at once. The main library has millions of books (your hard drive). The librarian (the OS) watches which books you're using. When you need a book from the main library, the librarian fetches it for you. If your desk is full, the librarian cleverly takes a book you haven't touched in a while and puts it back in the main library to make space. This swapping is what virtual memory does, making your small desk feel infinitely large, though fetching books from the main library takes a little longer.
- 1
A program is divided into fixed-size blocks called 'pages'.
- 2
The physical memory (RAM) is also divided into fixed-size blocks called 'frames'.
- 3
The Operating System's Memory Management Unit (MMU) maps the program's pages to available frames in RAM.
- 4
If RAM is full, the OS moves inactive pages to the hard disk (virtual memory) and brings them back only when needed, a process called swapping.
Explore the concept
Use the live diagram and synced steps — play it or tap a step card to walk through.
Full topic notes
Formal explanation with the rigour you need for the exam.
The OS as a Memory Manager
The operating system is the ultimate resource manager, and memory is one of its most precious resources. Its primary memory management duties include: keeping track of which parts of memory are currently being used and by which process, deciding which processes (or parts of processes) to load into memory when space becomes available, allocating and deallocating memory space as needed by processes, and ensuring that one process cannot interfere with the memory space of another. Without this careful management, a single faulty program could crash the entire system.
Allocation/Deallocation: Assigning memory to processes and reclaiming it afterwards.
Tracking: Maintaining a status for each memory location (allocated or free).
Protection: Preventing processes from accessing memory not allocated to them.
Efficiency: Maximising the number of processes that can be stored in memory to improve CPU utilisation.
Memory Partitioning: Paging and Segmentation
To manage memory effectively, the OS needs a way to divide it up. Two primary methods are paging and segmentation. Paging involves dividing a process's logical address space into fixed-size blocks called pages. Physical memory (RAM) is similarly divided into fixed-size frames. The OS maintains a page table for each process, which maps the pages to their corresponding frames in RAM. This allows a process's memory to be non-contiguous, meaning its pages can be scattered across different physical memory locations, which is highly flexible.
Segmentation takes a different approach. Instead of fixed-size blocks, it divides a program into logical units of varying sizes, called segments. A typical program might be segmented into a code segment, a data segment, and a stack segment. Each segment is a contiguous block of memory. This model is more intuitive from a programmer's perspective, as it mirrors the logical structure of the program and allows for granular protection (e.g., making the code segment read-only).
Paging Pros: Solves the problem of external fragmentation. Allocation is simple as any free frame can be used.
Paging Cons: Can suffer from internal fragmentation if a process's memory needs are not an exact multiple of the page size. The page table itself consumes memory.
Segmentation Pros: No internal fragmentation. Logical grouping of code and data supports sharing and protection.
Segmentation Cons: Suffers from external fragmentation, where free memory is broken into small, unusable pieces. Memory allocation is more complex.
Examiners love asking for a comparison of paging and segmentation. Create a table with key features: block size (fixed vs. variable), fragmentation (internal vs. external), and logical structure (physical vs. programmer's view). This will help you structure your answer for maximum marks.
Virtual Memory: The Illusion of Infinite Space
Virtual memory is a powerful technique that allows a system to run programs that are larger than the physical RAM available. It achieves this by using a portion of the secondary storage (like an SSD or HDD) as an extension of RAM. The OS moves data between RAM and this secondary storage area (often called the 'swap file' or 'paging file') as needed. This process is typically implemented using demand paging, where pages are only loaded into RAM when they are actually requested by the CPU.
When a program tries to access a memory address on a page that isn't currently in RAM, a hardware trap called a page fault occurs. The OS's page fault handler then takes over. It finds the required page on the disk, finds a free frame in RAM (or swaps out an existing page if RAM is full), loads the required page into the frame, updates the page table, and resumes the instruction that caused the fault. To the program, this entire process is transparent, apart from a slight delay.
Allows for an effective memory size much larger than the physical memory.
Increases the degree of multiprogramming, as more processes can be kept in memory.
Implemented using demand paging and a swap file on the hard disk.
Page faults are the mechanism for loading pages on demand.
Thrashing: When Swapping Goes Wrong
While virtual memory is incredibly useful, it has a significant drawback if overused. If a system has too many processes competing for too little physical memory, it can enter a state known as thrashing. In this state, the OS is constantly swapping pages in and out of memory because processes are frequently faulting for pages they need. The system spends the vast majority of its time servicing page faults rather than executing program code, leading to a catastrophic drop in performance. The CPU utilisation plummets because processes are always waiting for the disk.
Worked examples
See the formulas applied — reveal one step at a time, like the exam.
A computer system uses paging with a page size of 4 KB ( bytes). A process has a logical address of 7156. Determine the page number and the offset for this address.
- 1
The page size is 4 KB, which is bytes. We can find the page number and offset using integer division and the modulo operator.
A computer with 64 MB of available physical RAM is attempting to run four processes, each with a memory requirement of 20 MB. The OS uses virtual memory with demand paging. (a) Explain how the OS can run these processes simultaneously. [3 marks] (b) Describe a potential performance problem that could arise in this scenario. [2 marks]
- 1
(a) [3 marks]
- The total memory required by the processes is MB = 80 MB, which is greater than the 64 MB of available RAM. [1 mark]
- The OS uses virtual memory to manage this. It will load only a subset of the pages for each process into RAM initially. [1 mark]
- When a process needs a page that is not in RAM, a page fault occurs, and the OS loads the required page from the hard disk, swapping out another page if necessary. This creates the illusion that all 80 MB are in main memory. [1 mark]
How it all connects
The big idea sits in the middle — tap a linked idea to explore the link.
Tap a linked idea to see how it connects back to the main topic — that connection is what examiners reward.
Glossary
Try to recall each definition before you reveal it.
Quick check
Answer in your head first — then tap to check. No pressure.
Revision flashcards
Flip the card. Test yourself before the exam.
Memory Management
The process by which an operating system manages the computer's primary memory (RAM), allocating portions to programs as needed and freeing it when no longer in use.
Key takeaways
Review these before you close the topic — retrieval beats re-reading.
- ✓
Allocation/Deallocation: Assigning memory to processes and reclaiming it afterwards.
- ✓
Tracking: Maintaining a status for each memory location (allocated or free).
- ✓
Protection: Preventing processes from accessing memory not allocated to them.
- ✓
Efficiency: Maximising the number of processes that can be stored in memory to improve CPU utilisation.
Practice — then mark it
The whole point: a real Cambridge question, marked mark-by-mark.
Practice Questions: Memory Management
Practice Questions: Memory Management
Extra simulations & links
PhET, GeoGebra and other curated tools — open in a new tab.
Frequently asked
Checkpoint
One marked question is worth ten re-reads — close the loop before you move on.
Reading it isn’t knowing it — prove it.
Before you move on: do Practice Questions: Memory Management on paper, snap a photo, and get examiner-style feedback on exactly where you win and lose marks.