Address Binding, Paging, Segmentation, Virtual Memory, Swapping, Fragmentation & Page Replacement
1. What is Memory Management?
Memory Management is the OS function that controls and coordinates use of the computer's main memory (RAM). It decides which process gets memory, how much, when to allocate or release it, and how to protect processes from each other.
| Application | Memory Needed |
| Browser | 3 GB |
| IDE | 2 GB |
| Music Player | 500 MB |
| Antivirus | 1 GB |
| OS itself | 1.5 GB |
| Objective |
| Efficient utilization of memory |
| Protection between processes |
| Fast allocation and deallocation |
| Support multiprogramming |
| Maximize CPU utilization |
2. Memory Hierarchy
| Level (Fastest → Slowest) | Speed | Cost per Bit | Capacity |
| CPU Registers | Highest | Highest | Lowest |
| Cache | Very High | High | Small |
| Main Memory (RAM) | High | Medium | Medium |
| SSD / HDD | Low | Low | Very Large |
| Optical Disk / Tape | Lowest | Lowest | Largest |
📌 Exam Trick: Moving down the hierarchy — Speed ↓ | Cost per bit ↓ | Capacity ↑
3. Address Binding
Programs use symbolic addresses. These must be converted to actual memory addresses. This conversion is called Address Binding.
| Type | When | Advantage | Disadvantage |
| Compile-Time | During compilation | Simple and fast | Cannot relocate program later |
| Load-Time | When program is loaded into memory | Can relocate before execution | Slower startup |
| Execution-Time | While program is running | Most flexible; supports virtual memory | Requires MMU hardware support |
📌 Most modern OS use Execution-Time binding. Memory Trick — CLE: C → Compile | L → Load | E → Execution
Memory Management Unit (MMU)
The MMU is hardware that converts logical (virtual) addresses into physical addresses.
| Flow |
| CPU ↓ Logical Address ↓ MMU ↓ Physical Address ↓ RAM |
4. Logical Address vs Physical Address
| Feature | Logical Address | Physical Address |
| Generated by | CPU | MMU |
| Also called | Virtual Address | Real Address |
| Visible to | User programs | RAM hardware |
| Purpose | Program uses this address | Actual location in RAM |
5. Memory Allocation
| Method | Description | Advantage | Disadvantage |
| Contiguous Allocation |
Each process occupies one continuous block of RAM |
Simple, fast access |
Causes fragmentation |
| Non-Contiguous Allocation |
Process divided into parts stored at different locations (Paging, Segmentation) |
Better utilization, flexible |
More complex; needs page/segment table |
6. Fragmentation
Fragmentation means memory is wasted because of inefficient allocation.
| Type | Definition | Example | Common In |
| Internal Fragmentation |
Unused space inside an allocated memory block |
Block = 8 KB, Process needs 6 KB → 2 KB wasted inside |
Fixed-size allocation (paging) |
| External Fragmentation |
Unused memory exists between allocated blocks; total free memory may be enough but not contiguous |
Process A | Free | Process B | Free | Process C |
Variable-size allocation (segmentation) |
📌 Memory Trick: Inside = Internal | Outside (between) = External
7. Compaction
Compaction moves processes to make all free memory contiguous.
| Before Compaction | After Compaction |
| P1 | Free | P2 | Free | P3 | P1 | P2 | P3 | Free (one large block) |
| Advantage | Disadvantage |
| Removes external fragmentation | Time-consuming; processes must pause |
8. Paging
Paging divides logical memory into fixed-size pages and physical memory into frames of the same size. Pages are loaded into any available frame — no need for contiguous allocation.
| Term | In Logical Memory | In Physical Memory |
| Page | Fixed-size block of logical memory | — |
| Frame | — | Fixed-size block of physical RAM |
| Page Table | Maps each page number to a frame number |
Page Table & Address Translation
| Page Number | Frame Number |
| 0 | 5 |
| 1 | 2 |
| 2 | 8 |
| Address Translation Flow |
| Logical Address (Page Number, Offset) ↓ Page Table ↓ Frame Number ↓ Physical Address (Frame Number, Offset) |
| Advantages | Disadvantages |
| Eliminates external fragmentation | Small internal fragmentation possible |
| Efficient memory utilization | Page table itself consumes memory |
9. Segmentation
Segmentation divides memory into logical segments based on program structure (Code, Data, Stack, Heap). Each segment has a variable size.
| Segment Table Field | Meaning |
| Base Address | Starting physical address of the segment |
| Limit (Size) | Length of the segment |
| Advantages | Disadvantages |
| Matches logical program structure | Suffers from external fragmentation |
| Easier protection and sharing | Variable-size segments harder to manage |
Paging vs Segmentation
| Feature | Paging | Segmentation |
| Division size | Fixed-size pages | Variable-size segments |
| Division basis | Physical (hardware) | Logical (program structure) |
| External fragmentation | None | Possible |
| Internal fragmentation | Small amount possible | None |
| Address format | Page number + Offset | Segment number + Offset |
10. Virtual Memory
Virtual memory allows programs larger than physical RAM to execute by using disk space as an extension of memory.
| Scenario | Without Virtual Memory | With Virtual Memory |
| RAM = 8 GB, Program = 20 GB | Cannot run | Runs successfully |
| Advantages | Disadvantages |
| Larger programs can run | Slower than pure RAM access |
| Better multitasking | Page faults add overhead |
| Efficient RAM utilization | Can lead to thrashing if overused |
11. Swapping
Swapping temporarily moves an entire process from RAM to disk (swap space) and brings it back later.
| Step | Action |
| 1 | RAM becomes full |
| 2 | Inactive process moved to disk (swap out) |
| 3 | Memory becomes available for other processes |
| 4 | Process brought back when needed (swap in) |
| Advantage | Disadvantage |
| Supports multiprogramming beyond RAM size | Disk is much slower than RAM; high latency |
12. Demand Paging
Pages are loaded into RAM only when they are actually needed, not all at program startup.
| Advantages |
| Saves RAM — unused pages stay on disk |
| Faster program startup |
| Supports large programs on limited RAM |
13. Page Fault
A page fault occurs when a requested page is not present in RAM.
| Step | Action |
| 1 | CPU requests a page |
| 2 | Page not found in RAM (miss) |
| 3 | Page fault interrupt raised |
| 4 | OS loads the required page from disk into RAM |
| 5 | Program resumes execution |
Frequent page faults slow the system significantly and can lead to thrashing.
14. Page Replacement Algorithms
When RAM is full and a new page is needed, the OS must select a victim page to remove. This is page replacement.
FIFO (First-In, First-Out)
The oldest page in memory is removed first.
| Advantage | Disadvantage |
| Simple to implement | May suffer from Belady's Anomaly |
| Fair ordering | Does not consider how recently a page was used |
Belady's Anomaly: Increasing the number of page frames can increase the number of page faults in FIFO (counterintuitive).
LRU (Least Recently Used)
Remove the page that has not been used for the longest time.
| Advantage | Disadvantage |
| Generally performs better than FIFO | Requires tracking usage history (overhead) |
| No Belady's Anomaly | More complex to implement |
Optimal Page Replacement
Replace the page that will not be used for the longest time in the future.
| Advantage | Disadvantage |
| Produces minimum possible page faults | Requires future knowledge — not practical |
| Used as a theoretical benchmark | Cannot be implemented in real systems |
Algorithm Comparison
| Algorithm | Strategy | Performance | Practical? | Belady's Anomaly? |
| FIFO | Remove oldest page | Average | Yes | Yes |
| LRU | Remove least recently used | Good | Yes | No |
| Optimal | Remove page not needed longest | Best (minimum faults) | No (needs future info) | No |
📌 Memory Trick — FLO: F → FIFO | L → LRU | O → Optimal
15. Thrashing
Thrashing occurs when the system spends more time swapping pages than executing programs.
| Causes | Symptoms | Solutions |
| Too many processes running | High disk activity (constant page reads/writes) | Increase RAM |
| Insufficient RAM for active processes | Very low CPU utilization | Reduce multiprogramming level |
| Excessive page faults | System appears frozen / extremely slow | Use better page replacement algorithm |
Memory Protection
The OS protects memory using: Base Register, Limit Register, MMU, and Access Permissions. This ensures no process can access another process's memory.
| Mechanism | Purpose |
| Base Register | Stores the starting address of a process's memory |
| Limit Register | Stores the size of a process's memory region |
| MMU | Checks every memory access against base/limit registers |
| Access Permissions | Read / Write / Execute flags per region |
Memory Tricks
| Mnemonic | Full Form |
| Address Binding — CLE |
C → Compile-Time L → Load-Time E → Execution-Time |
| Fragmentation |
Inside = Internal | Outside (between blocks) = External |
| Page Replacement — FLO |
F → FIFO L → LRU O → Optimal |
| Memory Hierarchy — RCRSD |
Registers → Cache → RAM → SSD/HDD → Disk/Tape |
Frequently Asked Exam Questions
| Question | Answer |
| What is memory management? | The OS function that manages allocation and deallocation of RAM |
| Difference between logical and physical address? | Logical: generated by CPU; Physical: generated by MMU, used by RAM |
| Difference between paging and segmentation? | Paging: fixed-size pages (physical division); Segmentation: variable-size logical segments |
| Internal vs external fragmentation? | Internal: waste inside allocated block; External: waste between blocks |
| What is virtual memory? | Technique using disk to extend RAM so larger programs can execute |
| What is a page fault? | Requested page not present in RAM; OS loads it from disk |
| Optimal page replacement? | Replace page not needed for longest future time — theoretical minimum faults |
| What is thrashing? | System spends more time swapping pages than executing programs |
| What is Belady's Anomaly? | In FIFO, adding more frames can increase page faults |
Practice MCQs
-
1. Which hardware converts logical addresses into physical addresses?
A. ALU B. Cache C. MMU D. PCB
✅ Answer: C — MMU (Memory Management Unit)
-
2. Which fragmentation occurs inside an allocated memory block?
A. External B. Internal C. Paging D. Thrashing
✅ Answer: B — Internal Fragmentation
-
3. Paging divides memory into:
A. Segments B. Frames and Pages C. Blocks and Files D. Tracks and Sectors
✅ Answer: B — Frames and Pages
-
4. Which page replacement algorithm is theoretically optimal?
A. FIFO B. LRU C. Optimal D. Round Robin
✅ Answer: C — Optimal Page Replacement
-
5. A page fault occurs when:
A. RAM is damaged B. Requested page is not in main memory C. CPU overheats D. Cache becomes full
✅ Answer: B — Requested page is not in main memory