Home >>Operating System Tutorial >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.
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 –
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.
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.
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 −
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.
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.