Professional Documents
Culture Documents
Logical and Physical Address in Operating System
Logical and Physical Address in Operating System
Logical Address is generated by CPU while a program is running. The logical address is virtual address as it does
not exist physically, therefore, it is also known as Virtual Address. This address is used as a reference to access the
physical memory location by CPU.
Physical Address identifies a physical location of required data in a memory. The user never directly deals
with the physical address but can access by its corresponding logical address.
The user program generates the logical address and thinks that the program is running in this logical
address but the program needs physical memory for its execution, therefore, the logical address must be
mapped to the physical address by MMU before they are used.
Differences Between Logical and Physical Address in Operating System
1.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.
2.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.
3.The logical address does not exist physically in the memory whereas physical address
is a location in the memory that can be accessed physically.
4.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).
Virtual Memory
• Virtual Memory is a storage scheme that provides user an illusion of having a very big
main memory. This is done by treating a part of secondary memory as the main
memory.
• In this scheme, User can load the bigger size processes than the available main
memory by having the illusion that the memory is available to load the process.
•The ability to load only the portions of processes that were actually needed ( and
only when they were needed ) has several benefits: Programs could be written for a much
larger address space ( virtual memory space ) than physically exists on the computer.
•Because each process is only using a fraction of their total address space, there is more
memory left for other programs, improving CPU utilization and system throughput.
•Less I/O is needed for swapping processes in and out of RAM, speeding things up.
• Virtual Memory is a storage allocation scheme in which secondary memory can be
addressed as though it were part of main memory.
• It is a technique that is implemented using both hardware and software. It maps
memory addresses used by a program, called virtual addresses, into physical
addresses in computer memory.
• All memory references within a process are logical addresses that are dynamically
translated into physical addresses at run time. This means that a process can be
swapped in and out of main memory such that it occupies different places in main
memory at different times during the course of execution.
• A process may be broken into number of pieces and these pieces need not be
continuously located in the main memory during execution.
• If these characteristics are present then, it is not necessary that all the pages or
segments are present in the main memory during execution. This means that the
required pages need to be loaded into memory whenever required. Virtual
memory is implemented using Demand Paging.
Advantages of Virtual Memory
1.The degree of Multiprogramming will be increased.
2.User can run large application with less real RAM.
3.There is no need to buy more memory RAMs.
Disadvantages of Virtual Memory
4.The system becomes slower since swapping takes time.
5.It takes more time in switching between applications.
6.The user will have the lesser hard disk space for its use.
Definition of Paging
Paging is a memory management scheme. Paging allows a process to be stored in a memory
in a non-contiguous manner. Storing process in a non-contiguous manner solves the problem
of external fragmentation.
For implementing paging the physical and logical memory spaces are divided into the same
fixed-sized blocks. These fixed-sized blocks of physical memory are called frames, and the fixed-
sized blocks of logical memory are called pages.
When a process needs to be executed the process pages from logical memory space are
loaded into the frames of physical memory address space. Now the address generated
by CPU for accessing the frame is divided into two parts i.e. page number and page offset.
Page 1 frame1
Page 2 Frame 2
Page 3
frame 6
•Consider the following micro example, in which a process has 16 bytes of logical memory, mapped in 4 byte pages into
32 bytes of physical memory. ( Presumably some other processes would be consuming the remaining 16 bytes of physical
memory. )
•A logical address consists of two parts: A page number in which the address resides, and an offset from
the beginning of that page. ( The number of bits in the page number limits how many pages a single
process can address. The number of bits in the offset determines the maximum size of each page, and
should correspond to the system frame size. )
•The page table maps the page number to a frame number, to yield a physical address which also has two
parts: The frame number and the offset within that frame. The number of bits in the frame number
determines how many frames the system can address, and the number of bits in the offset determines the
size of each frame.
Demand Paging
•The basic idea behind demand paging is that when a process is swapped in, its pages are not swapped in all at once.
Rather they are swapped in only when the process needs them. ( on demand. ) This is termed a lazy swapper,
Paging Advantages
•On the programmer level, paging is a transparent function and does not require intervention.
•No external fragmentation.
•No internal fragmentation on updated OS’s.
•Frames do not have to be contiguous.
Paging Disadvantages
•Paging causes internal fragmentation on older systems.
•Longer memory lookup times than segmentation;
•Segmentation Advantages
•No internal fragmentation.
•Segment tables consumes less space compared to page tables.
•Average segment sizes are larger than most page sizes, which allows segments to store more process data.
•Less processing overhead.
•Simpler to relocate segments than to relocate contiguous address spaces on disk.
•Segment tables are smaller than page tables, and takes up less memory.
Segmentation Disadvantages
•Uses legacy technology in x86-64 servers.
•Linux only supports segmentation in 80x86 microprocessors: states that paging simplifies memory management by using the same set of linear
addresses.
•Porting Linux to different architectures is problematic because of limited segmentation support.
•Requires programmer intervention.
•Subject to serious external fragmentation.
Key Differences: Paging and Segmentation
Size:
•Paging: Fixed block size for pages and frames. Computer hardware determines page/frame sizes.
•Segmentation: Variable size segments are user-specified.
Fragmentation:
•Paging: Older systems were subject to internal fragmentation by not allocating entire pages to memory. Modern OS’s
no longer have this problem.
•Segmentation: Segmentation leads to external fragmentation.
Tables:
•Paging: Page tables direct the MMU to page location and status. This is a slower process than segmentation tables
•Segmentation: Segmentation tables contain segment ID and information, and are faster than direct paging table
lookups.
Availability:
Consider a reference string: 4, 7, 6, 1, 7, 6, 1, 2, 7, 2. the number of frames in the memory is 3. Find out the number of
page faults respective to:
FIFO
•Advantages –
• It is simple and easy to understand & implement.
•Disadvantages –
• The process effectiveness is low.
• When we increase the number of frames while using FIFO, we are giving more memory to processes.
So, page fault should decrease, but here the page faults are increasing. This problem is called as
Belady’s Anomaly.
• Every frame needs to be taken account off.
https://www.youtube.com/watch?v=l7HoguhFVQ4