What is Virtual Memory?
Virtual Memory is a memory management technique that allows the execution of processes that
may not be completely in main memory (RAM). It provides an illusion of a large, continuous
memory space to processes, even if the physical memory is smaller.
Key Points:
Virtual memory uses both RAM and a portion of the hard disk (called the swap space or
page file).
It allows larger programs to run and more processes to execute simultaneously.
Implemented using techniques like paging and segmentation.
Advantages of Virtual Memory:
1. Allows execution of large programs.
2. Enables multitasking by giving each process its own memory space.
3. Provides memory protection and isolation between processes.
4. Increases system efficiency and utilization.
Use of Demand Paging in Virtual Memory
Demand Paging is a technique used in virtual memory where pages are loaded into memory only
when they are required, not in advance.
How Demand Paging Works:
1. The process is divided into pages, and only some pages are loaded initially.
2. When a page is needed and is not in RAM, a page fault occurs.
3. The OS brings the required page from disk into RAM.
4. If RAM is full, the OS may use page replacement algorithms to decide which page to
remove.
Advantages of Demand Paging:
Efficient memory use: Only needed pages are loaded.
Faster process startup: No need to load entire process initially.
Supports large programs: Can run programs larger than physical memory.
Example:
A program needs 10 pages, but only 3 pages are frequently used.
Only those 3 are kept in RAM; others are fetched when required.
This reduces memory load and improves performance.