Logical and Physical Addresses in an Operating System
A logical address is generated by CPU while a program is running. Since a logical address does not physically exists it is also known as a virtual address. This address is used as a reference by the CPU to access the actual physical memory location.
There is a hardware device called Memory-Management Unit is used for mapping logical address to its corresponding physical address.
A physical address identifies the physical location of a specific data element in memory. The user never directly deals with the physical address but can determine the physical address by its corresponding logical address. The user program generates the logical address and believes that the program is running in this logical address space, but the program needs physical memory for its execution, therefore, the logical address must be mapped to the physical address by the MMU before the addresses are used. The term physical address space is used for all physical addresses corresponding to the logical addresses in a logical address space.
Differences Between Logical and Physical Address in Operating System
- The basic difference between Logical and physical address is that Logical address is generated by CPU in perspective of a program whereas the physical address is a location that exists in the memory unit.
- Logical Address Space is the set of all logical addresses generated by CPU for a program whereas the set of all physical address mapped to corresponding logical addresses is called Physical Address Space.
- The logical address does not exist physically in the memory whereas physical address is a location in the memory that can be accessed physically.
- Identical logical addresses are generated by Compile-time and Load time address binding methods whereas they differs from each other in run-time address binding method.
- The logical address is generated by the CPU while the program is running whereas the physical address is computed by the Memory Management Unit (MMU).
|Paramenter||LOGICAL ADDRESS||PHYSICAL ADDRESS|
|Basic||generated by CPU||location in a memory unit|
|Address Space||Logical Address Space is set of all logical addresses generated by CPU in reference to a program.||Physical Address is set of all physical addresses mapped to the corresponding logical addresses.|
|Visibility||User can view the logical address of a program.||User can never view physical address of program.|
|Generation||generated by the CPU||Computed by MMU|
|Access||The user can use the logical address to access the physical address.||The user can indirectly access physical address but not directly.|
Mapping Virtual Addresses to Physical Addresses
Memory consists of large array addresses. It is the responsibility of the CPU to fetch instruction address from the program counter. These instruction may cause loading or storing to specific memory address.
Address binding is the process of mapping from one address space to another address space. Logical addresses are generated by CPU during execution whereas physical address refers to location in a physical memory unit (the one that is loaded into memory). Note that users deal only with logical address (virtual address). The logical address is translated by the MMU. The output of this process is the appropriate physical address of the data in RAM.
An address binding can be done in three different ways:
Compile Time – If at compile time you know where a process will reside in memory then an absolute address can be generated - that is a physical address is generated in the program executable during compilation. Loading such an executable into memory is very fast. But if the generated address space is occupied by other process, then the program crashes and it becomes necessary to recompile the program to use a virtual address space.
Load time – If it is not known at the compile time where process will reside then relocatable addresses will be generated. The loader translates the relocatable address to absolute address. The base address of the process in main memory is added to all logical addresses by the loader to generate absolute address. If the base address of the process changes then we need to reload the process again.
Execution time- The instructions are already loaded into memory and are processed by the CPU. Additional memory may be allocated and/or deallocated at this time. This process is used if the process can be moved from one memory to another during execution (dynamic linking-Linking that is done during load or run time). e.g – Compaction.
MMU(Memory Management Unit)-
The run time mapping between virtual address and physical address is done by a hardware device known as MMU.
In memory management, Operating System will handle the processes and moves the processes between disk and memory for execution . It keeps the track of available and used memory.
"Logical and Physical Address in Operating System" by Ankit_Bisht, Geeks for Geeks is licensed under CC BY-SA 4.0
"Mapping Virtual Addresses to Physical Addresses" by NEERAJ NEGI, Geeks for Geeks is licensed under CC BY-SA 4.0