What Is Paging in Operating Systems?
Learn what paging is in operating systems, how pages and frames work, the role of the page table, and how it eliminates external memory fragmentation.
Expected Interview Answer
Paging is a memory management scheme that splits a process's virtual memory into fixed-size blocks called pages, and physical RAM into equal-size frames, so the OS can load pages into any free frame without needing contiguous memory.
Each process has a page table that maps its virtual pages to physical frames. When the CPU generates a virtual address, the memory management unit translates it using this table to find the actual physical location. Because pages can be scattered anywhere in RAM, paging eliminates external fragmentation that plagued older contiguous-allocation schemes. Pages not currently needed can be swapped out to disk, letting the system run more processes than physical memory could otherwise hold, at the cost of a page fault when a swapped-out page is accessed again.
- Eliminates external memory fragmentation
- Allows non-contiguous physical memory allocation
- Enables virtual memory larger than physical RAM
- Supports process isolation via separate page tables
- Makes swapping and demand loading possible
AI Mentor Explanation
Paging is like storing a team's kit not in one long shelf but in identical numbered lockers scattered across the pavilion. The equipment manager's locker chart tells him exactly which locker holds each item, so gear can sit in any free locker rather than needing one giant continuous shelf, and rarely used gear can be sent to the storeroom until requested again.
Step-by-Step Explanation
Step 1
Split virtual memory into pages
A process's address space is divided into equal-size pages, typically 4KB each.
Step 2
Split physical memory into frames
RAM is divided into frames of the same size as a page, so any page fits any frame.
Step 3
Maintain a page table
Each process gets a page table mapping its virtual page numbers to physical frame numbers.
Step 4
Translate addresses at runtime
The MMU uses the page table to convert every virtual address the CPU generates into a physical address.
Step 5
Handle page faults
If a referenced page isn't in memory, the OS pauses the process, loads the page from disk, updates the table, and resumes.
What Interviewer Expects
- Explains pages and frames are fixed, equal-size units
- Describes the role of the page table in address translation
- Knows paging removes external fragmentation
- Understands page faults and demand paging
- Can contrast paging with segmentation
Common Mistakes
- Confusing paging with segmentation (variable-size divisions)
- Thinking pages must be stored contiguously in RAM
- Forgetting the MMU is what performs address translation
- Ignoring internal fragmentation within the last page of a process
Best Answer (HR Friendly)
“Paging is how a computer's operating system breaks memory into equal-size chunks so it can store a program's data anywhere in RAM that has free space, instead of needing one long unbroken block. This makes memory use more flexible and lets the computer run more programs than it could otherwise fit at once.”
Code Example
# Virtual address breakdown: [ page number | offset ]
# Example: 4KB pages -> offset is lower 12 bits
virtual_address = 0x2140
page_number = virtual_address >> 12 # 0x2
offset = virtual_address & 0xFFF # 0x140
page_table = {0x0: 0x7, 0x1: 0x3, 0x2: 0x9} # page -> frame
frame = page_table[page_number] # 0x9
physical_address = (frame << 12) | offset
print(hex(physical_address)) # 0x9140
Follow-up Questions
- What is the difference between paging and segmentation?
- What causes a page fault and how is it handled?
- What is a TLB and why does it speed up address translation?
- How does demand paging differ from pre-paging?
- What is thrashing and how is it related to paging?
MCQ Practice
1. What does paging split memory into?
Paging divides virtual memory into fixed-size pages and physical memory into equal-size frames.
2. What translates a virtual address to a physical address?
The MMU consults the process's page table to convert virtual addresses into physical frame addresses at runtime.
3. What problem does paging primarily eliminate?
Because pages can be placed in any free frame, paging removes the external fragmentation caused by contiguous allocation schemes.
Flash Cards
What is a page? — A fixed-size block of a process's virtual memory, typically 4KB.
What is a frame? — A fixed-size block of physical memory equal in size to a page, where a page can be loaded.
What does a page table do? — Maps a process's virtual page numbers to the physical frame numbers holding them.
What is a page fault? — A trap raised when a process accesses a page not currently loaded in physical memory.