Introduction
Relocation is the process of adjusting process addresses so that a program can be executed at different memory locations. This is essential in multiprogramming and dynamic memory management, as processes do not always get the same memory address every time they execute.
When a program is compiled, it is often designed with logical addresses. However, when loaded into memory, it must be mapped to a physical address. If the OS moves a process in memory (due to swapping, paging, or memory reorganization), relocation ensures that the process still works correctly.
Why is Relocation Needed?
- Efficient Memory Utilization – The OS may load processes wherever space is available in RAM.
- Multiprogramming Support – Multiple programs must share limited memory, requiring flexible relocation.
- Swapping & Virtual Memory – Processes may be moved between RAM and disk (or different memory segments) for efficient execution.
- Dynamic Loading & Linking – Some program modules are loaded at runtime, requiring address adjustment.
Types of Relocation
Relocation can occur at different stages:
1. Static Relocation
✔ Happens before execution, usually during program loading.
✔ The OS loads the program into memory and adjusts all memory addresses before execution begins.
✔ If the process moves, it must be reloaded with new addresses.
📌 Example:
- A process is compiled with an assumed base address of 1000.
- The OS loads it at 5000, so it modifies all addresses accordingly before execution.
Limitation ❌: Once loaded, the process cannot be moved.
2. Dynamic Relocation (Execution-Time Relocation)
✔ Happens during execution using hardware support (Memory Management Unit – MMU).
✔ The OS uses base and limit registers to map logical addresses to physical addresses dynamically.
✔ If the process moves in memory, the addresses are automatically adjusted without stopping execution.
📌 Example:
- A process starts at memory address 4000.
- The OS moves it to 8000 during execution.
- The base register is updated, and the process continues running smoothly.
Advantage ✅: Processes can be moved freely without reloading.
Relocation Using Base and Limit Registers
Modern OS use base and limit registers for dynamic relocation:
- Base Register: Holds the starting physical address of a process in memory.
- Limit Register: Defines the process size to prevent access beyond allocated memory.
🔹 Logical Address (LA) → Generated by the program.
🔹 Physical Address (PA) = Base Register + Logical Address.
📌 Example Calculation:
- Base Register = 3000
- Logical Address = 500
- Physical Address = 3000 + 500 = 3500
If the OS moves the process to 6000, only the base register changes, and all addresses remain valid.
Comparison of Static vs. Dynamic Relocation
Feature | Static Relocation | Dynamic Relocation |
---|---|---|
When It Happens? | Before execution | During execution |
Flexibility | ❌ Not flexible | ✅ Highly flexible |
Process Movement | ❌ Process cannot move | ✅ Process can move |
Hardware Support | ❌ Not required | ✅ Needs MMU (Memory Management Unit) |
Example Use Case | Simple OS, fixed memory allocation | Modern OS with paging & segmentation |
Role of Relocation in Virtual Memory & Swapping
- In virtual memory, relocation allows processes to use more memory than physically available.
- In swapping, processes can be moved between RAM and disk without affecting execution.
Conclusion
Relocation is a key aspect of modern memory management that enables efficient use of RAM, process flexibility, and smooth execution. Static relocation is simple but rigid, while dynamic relocation offers better flexibility and performance with MMU support.