Virtual Memory in Operating System
Virtual memory is a memory management technique used by operating
systems to give the appearance of a large, continuous block of memory to
applications, even if the physical memory (RAM) is limited and not
necessarily allocated in contiguous manner. The main idea is to divide the
process in pages, use disk space to move out the pages if space in main
memory is required and bring back the pages when needed.
Objectives of Virtual Memory
A program doesn’t need to be fully loaded in memory to run. Only the
needed parts are loaded.
Programs can be bigger than the physical memory available in the
system.
Virtual memory creates the illusion of a large memory, even if the actual
memory (RAM) is small.
It uses both RAM and disk storage to manage memory, loading only
parts of programs into RAM as needed.
This allows the system to run more programs at once and manage
memory more efficiently.
Virtual Memory
How Virtual Memory Works
Virtual memory uses both hardware and software to manage memory.
When a program runs, it uses virtual addresses (not real memory
locations).
The computer system converts these virtual addresses into physical
addresses (actual locations in RAM) while the program runs.
Types of Virtual Memory
In a computer, virtual memory is managed by the Memory Management
Unit (MMU), which is often built into the CPU. The CPU generates virtual
addresses that the MMU translates into physical addresses. There are two
main types of virtual memory:
1. Paging
2. Segmentation
1. Paging
Paging divides memory into small fixed-size blocks called pages. When the
computer runs out of RAM, pages that aren't currently in use are moved to
the hard drive, into an area called a swap file. Here,
The swap file acts as an extension of RAM.
When a page is needed again, it is swapped back into RAM, a process
known as page swapping.
This ensures that the operating system (OS) and applications have
enough memory to run.
Page Fault Service Time: The time taken to service the page fault is
called page fault service time. The page fault service time includes the time
taken to perform all the above six steps.
Let Main memory access time is: mm
Page fault service time is: ss
Page fault rate is : pp
Then, Effective memory access time = (p∗s)+(1−p)∗m(p∗s)
+(1−p)∗m
Page and Frame: Page is a fixed size block of data in virtual memory and
a frame is a fixed size block of physical memory in RAM where these
pages are loaded.
Think of a page as a piece of a puzzle (virtual memory) While, a frame
as the spot where it fits on the board (physical memory).
When a program runs its pages are mapped to available frames so the
program can run even if the program size is larger than physical
memory.
2. Segmentation
Segmentation divides virtual memory into segments of different sizes.
Segments that aren't currently needed can be moved to the hard drive.
Here,
The system uses a segment table to keep track of each segment's
status, including whether it's in memory, if it's been modified and its
physical address.
Segments are mapped into a process's address space only when
needed.
Applications of Virtual memory
Virtual memory has the following important characteristics that increase the
capabilities of the computer system.
Increased Effective Memory: It enables a computer to have more
memory than the physical memory using the disk space. This allows for
the running of larger applications.
Memory Isolation: Virtual memory allocates a unique address space to
each process, such separation increases safety and reliability based on
the fact that one process cannot interact with another.
Efficient Memory Management: Virtual memory also helps in better
utilization of the physical memories through methods that include paging
and segmentation.
Simplified Program Development: For case of programmers, they can
program ‘as if’ there is one big block of memory and this makes the
programming easier and more efficient in delivering more complex
applications.
Management of Virtual Memory
Here are 5 key points on how to manage virtual memory:
1. Adjust the Page File Size
Automatic Management: All contemporary OS including Windows
contain the auto-configuration option for the size of the empirical page
file. But depending on the size of the RAM, they are set automatically,
although the user can manually adjust the page file size if required.
Manual Configuration: For tuned up users, the setting of the custom
size can sometimes boost up the performance of the system. The initial
size is usually advised to be set to the minimum value of 1.
2. Place the Page File on a Fast Drive
SSD Placement: If this is feasible, the page file should be stored in the
SSD instead of the HDD as a storage device. It has better read and
write times and the virtual memory may prove beneficial in an SSD.
Separate Drive: Regarding systems having multiple drives involved, the
page file needs to be placed on a different drive than the OS and that
shall in turn improve its performance.
3. Monitor and Optimize Usage
Performance Monitoring: Employ the software tools used in monitoring
the performance of the system in tracking the amounts of virtual
memory.
Regular Maintenance: Make sure there is no toolbar or other
application running in the background, take time and uninstall all the tool
bars to free virtual memory.
4. Disable Virtual Memory for SSD
Sufficient RAM: If for instance your system has a big physical memory,
Example: 16GB and above then it would be advised to freeze the page
file in order to minimize SSD usage. But it should be done, carefully and
only if the additional signals that one decides to feed into his
applications should not likely use all the available RAM.
5. Optimize System Settings
System Configuration: Change some general properties of the system
concerning virtual memory efficiency. This also involves enabling
additional control options in Windows.
Regular Updates: Ensure that your drivers are run in their newest
version because new releases contain some enhancements and issues
regarding memory management.
Benefits of Using Virtual Memory
Supports Multiprogramming & Larger Programs : Virtual memory
allows multiple processes to reside in memory at once by using demand
paging. Even programs larger than physical memory can be executed
efficiently.
Maximizes Application Capacity : With virtual memory, systems
can run more applications simultaneously, including multiple large ones.
It also allows only portions of programs to be loaded at a time, improving
speed and reducing memory overhead.
Eliminates Physical Memory Limitations : There's no immediate need
to upgrade RAM as virtual memory compensates using disk space.
Boosts Security & Isolation : By isolating the memory space for each
process, virtual memory enhances system security. This prevents
interference between applications and reduces the risk of data
corruption or unauthorized access.
Improves CPU & System Performance: Virtual memory helps the
CPU by managing logical partitions and memory usage more effectively.
It allows for cost-effective, flexible resource allocation, keeping CPU
workloads optimized and ensuring smoother multitasking.
Enhances Memory Management Efficiency : Virtual
memory automates memory allocation, including moving data between
RAM and disk without user intervention. It also avoids external
fragmentation, using more of the available memory effectively and
simplifying OS-level memory management.
Limitation of Virtual Memory
Slower Performance: Virtual memory can slow down the system,
because it often needs to move data between RAM and the hard drive.
Risk of Data Loss: There is a higher risk of losing data if something
goes wrong, like a power failure or hard disk crash, while the system is
moving data between RAM and the disk.
More Complex System: Managing virtual memory makes the operating
system more complex. It has to keep track of both real memory (RAM)
and virtual memory and make sure everything is in the right place.
What is Demand Paging in Operating
System?
Last Updated : 10 Sep, 2025
Demand paging is a technique used in virtual memory systems where
pages enter main memory only when requested or needed by the CPU. OS
loads only the necessary pages of a program into memory at runtime,
instead of loading the entire program into memory at the start. Here,
A page fault occurred when the program needed to access a page that
is not currently in memory.
The operating system then loads the required pages from the disk into
memory and updates the page tables accordingly.
This process is transparent to the running program and it continues to
run as if the page had always been in memory.
Pure Demand Paging
Pure demand paging is a specific implementation of demand paging. In on-
demand paging only, no pages are initially loaded into memory when the
program starts and all pages are initially marked as being on disk.
Operating systems that use pure demand paging as a memory
management strategy do so without preloading any pages into physical
memory prior to the commencement of a task.
Demand paging loads a process's whole address space into memory
one step at a time, bringing just the parts of the process that are actively
being used into memory from disc as needed.
It is useful for executing huge programs that might not fit totally in
memory or for computers with limited physical memory.
If the program accesses a lot of pages that are not in memory right now,
it could also result in a rise in page faults and possible performance
overhead.
Operating systems frequently use caching techniques and improve page
replacement algorithms to lessen the negative effects of page faults on
system performance as a whole.
Working Process of Demand Paging
Let us understand this with the help of an example. Suppose we want to
run a process P which have four pages P0, P1, P2 and P3. Currently, in the
page table, we have pages P1 and P3.
Copy on Write
Copy on Write or simply COW is a resource management technique. One
of its main use is in the implementation of the fork system call in which it
shares the virtual memory(pages) of the OS. In UNIX like OS, fork() system
call creates a duplicate process of the parent process which is called as the
child process. The idea behind a copy-on-write is that when a parent
process creates a child process then both of these processes initially will
share the same pages in memory and these shared pages will be marked
as copy-on-write which means that if any of these processes will try to
modify the shared pages then only a copy of these pages will be created
and the modifications will be done on the copy of pages by that process
and thus not affecting the other process. Suppose, there is a process P that
reates a new process Q and then process P modifies page 3. The below
figures shows what happens before and after process P modifies page 3.
File Systems in Operating System
Last Updated : 17 Sep, 2025
File systems are a crucial part of any operating system, providing a
structured way to store, organize and manage data on storage devices
such as hard drives, SSDs and USB drives.
File System
User Application: The programs or software that request file operations
like read, write, or delete.
Logical File System: Manages metadata, file names, directories, and
access permissions.
Virtual File System (VFS): Acts as a bridge, allowing different file
systems to work under a single interface.
Physical File System: Handles the actual storage of data blocks on the
disk.
Partition 1, Partition 2, Partition 3: Divisions of the storage device
where files are stored physically.
Note: It acts as a bridge between the operating system and the physical
storage hardware, allowing users and applications to perform CRUD
Operations on files in an organized and efficient manner.
Popular File Systems
Some common types of file systems include:
FAT (File Allocation Table): An older file system used by older
versions of Windows and other operating systems.
NTFS (New Technology File System): A modern file system used by
Windows. It supports features such as file and folder permissions,
compression and encryption.
ext (Extended File System): A file system commonly used
on Linux and Unix-based operating systems.
HFS (Hierarchical File System): A file system used by macOS.
APFS (Apple File System): A new file system introduced by Apple for
their Macs and iOS devices.
Popular File Systems
The name of the file is divided into two parts as shown below:
1. Name
2. Extension, separated by a period.
Issues Handled By File System
A free space is created on the hard drive whenever a file is deleted from
it.
To reallocate them to other files, many of these spaces may need to be
recovered.
Choosing where to store the files on the hard disc is the main issue with
files one block may or may not be used to store a file.
File Directories
The collection of files is a file directory and contains information about the
files, including attributes, location, etc. Much of this information, is
managed by the operating system.
Note: The directory is itself a file, accessible by various file management
routines.
Advantages of Maintaining Directories
Efficiency: A file can be located more quickly.
Naming: It becomes convenient for users as two users can have same
name for different files or may have different name for same file.
Grouping: Logical grouping of files can be done by properties e.g. all
java programs, all games etc.
Structures of Directory
Single-Level Directory: In this, a single directory is maintained for all
the users.
Two-Level Directory: In this separate directories for each user is
maintained.
Tree-Structured Directory: The directory is maintained in the form of a
tree. Searching is efficient and also there is grouping capability. We
have absolute or relative path name for a file.
File Allocation Methods
There are several types of file allocation methods. These are mentioned
below:
Continuous Allocation
Linked Allocation(Non-contiguous allocation)
Indexed Allocation
Disk Free Space Management
To perform any of the file allocation techniques, it is necessary to know
what blocks on the disk are available. Thus to manage unallocated disk
space, two common methods are used:
Bit Tables: This uses a vector containing one bit for each block on the
disk. Each entry for a 0 corresponds to a free block and each 1
corresponds to a block in use.
Free Block List: In this method, each block is assigned a number
sequentially and the list of the numbers of all free blocks is maintained in
a reserved block of the disk.
Linked List: Free blocks are linked together in a list. Each free block
stores the address of the next free block.
Boundary Tags: Each block contains a boundary tag indicating its size
and whether it is free or occupied.
File Access Methods in OS
A file access method defines how data in a file is read, written, or modified.
The three main methods are:
1. Sequential Access
Definition: Data is accessed in order, one record after another.
Use Case: Text files, log files, audio/video streaming.
Operations: read next, write next, reset.
Advantages: Simple, efficient for large sequential reads.
Disadvantages: Slow for random access.
Diagram:
Copy code
[Record 1] → [Record 2] → [Record 3] → [Record 4] → ...
Pointer moves forward sequentially.
2. Direct (Random) Access
Definition: Data is accessed directly using a record number or byte offset.
Use Case: Databases, large binary files.
Operations: read n, write n, seek.
Advantages: Fast access to specific data.
Disadvantages: Requires fixed-length records or indexing.
Diagram:
Copy code
[Record 1] [Record 2] [Record 3] [Record 4]
↑ ↑ ↑ ↑
Access directly without reading previous records
3. Indexed Sequential Access
Definition: Combines sequential and direct access using an index table.
Use Case: Large datasets where both sequential and random access are
needed.
Operations: Search index → Jump to block → Sequential read.
Advantages: Faster search than pure sequential, supports range queries.
Disadvantages: Extra storage for index, index maintenance overhead.
Diagram:
Copy code
[Index Table] → Points to → [Data Blocks]
Key 1 → Block A → Record 1 → Record 2
Key 2 → Block B → Record 3 → Record 4
Page Replacemnet and Thrashing in Operating System
Page replacement and thrashing are closely related concepts in operating systems.
Page replacement refers to the process of replacing pages in memory with pages fr
om the disk to free up memory space for new pages. Thrashing occurs when the op
erating system spends more time swapping pages than executing processes, leadin
g to excessive page faults and a significant drop in CPU utilization. This cycle of low
CPU utilization → more processes → more page faults is called thrashing. The conc
ept of locality of reference helps explain thrashing: A locality is a set of pages that a
program actively uses together. If the number of frames allocated to a process cover
s its current locality → few page faults. If frames are fewer than the locality size → fr
equent page faults → thrashing. Thrashing happens when active localities of multiple
processes cannot fit into memory simultaneously.