Paging in Operating Systems
Paging is a memory management scheme that divides logical memory into fixed-size pages and physical memory into frames of the same size, so any page can be placed in any free frame. A per-process page table maps each page number to a frame number, removing the need for a process to occupy one contiguous block of RAM.
Paging is a memory management scheme that eliminates the need for a process's memory to occupy one contiguous block of physical RAM. Instead, both logical memory (divided into fixed-size pages) and physical memory (divided into fixed-size frames, the same size as a page) are broken into equal-sized chunks, and any page can be placed into any available frame, anywhere in physical memory.
How address translation works with paging
A logical address under paging is split into two parts: a page number and an offset within that page. The OS maintains a page table for each process, which maps every page number to the physical frame number it's currently stored in. To translate a logical address: look up the page number in the page table to get the frame number, then combine that frame number with the original offset to get the real physical address.
Step-by-step translation example
Say the page size is 1024 bytes (so the offset needs 10 bits), and a process's page table looks like this:
| Page Number | Frame Number |
|---|---|
| 0 | 5 |
| 1 | 2 |
| 2 | 9 |
The process generates logical address 2050. Divide by page size (1024): page number = 2050 / 1024 = 2 (integer division), offset = 2050 mod 1024 = 2. Look up page 2 in the page table: frame 9. Physical address = frame number x page size + offset = 9 x 1024 + 2 = 9218.
Notice the process's 3 pages (0, 1, 2) are stored in frames 5, 2, and 9, completely non-contiguous in physical memory, and none of that matters to the process itself; the page table handles the translation transparently.
Why this solves external fragmentation
Since any page can go into any free frame, there's no need to find one big contiguous free region for a process. A process needing 3 pages just needs any 3 free frames, anywhere in physical memory. This is exactly why paging eliminates external fragmentation (covered in its own topic), at the cost of some internal fragmentation in the last, partially-used page.
Where this matters in real systems
Every modern general-purpose operating system, Linux, Windows, macOS, uses paging as its foundational memory management scheme, almost always combined with virtual memory and demand paging (covered in their own dedicated topics) so that not every page even needs to be in physical RAM at once. Hardware support for this, in the form of a Translation Lookaside Buffer (a small, fast cache of recent page-table lookups built into the CPU), exists specifically because page table lookups happen on nearly every single memory access a running program makes, and doing a full page-table walk every single time would be far too slow without that cache.
What interviewers actually ask about paging
- "What problem does paging solve?" External fragmentation, by allowing a process's memory to be scattered across non-contiguous physical frames instead of requiring one contiguous block.
- "Walk me through translating a logical address to a physical address under paging." Split the logical address into a page number and offset, look up the frame number for that page in the page table, then combine the frame number and offset to get the physical address.
- "What does a page table actually store?" A per-process mapping from each page number to the physical frame number currently holding that page's data.
- "What is a TLB and why does it matter for paging performance?" A Translation Lookaside Buffer, a small hardware cache of recent page-table translations, which avoids the cost of a full page-table lookup on every single memory access.
Key takeaways
- Paging divides logical and physical memory into fixed-size pages and frames, letting any page live in any free frame.
- A page table per process maps page numbers to frame numbers for address translation.
- This eliminates external fragmentation at the cost of some internal fragmentation.
- A TLB caches recent translations in hardware since page lookups happen on almost every memory access.
More in Memory Management
Browse all Operating Systems topics
Log in to save which topics you've read across every subject.
Frequently asked questions
What problem does paging solve?
External fragmentation, by allowing a process's memory to be scattered across non-contiguous physical frames instead of requiring one contiguous block.
Walk me through translating a logical address to a physical address under paging.
Split the logical address into a page number and offset, look up the frame number for that page in the page table, then combine the frame number and offset to get the physical address.
What does a page table actually store?
A per-process mapping from each page number to the physical frame number currently holding that page's data.
What is a TLB and why does it matter for paging performance?
A Translation Lookaside Buffer, a small hardware cache of recent page-table translations, which avoids the cost of a full page-table lookup on every single memory access.