Figure 4.1: The Three Stages of Address Binding in an Operating System
Figure 4.1: The Three Stages of Address Binding in an Operating System
1. Compile-Time Binding
Compiler generates Absolute Code when exact RAM address is known in advance
2. Load-Time Binding
Compiler generates Relocatable Code; final binding happens when Loader loads program into RAM
3. Execution-Time Binding
Binding is delayed until runtime using MMU Hardware (Used by all modern OS!)
Explanation
- Compile-time binding fixes addresses early and load-time binding chooses them when loading.
- Execution-time binding allows translation while the program is running.
Figure 4.2: Dynamic Address Translation by the Memory Management Unit (MMU)
Figure 4.2: Dynamic Address Translation by the Memory Management Unit (MMU)
CPUGenerates Logical Address =
346→
MMU (Relocation Register = 14000)Adds Base: 14000 + 346
→
Physical RAMAccesses Physical Address =
14346Explanation
- The MMU checks the logical address against the permitted range.
- It uses relocation information to produce the physical address for a valid reference.
Figure 4.3: Process Swapping Between Main Memory (RAM) and Disk Backing Store
Figure 4.3: Process Swapping Between Main Memory (RAM) and Disk Backing Store
Main Memory (RAM)Process P1 (Blocked / Low Priority)
→ Swap Out (Frees RAM) →
Backing Store (Hard Disk / SSD)Holds swapped processes in Swap Space
→ Swap In (Loads P2 to RAM) →
Main Memory (RAM)Process P2 (Ready to Run!)
Explanation
- Swapping moves process memory to backing storage to free RAM.
- Restoring it later requires disk transfer and appropriate address mapping.
Figure 4.4: Contiguous Memory Allocation vs Non-Contiguous Memory Allocation
Figure 4.4: Contiguous Memory Allocation vs Non-Contiguous Memory Allocation
1. Contiguous Memory Allocation
- Each process is contained in a single continuous (adjacent) block of RAM addresses
- Simple & fast address translation using Base + Limit registers
- Types: Fixed Partitioning (MFT) & Variable/Dynamic Partitioning (MVT)
- Drawback: Suffers from Internal & External Fragmentation
2. Non-Contiguous Memory Allocation
- A single process is divided into blocks and placed in scattered, non-adjacent locations in RAM
- Uses a Page Table or Segment Table to keep track of blocks
- Types: Paging and Segmentation
- Benefit: Eliminates External Fragmentation (in Paging)!
Explanation
- Contiguous allocation places a process in one continuous region.
- Non-contiguous allocation lets its parts occupy different physical locations.
Figure 4.5: Internal Fragmentation vs External Fragmentation
Figure 4.5: Internal Fragmentation vs External Fragmentation
1. Internal Fragmentation (Waste INSIDE Block)
- Occurs when memory is divided into Fixed-Size blocks (Fixed Partitioning / Paging)
- A process of
18 KBis given a20 KBblock →2 KBwasted INSIDE the block! - Belongs to the allocated partition, so no other process can use it
2. External Fragmentation (Waste OUTSIDE Blocks)
- Occurs in Variable-Size Contiguous Allocation & Segmentation
- Total free RAM is
100 KB, but split into scattered holes (`30 KB + 40 KB + 30 KB`), so a60 KBprocess cannot fit! - Solved using Compaction or Paging
Explanation
- Internal fragmentation wastes space inside an allocated region.
- External fragmentation leaves free space split across separate holes.
Figure 4.6: How Compaction Eliminates External Fragmentation
Figure 4.6: How Compaction Eliminates External Fragmentation
Before Compaction[P1] [Free 30K] [P2] [Free 40K] [P3] [Free 30K]
→ Shift Processes Together →
After Compaction[P1] [P2] [P3] [One Big Free Block: 100 KB!]
Explanation
- Compaction moves allocated regions so small holes become one larger free area.
- It requires a way to relocate affected addresses safely.
Figure 4.7: Paging Hardware — Translating Logical Address (p, d) to Physical Address (f, d)
Figure 4.7: Paging Hardware — Translating Logical Address (p, d) to Physical Address (f, d)
CPU Logical AddressPage No (p) | Offset (d)
→ Index p in →
Page TableLooks up Frame No (f) for Page p
→ Combine f + d →
Physical RAM AddressFrame No (f) | Offset (d)
Explanation
- The page number selects a page-table entry containing the frame number.
- The offset passes through unchanged to locate the byte in that frame.
Figure 4.8: Segmentation Hardware — Address Translation Using Segment Table (Base & Limit)
Figure 4.8: Segmentation Hardware — Address Translation Using Segment Table (Base & Limit)
CPU Logical AddressSegment (s) | Offset (d)
→ Look up s →
Segment TableReads Limit (Size) & Base (Start Addr)
→ Check d < Limit →
Physical AddressPhysical Addr = Base + d
Explanation
- The segment number selects a base and limit.
- A valid offset is added to the base, while an out-of-range offset causes a fault.
Figure 4.9: The 6 Steps of Handling a Page Fault in Demand Paging
Figure 4.9: The 6 Steps of Handling a Page Fault in Demand Paging
Step 1Check Page Table
MMU checks Page Table entry for Page X; sees bit is
i (Invalid)Step 2Trap to OS (Page Fault)
MMU generates a Page Fault Trap to the Operating System Kernel
Step 3Locate Page on Backing Store
OS verifies the reference is legal and finds Page X on the Hard Disk / SSD
Step 4Read Page into Free RAM Frame
OS finds a free Frame in RAM (or replaces an old frame) and loads Page X from Disk
Step 5Update Page Table to Valid (v)
Once disk read finishes, OS sets the Frame Number and flips bit from
i → v (Valid)Step 6Restart Instruction
CPU restarts the exact instruction that caused the Page Fault — now it succeeds!
Explanation
- A fault on a valid absent page makes the OS locate the data and obtain a frame.
- After loading the page and updating its mapping, execution can retry the instruction.
Figure 4.10: The 3 Major Page Replacement Algorithms in Operating Systems
Figure 4.10: The 3 Major Page Replacement Algorithms in Operating Systems
1. FIFO (First-In, First-Out)
Replaces the OLDEST page that was brought into RAM first (Suffers from Belady's Anomaly)
2. Optimal (OPT / MIN)
Replaces the page that will NOT be used for the longest period of time in the FUTURE
3. LRU (Least Recently Used)
Replaces the page that has NOT been used for the longest period of time in the PAST
Explanation
- FIFO evicts the oldest loaded page and LRU evicts the least recently used.
- Optimal evicts the page whose next use is furthest in the future.