Relocation in Operating Systems
1. What is Relocation?
Relocation is the process of adjusting memory addresses so that a program can execute
correctly regardless of its actual physical memory location. It allows the operating system
to move processes in memory dynamically to optimize resource usage.
Why is Relocation Needed?
• The OS loads processes in different memory locations depending on availability.
• Programs are compiled assuming they start from address 0, but in reality, they can
be placed anywhere.
• Swapping, compaction, and dynamic memory allocation require relocation to
ensure correct address references.
• Supports multiprogramming and virtual memory by allowing processes to be
moved without stopping execution.
Relocation ensures that a program runs correctly even when moved in memory.
2. How Does Relocation Work?
A. Logical vs. Physical Addresses
• Logical Address: The address generated by the CPU.
• Physical Address: The actual location in RAM where data is stored.
• Address Translation: Converts logical addresses to physical addresses.
B. Role of Base and Limit Registers (Execution-Time Relocation)
• Base Register: Holds the starting physical address of a process.
• Limit Register: Ensures that the process does not access memory beyond its
allocated range.
• Address Translation Formula:
Physical Address=Base Register+Logical Address\text{Physical Address} =
\text{Base Register} + \text{Logical Address}
Example:
• Base Register = 5000
• Logical Address = 100
• Physical Address = 5000 + 100 = 5100
This allows processes to move without modifying their code.
3. Types of Relocation
1⃣ Static Relocation (Load-Time Relocation)
• Address binding occurs before execution (at compile-time or load-time).
• The program is assigned a fixed physical address and cannot be moved during
execution.
• Limitation: If memory becomes fragmented, the program cannot be moved
dynamically.
Example:
• A program is compiled with a starting address = 5000.
• If loaded at 5000, it runs fine.
• If the OS wants to load it at 6000, the program must be recompiled with a new
address.
2⃣ Dynamic Relocation (Execution-Time Relocation)
• Address binding occurs during execution, allowing processes to be moved
dynamically.
• Uses Base Register & MMU (Memory Management Unit) for address translation.
• The program always uses logical addresses, which the MMU translates into
physical addresses at runtime.
• Advantage: The OS can move a program anywhere in memory without modifying
its code.
Example:
• Process A is assigned a Base Address = 5000.
• If it gets moved to Base Address = 8000, the MMU automatically updates
addresses, so no recompilation is needed.
Modern operating systems use dynamic relocation for flexibility.
4. What Helps in Relocation?
A. Memory Management Unit (MMU)
• Responsible for address translation from logical to physical addresses.
• Uses Base and Limit Registers in simple systems.
• Uses Paging and Segmentation in modern systems.
B. Paging (Solves Relocation Issues)
• Breaks memory into fixed-sized pages and maps them to frames in RAM.
• Page tables handle dynamic address translation, so a process can move without
modification.
• No need for a base register; OS just updates page table entries.
C. Segmentation
• Divides memory into variable-sized segments (Code, Data, Stack).
• Each segment has its own base and limit values.
• Relocation happens by updating the Segment Table when a process moves.
D. Translation Lookaside Buffer (TLB)
• Caches frequently used page table entries to speed up relocation and address
translation.
5. Comparison of Static vs. Dynamic Relocation
Feature Static Relocation Dynamic Relocation
When Binding Occurs Compile-Time / Load-Time Execution-Time
Feature Static Relocation Dynamic Relocation
Flexibility Fixed memory location Can be moved at runtime
Memory Utilization Less efficient More efficient
Requires MMU? No Yes
6. Advantages of Relocation
Efficient Memory Use – Processes can move to free spaces, reducing fragmentation.
Supports Multiprogramming – Multiple processes can share memory dynamically.
Enables Virtual Memory – Allows processes to execute even if they are partially in
RAM.
Avoids Program Modification – Programs don’t need recompilation for different
memory locations.
7. Disadvantages of Relocation
Overhead of Address Translation – Needs additional hardware like MMU and
relocation registers.
Performance Cost – Translating addresses at runtime can slow down execution.
Complexity – Requires OS support for dynamic memory allocation.
Conclusion
Relocation is essential for modern operating systems to support multiprogramming,
memory optimization, and dynamic process management. Dynamic relocation (using
MMU, paging, and segmentation) is the preferred method, as it allows flexible memory
allocation without modifying program code.
Would you like a detailed example of relocation in a real OS (Linux, Windows)?