- OS - Home
- OS - Overview
- OS - History
- OS - Evolution
- OS - Functions
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- Process Management
- Processes in Operating System
- States of a Process
- Process Schedulers
- Process Control Block
- Operations on Processes
- Process Suspension and Process Switching
- Process States and the Machine Cycle
- Inter Process Communication (IPC)
- Context Switching
- Threads
- Types of Threading
- Multi-threading
- System Calls
- Scheduling Algorithms
- Process Scheduling
- Types of Scheduling
- Scheduling Algorithms Overview
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithm
- HRRN Scheduling Algorithm
- Priority Scheduling Algorithm
- Multilevel Queue Scheduling
- Lottery Scheduling Algorithm
- Starvation and Aging
- Turn Around Time & Waiting Time
- Burst Time in SJF Scheduling
- Process Synchronization
- Process Synchronization
- Solutions For Process Synchronization
- Hardware-Based Solution
- Software-Based Solution
- Critical Section Problem
- Critical Section Synchronization
- Mutual Exclusion Synchronization
- Mutual Exclusion Using Interrupt Disabling
- Peterson's Algorithm
- Dekker's Algorithm
- Bakery Algorithm
- Semaphores
- Binary Semaphores
- Counting Semaphores
- Mutex
- Turn Variable
- Bounded Buffer Problem
- Reader Writer Locks
- Test and Set Lock
- Monitors
- Sleep and Wake
- Race Condition
- Classical Synchronization Problems
- Dining Philosophers Problem
- Producer Consumer Problem
- Sleeping Barber Problem
- Reader Writer Problem
- OS Deadlock
- Introduction to Deadlock
- Conditions for Deadlock
- Deadlock Handling
- Deadlock Prevention
- Deadlock Avoidance (Banker's Algorithm)
- Deadlock Detection and Recovery
- Deadlock Ignorance
- Resource Allocation Graph
- Livelock
- Memory Management
- Memory Management
- Logical and Physical Address
- Contiguous Memory Allocation
- Non-Contiguous Memory Allocation
- First Fit Algorithm
- Next Fit Algorithm
- Best Fit Algorithm
- Worst Fit Algorithm
- Buffering
- Fragmentation
- Compaction
- Virtual Memory
- Segmentation
- Buddy System
- Slab Allocation
- Overlays
- Free Space Management
- Locality of Reference
- Paging and Page Replacement
- Paging
- Demand Paging
- Page Table
- Page Replacement Algorithms
- Optimal Page Replacement Algorithm
- Belady's Anomaly
- Thrashing
- Storage and File Management
- File Systems
- File Attributes
- Structures of Directory
- Linked Index Allocation
- Indexed Allocation
- Disk Scheduling Algorithms
- FCFS Disk Scheduling
- SSTF Disk Scheduling
- SCAN Disk Scheduling
- LOOK Disk Scheduling
- I/O Systems
- I/O Hardware
- I/O Software
- I/O Programmed
- I/O Interrupt-Initiated
- Direct Memory Access
- OS Types
- OS - Types
- OS - Batch Processing
- OS - Multiprocessing
- OS - Hybrid
- OS - Monolithic
- OS - Zephyr
- OS - Nix
- OS - Linux
- OS - Blackberry
- OS - Garuda
- OS - Tails
- OS - Clustered
- OS - Haiku
- OS - AIX
- OS - Solus
- OS - Tizen
- OS - Bharat
- OS - Fire
- OS - Bliss
- OS - VxWorks
- OS - Embedded
- OS - Single User
- Miscellaneous Topics
- OS - Security
- OS Questions Answers
- OS - Questions Answers
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
Operating System - Logical and Physical Address
In computers, an address is used to identify a location in the computer memory. In operating systems, there are two types of addresses, namely, logical address and physical address. A logical address is the virtual address that is generated by the CPU to access memory locations. On the other hand, a physical address is one that represents a location in the computer memory.
- Physical Address in Operating System
- Logical Address in Operating System
- Address Translation Using MMU
- Logical Address vs Physical Address
Physical Address in Operating System
The physical address of a computer program is one that represents a location in the memory unit of the computer. The physical address is the real address that is used to access data stored in the RAM (Random Access Memory) of the computer system. A group of several physical addresses is referred to as a physical address space.
The physical address is generated by the Memory Management Unit (MMU) of the computer system after translating the logical address generated by the CPU. The physical address is used by the memory controller to access the actual data stored in the RAM.
The image below shows how the logical address and physical address are used in a computer system −
Logical Address in Operating System
The logical address is a virtual address created by the CPU of the computer system. The logical address of a program is generated when the program is running. A group of several logical address is referred to a logical address space. The logical address is basically used as a reference to access the physical memory locations.
Why Logical Address is Needed?
The idea behind implementing logical address in operating systems is:
- The part of the program that is currently in use will be stored in physical memory (RAM), and the rest of the program can be stored in secondary storage (like hard disk).
- The logical address is used to access the parts of the program that are currently stored in secondary storage.
- So the logical address allows the program to use more memory than what is physically available in the RAM. This technique is known as virtual memory.
- Also, it provides an abstraction layer between the program and the physical memory.
The logical address is translated into physical address by the Memory Management Unit (MMU) of the computer system. This translation is done using a page table that maps logical addresses to physical addresses.
Address Translation Using MMU
The Memory Management Unit (MMU) is a special hardware component used for translating virtual addresses generated by the CPU into physical addresses used to access RAM. The MMU uses page tables ( along with translation lookaside buffers) to perform this mapping. A page table is a data structure that stores the mapping between virtual pages and physical frames in memory. The translation lookaside buffer (TLB) is a small cache that stores recently used page table entries.
When a logical address is generated, the MMU extracts the page number and offset from it. It then check the page table to find frame number for the corresponding page number. The frame number is combined with the offset to create the final physical address using the following formula −
$$\mathrm{\text{Physical Address} = (\text{Frame Number} \times \text{Page Size}) + \text{Offset}}$$
Where,
- Frame number is the number of the frame in physical memory where the page is stored.
- Page size is the size of each page in memory.
- Offset is the distance from the start of the page to the specific location within the page.
Example
Suppose a virtual address like 0x100000 is generated by a process. Assume that the page size is 4 KB (4096 bytes). The MMU will extract the page number and offset from the virtual address as follows:
$$\mathrm{\text{Page Number} = \frac{0x100000}{4096} = 256}$$
$$\mathrm{\text{Offset} = 0x100000 \mod 4096 = 0}$$
Now, the MMU will look up the page table to find the corresponding frame number for page number 256. Let's assume that the frame number is 512. The MMU will then calculate the physical address as follows −
$$\mathrm{\text{Physical Address} = (512 \times 4096) + 0 = 0x200000}$$
So, the virtual address 0x100000 is translated to the physical address 0x200000 using the MMU.
Note: The translation explained here is based on a simple paging mechanism. The formula and methods may vary based on the specific memory management techniques like segmentation, inverted page tables, etc.
Logical Address vs Physical Address
The following table highlights all the major differences between logical and physical address in operating system −
| Logical Address | Physical Address |
|---|---|
| This address is generated by the CPU. | This address is a location in the memory unit. |
| The address space consists of the set of all logical addresses. | This address is a set of all physical addresses that are mapped to the corresponding logical addresses. |
| These addresses are generated by CPU with reference to a specific program. | It is computed using Memory Management Unit (MMU). |
| The user has the ability to view the logical address of a program. | The user can't view the physical address of program directly. |
| The user can use the logical address in order to access the physical address. | The user can indirectly access the physical address. |
Conclusion
A physical address is a memory address that is represented in the form of a binary number on the address bus circuitry in order to enable the data bus to access a particular storage cell of main memory. A logical address, on the other hand, is a memory address that is generated by the CPU and is translated into a physical address by the MMU in order to access a specific location in the main memory.
The most significant difference between a logical address and a physical address is that the logical address is a virtual address generated by the CPU that is used to access the physical address, while a physical address is a location in the computer's memory unit.