Home >>Operating System Tutorial >Operating System Virtual Memory

Operating System Virtual Memory

Operating System Virtual Memory

A computer can address more of the memory than the physically installed sum on the system. This extra memory is generally referred to as virtual memory and is a part of a hard disk set up to simulate the RAM of the computer.

This scheme's most visible advantage is that programmes can be larger than physical memory. Virtual memory serves two goals. Firstly, it helps one to expand the usage of physical memory by disk usage. Second, it helps us to protect memory, since every virtual address is translated into a physical address.

The situations follow when the entire programme is not required to be fully loaded into the main memory.

  • User's written error handling routines are only used when a data or computation error occurred.
  • Certain programme options and features may be rarely utilised.
  • A fixed amount of address space is assigned to several tables but only a limited amount of the table is actually used.
  • The ability to run a programme that's only partially in memory will offset several advantages.
  • The loading or swapping of each user programme into memory will require less I / Os.
  • A programme will no longer be limited by the amount of usable physical memory.
  • Each user programme may take less physical memory, more programmes may run at the same time, with a corresponding increase in use and throughput of the CPUs.

Modern, general-purpose microprocessors, a memory management unit, or MMU, are built into the hardware. The task of the MMU is to turn the virtual addresses into physical addresses. Below is a simple example –

Operating System

Virtual memory is generally implemented by request paging. It can be incorporated within a segmentation system as well. Virtual memory can also be used to provide segmentation of demand.

Demand Paging

A demand paging system is very similar to a swapping system where processes reside in secondary memory, and pages are loaded on-demand only, not before. When a context switch happens, the operating system does not copy any of the pages of the old programme to the disk or any of the pages of the new programme into the main memory. Instead, it only starts executing the new programme after loading the first page and finding the pages of the programme as referenced.

Operating System

When executing a programme, when the programme refers to a page that is not usable in the main memory because it was swapped out a little while earlier, the processor considers this invalid memory reference as a page fault and transfers control from the programme to the operating system to demand the page back into the memory.


Here are the benefits of Demand Paging −

  • Huge virtual memory.
  • More Memory Usage Effective.
  • There is no limit on multiprogramming degree.


  • Huge virtual memory.

Page Replacement Algorithm

Page replacement algorithms are the techniques that an Operating System uses to determine the memory pages to swap, to write to disk when a memory page needs to be allocated. Paging occurs when a page fault occurs and a free page cannot be used to account for allocation purposes on the basis that pages are not available or the number of free pages is smaller than the pages needed.

When the page which has been selected for replacement and has been paged out is referenced again, it must be read in from the disc and this requires completion of I / O. This method determines the quality of the page replacement algorithm: the shorter the page-in waiting time, the better the algorithm.

A page replacement algorithm looks at the limited knowledge about accessing hardware-provided pages, and tries to choose the pages should be substituted to reduce the total number of page misses while balancing them with the expense of the algorithm's own primary storage and processing time.

There are several different algorithms for replacing a page.

Reference String

The Memory Reference String is called a Reference String. Reference strings are created either artificially or by tracing a given structure and recording and memory reference address. The latter option produces large quantities of data, where two things are observed.

  • We need to remember just the page number and not the entire address for a given page size.
  • If we have a page p reference then any references to page p that follow immediately will never cause a page fault. After the first reference, page p will be in memory; the references immediately following will not be at fault.
  • Consider for instance the following address sequence − 123,215,600,1234,76,96
  • If page size is 100, then 1,2,6,12,0,0 is the reference string

First In First Out (FIFO) algorithm

  • The oldest page in main memory is the one to be chosen for replacement.
  • Simple to install, maintain a list, replace tail pages and add new pages at the head.

Optimal Page algorithm

  • An optimum algorithm for page replacement has the lowest page-fault rate of all algorithms. An optimal algorithm for page replacement exists, and is called OPT or MIN.
  • Replace the page that is not to be used for the longest time period. Use the time you want to access a page.

Least Recently Used (LRU) algorithm

  • Page that hasn't been used in main memory for the longest time is the one to be chosen for replacement.
  • Simple to introduce, maintain a list, replace pages with a look back into time.

Page Buffering algorithm

  • Keep a pool of free frames for fast start of a process.
  • Pick a page that is to be replaced on page fault.
  • Write the new page into the free pool frame, mark the table on the page and restart the process.
  • Now write the dirty page out of the disk and put the replaced page in free pool for the frame keeping.

Least frequently Used(LFU) algorithm

  • The one which will be chosen for replacement is the page with the smallest count.
  • This algorithm suffers from the situation where a page is heavily used during the initial phase of a process, but is never used again again.

Most frequently Used(MFU) algorithm

  • This algorithm is based on the argument that the page with the smallest count is likely to have only been brought in and yet to be used.

No Sidebar ads