Introduction to Memory management and virtual memory

Operating System reside in part of memory and rest is used by multiple processes. A process needs some memory to store its variable and code. Operating system must manages memory location, either allocated or free. The efficient utilization of memory by minimizing internal and external fragmentation is the goal of memory management and it’s functionality is the allocating and deallocating memory to processes.


Main Memory refers to a physical memory that is the internal memory of the computer. The word main is used to distinguish it from external mass storage devices such as disk drives. Main memory is also known as RAM. The computer is able to change only data that is in main memory. Therefore, every program we execute and every file we access must be copied from a storage device into main memory.

All the programs are loaded in the main memeory for execution. Sometimes the complete program is loaded into the memory, but some times a certain part or routine of the program is loaded into the main memory only when it is called by the program, this mechanism is called Dynamic Loading, this enhances the performance.

Also, at times one program is dependent on some other program. In such a case, rather than loading all the dependent programs, CPU links the dependent programs to the main executing program when its required. This mechanism is known as Dynamic Linking.


Virtual Memory

Virtual Memory is a space where large programs can store themselves in form of pages while their execution and only the required pages or portions of processes are loaded into the main memory. This technique is useful as large virtual memory is provided for user programs when a very small physical memory is there.

In real scenarios, most processes never need all their pages at once, for following reasons :

  • Error handling code is not needed unless that specific error occurs, some of which are quite rare.
  • Arrays are often over-sized for worst-case scenarios, and only a small fraction of the arrays are actually used in practice.
  • Certain features of certain programs are rarely used.


Benefits of having Virtual Memory :

  1. Large programs can be written, as virtual space available is huge compared to physical memory.
  2. Less I/O required, leads to faster and easy swapping of processes.
  3. More physical memory available, as programs are stored on virtual memory, so they occupy very less space on actual physical memory.

Logical vs physical address space

The address generated by CPU is called logical (or virtual) address space. Processes are always uses virtual address space and they do not see physical address. Logical address space is set of logical addresses that generated by a program.

The physical address is address that seen by memory unit and used to access memory units. Virtual addresses are mapped with physical addresses by memory management unit.




Objective and Functions of MMU:

  • Memory management unit (MMU) is a hardware device that maps virtual addresses to physical addresses.
  • The functions of the memory management unit is raising exception when necessary, protection and translation of virtual to physical addresses. Operating system handles memory management unit




What to read next

Please Go through all these linksW3Schools – HTML Tutorial

DefinitionFiber optics is the technology used to transmit information as pulses of light through strands of fiber made of glass or plastic over long