←Back to Subject
Notes
Notes
Study material and explanations
Diagrams
Diagrams
Visualize concepts easily
Mnemonics
Mnemonics
Tricks to remember faster
One Night Prep
One Night Prep
Short and focused revision
Revision
Revision
Quick summary and key points
Important Questions
Important Questions
Practice most relevant questions
Notes

Memory Management: Address Binding, Logical vs Physical Address Space & Swapping

Study material and explanations for Unit 4

Memory Management: Address Binding, Logical vs Physical Address Space & Swapping

1. Introduction to Memory Management

In a computer system, the CPU can only fetch and execute instructions directly from Main Memory (RAM) and CPU registers—it cannot execute programs directly from the Hard Disk!

Memory Management is the core function of the Operating System that manages Main Memory (RAM):

  1. Keeping track of which parts of RAM are currently in use and by which process.
  2. Deciding which processes (or parts of processes) to move into and out of RAM.
  3. Allocating RAM space when processes request it and deallocating (freeing) it when processes terminate.
  4. Protecting one process’s memory space from being accessed or corrupted by another process (Base and Limit Registers).

2. Address Binding (Compile Time, Load Time & Execution Time)

When you write a C or Java program, you refer to variables using symbolic names like int count = 10; or totalMarks. The CPU and RAM, however, only understand numerical Physical Memory Addresses (like byte address 74014).

Definition of Address Binding: The process of mapping (translating) a program’s symbolic/logical instructions and data to actual physical memory addresses in RAM is called Address Binding.

Address binding can happen at three different stages of a program’s lifecycle:

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!)

1. Compile-Time Binding (Static Binding)

  • When it happens: If it is known at compile time exactly where the process will reside in RAM (e.g., starting at physical address 2000), the compiler generates Absolute Code containing fixed physical addresses.
  • Drawback: If the starting location in RAM ever changes later, the entire program must be recompiled from scratch! (Used only in tiny embedded microcontrollers or old MS-DOS .COM programs).

2. Load-Time Binding

  • When it happens: If it is not known at compile time where in RAM the process will reside, the compiler generates Relocatable Code (addresses relative to 0, like 0, +4, +8...).
  • Final address binding is delayed until Load Time, when the OS Loader picks a free starting address in RAM (say 5000) and adds 5000 to every relative address (5000, 5004, 5008...).
  • Drawback: Once loaded into RAM, the process cannot be moved to a different location in RAM during execution.

3. Execution-Time (Runtime / Dynamic) Binding

  • When it happens: If a process can be moved from one memory segment in RAM to another during its execution (for example, during Swapping or Compaction), then address binding must be delayed until Execution Time (Runtime)!
  • How it works: Special hardware inside the CPU called the MMU (Memory Management Unit) dynamically adds the value of a Relocation (Base) Register to every logical address generated by the CPU at runtime. (Virtually all modern operating systems—Windows, Linux, macOS—use Execution-Time Binding!)

3. Logical vs Physical Address Space & Role of MMU

This is one of the most important 5-mark questions in Unit 4 of DAVV BCA exams!

A. Logical Address (Virtual Address)

  • An address generated by the CPU while a program is running (e.g., byte 346 of the current program).
  • Logical Address Space: The set of all logical addresses generated by a program (typically ranges from 0 to MAX). The user program only ever sees its own Logical Address Space!

B. Physical Address (Real Address)

  • The actual hardware address seen by the Main Memory (RAM) unit (the address loaded into the Memory Address Register MAR of RAM, e.g., physical location 14346).
  • Physical Address Space: The set of all physical addresses corresponding to the logical addresses.

C. Role of the MMU (Memory Management Unit)

Who translates the CPU’s Logical Address into RAM’s Physical Address on the fly? A hardware device called 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 = 14346

Formula: Physical Address = Relocation (Base) Register Value + Logical Address

Comparison Table: Logical Address vs Physical Address

Basis Logical Address (Virtual Address) Physical Address (Real Address)
1. Generated By Generated by the CPU during program execution. Computed by the MMU (Memory Management Unit) hardware.
2. What It Refers To Refers to a location in the program’s virtual/logical view (starts at 0). Refers to an actual physical byte cell inside RAM chips.
3. User Visibility Visible to the user program and programmer. Invisible to the user program; handled strictly by OS & MMU.
4. When Identical? Identical to Physical Address in Compile-Time and Load-Time binding. Differs from Logical Address in Execution-Time (Runtime) binding!

4. Swapping in Operating Systems

What is Swapping?

Main Memory (RAM) has limited size (e.g., 8 GB). When too many processes are running at once and RAM becomes full, a process must be inside RAM to be executed, but an idle/blocked process can be temporarily moved out of RAM to the Hard Disk!

Definition of Swapping: Swapping is a memory management mechanism in which a process can be temporarily swapped out of Main Memory (RAM) to a fast disk area called the Backing Store (Swap Space), and later swapped back into RAM for continued execution!

  • Swapping is managed by the Medium-Term Scheduler.
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!)

Two Operations of Swapping:

  1. Swap Out (Roll Out): Moving a blocked or low-priority process from Main Memory (RAM) → Backing Store (Disk) to free up RAM space.
  2. Swap In (Roll In): Bringing a ready or higher-priority process from Backing Store (Disk) → Main Memory (RAM) so the CPU can execute it. (Note: Using Swapping specifically for Priority-based scheduling—where a low-priority process is swapped out so a newly arrived high-priority process can run immediately—is called Roll Out, Roll In).

Advantages & Disadvantages of Swapping:

  • Advantage: Allows the total memory used by all running processes to exceed the physical RAM size, increasing the Degree of Multiprogramming.
  • Disadvantage: Disk transfer time (Swap-out + Swap-in time) is slow compared to RAM speed, so frequent swapping causes high I/O overhead.

💡 Exam Preparation Tips for DAVV BCA

  • Always draw Figure 4.2 (CPU -> Logical Address 346 -> MMU [+14000] -> Physical Address 14346 -> RAM) when asked about Logical vs Physical Address Space or Address Binding!
  • Remember the term “Roll Out, Roll In” as a variant of Swapping used in Priority Scheduling.