Sub topic 1
Address Spaces and Address Binding
A process needs memory for its code, data, heap, and stack. The operating system gives each process an address space, which is the set of addresses that the process can use. The process uses these addresses without knowing where its data is stored in physical memory.
Prerequisites
This chapter assumes that you know binary and hexadecimal numbers, basic CPU and main-memory organization, and the meaning of a process and a context switch.
Logical, Virtual, and Physical Addresses
A logical address is an address generated by the CPU while a program runs. In many operating systems, logical address and virtual address mean the same thing. The process uses this private address space.
A physical address is the actual location in main memory, such as RAM. The operating system and hardware translate virtual addresses into physical addresses.
The memory-management unit (MMU) is hardware that performs this translation during a memory access. The operating system configures the MMU with information about the process's memory layout.
| Address type | Generated or used by | Meaning |
|---|---|---|
| Logical or virtual | CPU and program | Address used inside a process |
| Physical | Main-memory hardware | Actual RAM location |
| Effective physical | MMU output | RAM location after translation |
A process can use virtual address 0x2000 even when that address maps to different physical locations at different times. This gives processes isolation and lets the operating system move memory without changing the program's addresses.
Address Binding
Address binding is the process of mapping program addresses to memory addresses. It can happen at different times.
- Compile-time binding happens when the compiler creates code for a fixed memory location. If the starting location changes, the program usually must be recompiled.
- Load-time binding happens when the loader places the program in memory. The loader adjusts relocatable addresses after choosing the starting location.
- Execution-time binding happens while the program runs. Hardware translates addresses on every access, so the process can move during execution.
Modern general-purpose systems usually use execution-time binding. It supports virtual memory, process isolation, and movement of pages between RAM and storage.
Base and Limit Registers
A simple relocation method uses two registers:
- The base register stores the first physical address assigned to a process.
- The limit register stores the size of the process's valid address range.
For a logical address L, the MMU checks:
- If
Lis greater than or equal to the limit, it raises a protection fault. - Otherwise, it computes the physical address as
base + L.
For example, if the base is 12,000 and the limit is 4,000, logical address 1,500 becomes physical address 13,500. Logical address 4,000 is invalid because valid offsets range from 0 through 3,999.
This method provides relocation and basic protection, but it requires one contiguous physical region for each process. Paging later removes this requirement by dividing memory into fixed-size pieces.
Why Separate Address Spaces Matter
Each process can use the same virtual address values without accessing another process's memory. During a context switch, the operating system changes the translation information used by the MMU. A process therefore sees its own address space even though processes share the same RAM.
This separation supports:
- Protection against accidental or malicious access.
- Relocation when memory locations change.
- Sharing of selected regions, such as read-only program code.
- Efficient process creation and virtual-memory techniques.
Exercise
A process has base register 8,000 and limit register 2,500. What physical address corresponds to logical address 2,000, and what happens for logical address 2,500?
Show answer
Logical address 2,000 maps to physical address 10,000. Logical address 2,500 is rejected because it equals the limit and is outside the valid range.