Operating Systems · Virtual Memory and Page Replacement
Concept of Virtual Memory and Partial Loading of Process
Overview
Virtual memory lets a process run without being fully present in main memory: only part of it is loaded, and the process still executes.
It matters because it allows programs larger than physical memory to run, and it lets more processes share memory at once, raising CPU utilization.
Key concepts
- Virtual memory: the technique of running a process without having the complete process in main memory; only a partial amount of the process is kept in main memory at any time, and the process can still execute.
- Formal statement: whenever the size of the process is larger than the size of the main memory, only a partial amount of the process is placed in the main memory, and the process is still able to run — this is called virtual memory.
- Partial loading: the part of the process kept in memory is not fixed; the operating system keeps swapping the needed parts in and out.
Part of the process in main memory — not the entire process — is enough to start and continue running. - OS-implemented: the mechanism is implemented inside the operating system, so the user/programmer does not have to manage it.
- Programmer's illusion: the programmer need not know about virtual memory and does not manage it; the programmer gets the illusion that a lot of memory is available — possibly infinite memory — and can write a program of any length.
- Original purpose: proposed initially to handle cases where the size of the process is very much higher than the size of the available memory.
- Later purpose: modern machines have very large RAM (even a small mobile phone may have several GB of RAM) and main memory sizes keep increasing, so main memory can be larger than the process size.
Virtual memory is still implemented because at any instant only part of each process is loaded into main memory, so as many processes as possible can be inside main memory at the same time. - Benefit: the degree of multiprogramming increases, and therefore CPU utilization increases.
- Scope: virtual memory is used whether the process size is bigger than main memory or smaller than main memory; in both cases many processes can be present in main memory simultaneously, giving a higher degree of multiprogramming and higher CPU utilization.

How it works
- The problem that forces virtual memory: suppose the physical (main) memory is only 128 KB but the process (logical address space) size is 256 MB. The process cannot be placed completely in main memory, and if the whole process had to be resident before running, this program could never run at all.
Hence the concept of virtual memory comes into the picture. - The key observation: at any point of time, only a part of the process is actually required for execution — not the entire process. So take a part of the process, load it into memory, and run it; this is exactly virtual memory.
- Implementation: the operating system implements virtual memory; the programmer need not know about it and does not manage it.
The programmer gets the illusion that a lot of memory (possibly infinite memory) is available and can write a program of any length.
The operating system takes care of the limitation: if the physical memory is less than the memory the process needs, the OS applies the virtual memory concept. - Modern use: even when main memory is larger than the process, only part of each process is loaded at any instant, so as many processes as possible fit in main memory, increasing the degree of multiprogramming and CPU utilization.
Worked examples
Process larger than main memory: physical (main) memory is 128 KB, process (logical address space) size is 256 MB. The process cannot be placed completely in main memory. Only a part of the process is loaded and the process runs; the operating system swaps needed parts in and out as execution proceeds.
Comparison
| Point | Overlays | Virtual memory |
|---|---|---|
| Who manages it | The user (the programmer) | The operating system |
| Programmer awareness | Programmer must know and handle it | Programmer need not know about it |
| Illusion provided | None — programmer does the loading decisions | Programmer gets the illusion of (almost) infinite memory and can write a program of any length |
| Scope | Only when process does not fit | Used whether or not the process fits in main memory |
Revision summary
- Virtual memory = partial loading of a process: only a part of the process is in main memory, and the process still runs.
- It is needed when process size > main memory size (example: physical memory 128 KB, process size 256 MB).
- Justification: only a part of the process is needed at any instant of time.
- It is implemented by the operating system, not by the user (unlike overlays); the programmer is unaware and sees abundant memory.
- A second, modern reason for its use: even when processes fit in memory, keeping only parts of many processes in memory increases the degree of multiprogramming, which increases CPU utilization.
- Virtual memory applies in both cases — process bigger than memory, or process smaller than memory.
Previous-year exam insights
- Virtual memory requires hardware support (MMU with page tables/TLB) plus OS support; it is not merely a software trick, and it does not remove the need for memory-management hardware even when virtual and physical address spaces are the same size.
Asked inGATE 2006 - Swap space resides on disk (secondary storage) and is used to hold process data (pages/segments) that are swapped out of main memory; the amount of virtual memory usable is limited by the available secondary storage (swap space).
Asked inGATE 2005GATE 2001GATE 1991 - The minimum number of page frames that must be allocated to a running process is determined by the instruction set architecture (the maximum number of distinct pages a single instruction can reference), not by page size or physical memory size.
Asked inGATE 2004UGC NET 2019 - Advantages of virtual memory include: programs can exceed the size of physical memory, each process gets a protected address space, and the linker/loader can assign addresses independent of physical placement; a disadvantage is that it causes more I/O (paging/swapping) and is not faster on average.
Asked inGATE 1999UGC NET 2017 - In a virtual memory system the virtual address space is determined by the width of the CPU's address (virtual address) lines; it is typically larger than the physical memory size, and it is not constrained to be smaller than the secondary storage, although only as much of it as the swap space/backing store can hold can be actively used.
Asked inGATE 1995 - Virtual memory is associated with the memory component (virtual address space), the file system with disk, threads with CPU, and signals with interrupts, when matching system components to their abstractions.
Asked inUGC NET 2019