Virtual Memory in Operating Systems | OS Tutorials YASH PAL, June 15, 2026June 15, 2026 In an operating system, virtual memory is a technique that allows the execution of processes that may not be completely in memory. It is basically a storage collection scheme in which secondary memory can be addressed as though it were part of main memory.The addresses a program may use to reference memory are distinguished from the addresses the memory system uses to identify physical storage sites, and program-generated addresses are translated automatically to the corresponding machine addresses. The size of virtual storage is limited by the addressing scheme of the computer system and by the actual number of main storage locations. Performance of virtual memory depends on the rate at which parts of a process have to be loaded into the memory from a disk.Table of Contents Virtual Memory ConceptImplementation of Virtual MemoryVirtual Memory AddressingVirtual Address SpaceAdvantages of Virtual Address SpaceVirtual Memory ConceptThe basic idea behind virtual memory is that each program has its own address space, which is broken up into chunks called pages. Each page is a contiguous range of addresses. These pages are mapped onto physical memory, but not all pages have to be in physical memory to run the program. The basis of virtual memory is the model of non-contiguous memory allocation. In the non-contiguous memory allocation model, several non-adjacent memory areas are allocated to a process.None of these areas is large enough to hold the complete process; hence, a part of the process is loaded in each of these areas. The non-contiguous memory allocation model provides advantages, such as a memory area that is not large enough to hold a complete process can still be used. So, less fragmentation results, and hence improves memory utilization. Each process is assumed to consist of parts called process components. The parts can be loaded into non-adjacent areas of memory for execution.The MMU (Memory Management Unit) translates every operand or instruction address used by a process into the address of the memory byte where the operand or instruction actually resides.Using a non-contiguous memory allocation model reduces memory fragmentation, since a free memory area can be reused even if it is not large enough to hold an entire process.The illusion of a large memory is created by enabling execution of a process whose size exceeds the size of a memory.This is achieved by keeping a process on disk and loading only the portions it requires into memory at any given time.Figure 1 shows a schematic of virtual memory.Figure 1: Overview of Virtual MemoryA process contains six components. Three of these components are presently in memory. Information about the memory areas where these components exist is maintained in a data structure of the virtual memory handler.When an instruction in the process refers to a process component that is not in memory, it is loaded from the disk.The virtual memory handler removes some process components from memory to make place for loading other components.Finally, we can define virtual memory as a memory hierarchy consisting of a computer system’s memory and a disk that enables a process to operate with only some portions of its address space in memory.Implementation of Virtual MemoryTwo fundamental approaches used to implement virtual memory are:PagingSegmentationIn Paging, each process component is called a page, while in segmentation, each process component is called a segment.Figure 2: Virtual Memory ConceptThe virtual memory systems using paging and segmentation are called a paged virtual memory system and a segmented virtual memory system.Figure 2 depicts the virtual memory concepts. The processor hardware together with the OS provides the user with a “virtual processor” that has access to virtual memory.This memory may be a linear address space or a collection of segments, which are variable-length blocks of contiguous address.Memory sharing can be achieved by overlapping portions of two virtual memory spaces.Virtual Memory AddressingFigure 3: Virtual Memory AddressingFigure 3 depicts the addressing concerns in a virtual memory scheme.Storage consists of directly addressable main memory and lower-speed auxiliary memory that is accessed indirectly by loading blocks into main memory.Address translation hardware (memory management unit) is placed between the processor and memory.If a reference is made to a virtual address which is not in real memory, then a portion of the contents of real memory is swapped out to auxiliary memory and the desired block of data is = swapped in.During this activity, the process that generated the address reference must be suspended.Virtual Address SpaceThe virtual address space of a process refers to the logical or virtual view of how a process is stored in memory.As shown in Figure 4, a process begins at a certain logical address, say, address 0, and exists in contiguous memory.Since physical memory may be organized in page frames, the physical page frames assigned to a process may not be contiguous.Hence, it is up to the memory management unit (MMU) to map logical pages to physical page frames in memory.As shown in Figure 4, the heap can be grown upward in memory, and it is used for dynamic memory allocation.Similarly, the stack can grow downward in memory through successive function calls.Large vacant space is called a hole between the heap and the stack is part of the virtual address space but will require actual physical pages only if the heap or stack grows.Virtual address space that includes holes is known as sparse address space.Using a sparse address space is beneficial because the holes can be filled as the stack or heap segments grow or if we wish to dynamically link libraries during program execution.For separating logical memory from physical memory, virtual memory also allows files and memory to be shared by two or more processes through page sharing.Figure 4: Virtual address spaceAdvantages of Virtual Address SpaceShared libraries can be shared by several processes through mapping of the shared object into a virtual address space. Each process considers the shared libraries to be part of its virtual address space.The actual pages where the libraries reside in physical memory are shared by all the processes. It is shown in Figure 5 below:Figure 5: Shared library using Virtual MemorySimilarly, virtual memory enables processes to share memory. Virtual memory allows one process to create a region of memory that it can share with another process.Virtual memory can allow pages to be shared during process creation with the fork() system call, thus speeding up process creation. engineering subjects Operating System Operating System