Header Ads Widget

Virtual Memory

What is Virtual Memory?

Virtual memory in computer organization architecture is a technique and not actually a memory in physical form present in computer system. This is the reason it is known as virtual memory.

Virtual memory in COA is simply a technique used to provide an illusion of presence of large main memory to the programmer, when in actual it’s not present physically. 

The size of virtual memory is equivalent to the size of secondary memory. Each virtual address or logical address referenced by the CPU is mapped to a physical address in main memory. 

A hardware device called Memory Management Unit (MMU) performs this mapping during run time. To perform this activity MMU actually takes help of a memory map table, which is maintained by the operating system. 

What is logical address space and physical address space?

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. The term Logical Address Space is used for the set of all logical addresses generated by a program’s perspective. 

The hardware device called Memory-Management Unit is used for mapping logical address to its corresponding physical address.

Let's say,

Logical Address Space = 128 MB = (2 ^ 7 X 2 ^ 20) Bytes = 2 ^ 27 Bytes
Word size = 4 Bytes = 2 ^ 2 Bytes

Logical Address Space (in words) = (2 ^ 27) / (2 ^ 2) = 2 ^ 25 Words
Logical Address = 25 Bits

In general,
If, logical address space = L words
Then, Logical Address = Log2L bits

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. The term Physical Address Space is used for all physical addresses corresponding to the logical addresses in a Logical address space.  

Physical Address Space = Size of the Main Memory

If, physical address space = 64 KB = 2 ^ 6 KB = 2 ^ 6 X 2 ^ 10 Bytes = 2 ^ 16 bytes

Let us consider,
word size = 8 Bytes = 2 ^ 3 Bytes

Hence,
Physical address space (in words) = (2 ^ 16) / (2 ^ 3) = 2 ^ 13 Words

Therefore,
Physical Address = 13 bits

In General,
If, Physical Address Space = N Words

then, Physical Address = log2 N

MMU scheme

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. 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.
  5. 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).

Advantages of Virtual memory

Listed below are major advantages of using virtual memory techniques:

  • Virtual memory technique helps in efficient utilization of main memory. As larger size programs are divided into blocks and partially each block is loaded into main memory as per need. This makes simultaneous execution of multiple program possible.
  • Virtual memory helps in efficient CPU utilization
  • Virtual memory helps to improve overall throughput.

Post a Comment

0 Comments