Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
What is Logical address? 
3.
What is Physical address? 
4.
Important Points to Remember
5.
Differences between Logical Address and Physical Address
6.
What is a Memory Management Unit(MMU)? 
7.
Mapping Logical/Virtual Addresses to Physical Addresses
8.
Frequently Asked Questions 
8.1.
What is a physical address example?
8.2.
What is an example of a logical address?
8.3.
What are the 3 types of addresses in a network?
8.4.
Is IP address physical or logical?
9.
Conclusion
Last Updated: Mar 27, 2024
Easy

Difference between Logical Address and Physical Address

Crack Google SDE interview : Essential projects
Speaker
Saurav Prateek
SDE-2 @
20 Jun, 2024 @ 01:30 PM

Introduction

In a computer system, the OS and the different processes reside in the memory unit of the system. An address is used to identify a location in the memory unit uniquely.

There are two types of addresses - logical address and physical address space in OS.

Difference between logical and physical address space in os

What is Logical address? 

A logical address, in computing, refers to a virtual address that a program or process uses to reference memory locations. It is generated by the CPU (Central Processing Unit) during program execution and is translated by the memory management unit (MMU) into a physical address before accessing the actual memory.

The logical address space is the set of all addresses that a program can reference, regardless of the actual physical memory layout. It provides a layer of abstraction that allows programs to operate independently of the underlying hardware configuration.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

What is Physical address? 

A physical address, in computing, refers to the actual location of data in the computer's physical memory or RAM (Random Access Memory). Unlike logical addresses, which are used by programs to reference memory locations in an abstract manner, physical addresses directly correspond to specific locations in the computer's physical memory modules.

When a program executes and accesses memory, the CPU generates logical addresses that are translated by the memory management unit (MMU) into physical addresses before data can be read from or written to memory. This translation process involves mapping logical addresses to their corresponding physical addresses based on the memory management scheme in use, such as paging or segmentation.

Important Points to Remember

Here are some important points to remember about logical and physical addresses in computing:

Logical Address:

  1. Virtual Address Space: Logical addresses represent the virtual address space that a process sees. They are generated by the CPU during program execution.
  2. Abstraction: Logical addresses provide an abstraction layer, allowing programs to reference memory locations independently of the underlying physical memory layout.
  3. Used by Programs: Programs use logical addresses to access memory, assuming a contiguous and uniform memory space.
  4. Managed by OS: Logical address translation is managed by the operating system and the memory management unit (MMU) hardware.
  5. Allows Virtual Memory: Logical addresses facilitate the implementation of virtual memory, allowing for efficient memory management and multitasking.
     

Physical Address:

  1. Actual Memory Location: Physical addresses represent the actual location of data in the physical memory or RAM.
  2. Direct Access: Hardware components access data in memory using physical addresses.
  3. Managed by Hardware: The translation of logical addresses to physical addresses is handled by the memory management unit (MMU) hardware in conjunction with the operating system.
  4. Dependent on Hardware Configuration: Physical addresses depend on the installed hardware configuration, including the amount and layout of physical memory modules.
  5. Limited by Hardware: Physical addresses are limited by the amount of physical memory installed in the system.

Differences between Logical Address and Physical Address

The key differences between logical address and physical address are:

Logical Address

Physical Address

It is an address generated by the CPU during program execution. It refers to a physical location in the memory unit.
User programs deal with the logical address directly. The user program never sees the physical address.
The user can access the physical address using the logical address. Users cannot directly access the physical address.
The set of all logical addresses generated by a program are known as the ‘logical address space’. The set of all physical addresses are known as the 'physical address space'.
A logical address does not exist physically and is referred to as a ‘virtual address’. A physical address is a real location that exists in the memory unit.is

What is a Memory Management Unit(MMU)? 

MMU or the memory management unit is a hardware device that maps a logical address to its corresponding physical address. Many memory mapping methods can be used for this purpose of mapping.

memory management unit

Dynamic relocation using relocation register

In the above example, the mapping of logical to physical address is achieved using a simple MMU scheme known as base-register scheme.

The value of the base register or ‘relocation register’ is added with the logical address generated by the CPU. The sum of these two values is the physical address located in memory. Here the logical address ‘125’ is added with relocation register value ‘14000’ to obtain the physical address of ‘14125’. 

Therefore we have two types of addresses, logical and physical addresses.

The range of logical addresses is  0 to MAX

While the physical address range is (R+0) to (R+MAX) for a particular base value R.
You can also read about - interleave memory.

Mapping Logical/Virtual Addresses to Physical Addresses

MMU or the memory-management unit, is a hardware device that maps a logical or virtual address to its corresponding physical address.

The mapping can be done in three ways which are discussed below:

  1. Compile time: At the compile time, if it is known where the program will reside, it helps you generate the physical address. The compilation during the program execution generates the physical address
     
  2. Load time: At the compile time, if it is not known where the program will reside, it helps you generate the reallocated address, which is when the compiler converts the symbolic addresses into the relative addresses
     
  3. Run time binding: If the process can be moved from one memory to another memory during the execution, then is the runtime binding

MMU is essential for effectively managing memory addresses, which improves computer systems' flexibility and performance. Compile-time, load-time, and run-time binding are three techniques that enable dynamic adaptation to different program execution conditions, assuring optimal memory consumption.

Frequently Asked Questions 

What is a physical address example?

Physical address example: 0x0000FFFF (hexadecimal) or 65535 (decimal) - Represents a specific location in the computer's physical memory.

What is an example of a logical address?

Logical address example: 0xABCD1234 - Represents a virtual memory address generated by the CPU during program execution.

What are the 3 types of addresses in a network?

The network has three types of physical addresses: Unicast, Multicast, and Broadcast. Unicast is from one system to another system, Multicast is from one system to many systems, and the broadcast has to be received by every system in the network.

Is IP address physical or logical?

The IP address is the logical address. It is given by the software in the servers and can be changed from time to time. For Example, every time a new IP address is assigned to your laptop when you use a different hotspot.

Conclusion

In this blog, we discussed logical and physical addresses in Operating Systems. The CPU generates the logical address during program execution, and the physical address refers to an actual physical location located in the memory unit. 

If you are preparing for interviews, don’t forget to study Operating Systems - as it is one of the most asked topics in interviews.

Recommended Reading:

Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top Tech companies on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Happy Learning Ninja!

Previous article
Non-Contiguous Memory Allocation in OS
Next article
Thrashing in OS (Operating System)
Live masterclass