Mapping virtual address to physical address
1 Answer

Address is used to uniquely identify the location of something inside the CPU memory. There are two types of addresses - physical and logical address.

Physical addresses

The physical addresses are provided by the hardware -

  • Per machine has one physical address space
  • Valid addresses are usually between 0 and some machine specific maximum
  • Not all addresses have to belong to the machine's main memory; other hardware devices can be mapped into the address space

The physical address, however, is not viewable directly by the user program and the logical address is utilized as a resource to access the physical address with the aid of a pointer.

Virtual addresses

The Virtual (or Logical) addresses are provided by the OS kernel -

  • one virtual address space per process
  • addresses may start at zero, but not necessarily
  • space may consist of several segments (i.e., have gaps)
  • viewable by the user program

A logical address is also created by a Central Processing Unit when a program is being executed whereas a physical address is an actual location found within the memory unit.

When a logical address is mapped to its corresponding physical address, it becomes a joint a memory management unit between the CPU and the bus that carries the memory since the tasks performed are similar when it gets to the address translation layer and the CPU.

Mapping virtual address to physical address

Mapping of virtual addresses to physical addresses is also called as address translation or address binding. OS divides physical memory into partitions. Different partitions can have different sizes.

  • Each partition can be given to a process as a virtual address space
  • virtual address == physical address
  • To change the partition, a program is loaded into requires recompilation or relocation (if the compiler produces relocatable code)
  • The number of processes is limited by the number of partitions size of virtual address space is limited by the size of the partition

The memory management unit (MMU) of the CPU contains a relocation register. Whenever a thread tries to access a memory location (through a virtual address), the value of the relocation register is added to the virtual memory address – dynamic binding. The kernel maintains a separate relocation value for each process (as part of the virtual address space); changes the relocation register at every context switch.

Properties: all programs can start at virtual address 0; the kernel can relocate a process w/o changing the program; kernel can allocate physical memory dynamically; each virtual address space is still contiguous in physical mem.

enter image description here

Fig: Mapping virtual address to physical address

Reallocation registers

enter image description here

Fig: Relocation Registers

In some systems, a virtual address space can be made up of multiple independent segments. A logical address then consists of two parts: (segment ID, address within the segment).

Each segment can grow or shrink independently of the other segments in the same address space; has its own memory protection attributes. A process may have separate segments for code, data, stack.

Each virtual address space is divided into fixed-size chunks called pages. The physical address space is divided into fixed-size chunks called frames. Pages have the same size as frames. The kernel maintains a page table (or page-frame table) for each process, specifying the frame within which each page is located. The CPU's memory management unit (MMU) translates virtual addresses to physical addresses on-the-fly for every memory access.

Please log in to add an answer.