A
Lab Project Report On
VIRTUAL MEMORY ALLOCATION
Submitted for partial fulfilment of the requirements for the award of the degree
of
BACHELOR OF TECHNOLOGY IN
COMPUTER SCIENCE AND ENGINEERING(AI&ML)
By
[Link]-24K81A66E0
Under the Guidance of
[Link]
Assistance Professor
COMPUTER SCIENCE AND
ENGINEERING(AI&ML)
St. MARTIN’S ENGINEERING COLLEGE
UGC Autonoumous
Affiliated to JNTUH, Aprroved by AICTE
Accredited by NBA &NAAC A+, ISO 9001-2008
Certified
Dhulapally, Secunderbad-500100
[Link]
[Link] ENGINEERING COLLEGE
UGC autonomous
Accredited by NBA & NAAC A+
Dhulapally,Secunderabad-500100 [Link]
CERTIFICATE
This is to certify that the project entitled “VIRTUAL MEMORY SIMULATOR” is
being submitted by [Link]-(24K81A66E0) in fulfilment of the requirements for
the award of degree of BACHELOR OF TECHNOLOGY IN COMPUTER
SCIENCE AND ENGINERING(AI&ML) is recorded of Bonafide work carried out by
[Link] result embodied in this report have been verified and found satisfactory.
Project Internal Examiner Head of Department
[Link] [Link] MAMIDISETTY
Department of CSE(AI&ML) Department of CSE(AI&ML)
St. MARTIN’S ENGINEERING COLLEGE
UGC Autonomous
Accredited by NBA & NAAC A+
Dhulapally,Secunderabad-500100 [Link]
DECLARATION
I, the student of “Bachelor of Technology in Department of COMPUTERSCIENCE
AND ENGINEERING(AI&ML)”,session:2024-2028,[Link]’s Engneering
College, Dulapally, Kompally, Secunderabad, hereby declare that the work presented
in this project work entitled “VIRTUAL MEMORY SIMULATOR” is the outcome of
my own Bonafide work and is corrected to the best of my knowledge and this work has
been undertaken taking care of Engineering Ethics. This result embodied in this project
report has not been submitted in any university for award of any degree.
ACKNOWLEDGEMENT
The satisfaction and euphoria that accompanies the successful completion of any task would
be incomplete without the mention of the people who made it possible and whose
encouragement and guidance have crowded our efforts with success. First and foremost, we
would like to express our deep sense of gratitude and indebtedness to our College
Management for their kind support and permission to use the facilities available in the
Institute.
We especially would like to express our deep sense of gratitude and indebtedness to
[Link], Group Director, St. Martin’s Engineering College Dhulapally, for
permitting us to undertake this project.
We wish to record our profound gratitude to Dr. M. SREENIVAS RAO,
Principal, St. Martin’s Engineering College, for his motivation and encouragement.
We are also thankful to [Link] MAMIDISETTY, Head of the Department,
Computer Science And Engineering(AI&ML), St. Martin’s Engineering College, Dhulapally,
Secunderabad, for his support and guidance throughout our project.
We would like to express our sincere gratitude and indebtedness to our project supervisor
Mrs,[Link], Assistant Professor, Department of Computer Science And
Engineering(AI&ML), St. Martins Engineering College, Dhulapally, for his/her support and
guidance throughout our project. Finally, we express thanks to all those who have helped us
successfully completing this project. Furthermore, we would like to thank our family and
friends for their moral support and encouragement. We express thanks to all those who have
helped us in successfully completing the project.
[Link](25K81A66E0)
CONTENTS
1 ABSTRACT
2 INTRDUCTION
3 SYSTEM ANALYSIS
4 ALGORITHM
5 SOURCE CODE
6 SYSTEM TESTING
7 OUTPUT
8 SYSTEM REQUIREMENT
Hardware Requirements
Software Requirements
9 CONCLUSION
10 FUTURE ENHANCEMENT
11 REFERENCES
ABSTRACT
Virtual memory is one of the most fundamental concepts in modern operating systems,
enabling efficient memory utilization, multitasking, and isolation between processes.
However, the internal workings of virtual memory—such as address translation, paging, and
page replacement—are often difficult for students to visualize and understand purely through
theory. To address this challenge, the Virtual Memory Simulator is designed as an
educational and analytical tool that models the complete behavior of a virtual memory
subsystem.
This simulator replicates the processes involved in translating logical addresses into physical
addresses using mechanisms such as paging and page tables. It demonstrates how the
operating system manages limited physical memory by dividing memory into fixed-size
pages and mapping them to frames. The simulator also highlights the occurrence of page
faults and how the system responds to them. By integrating multiple page replacement
algorithms—such as First-In First-Out (FIFO), Least Recently Used (LRU), and the Optimal
algorithm—the simulator allows users to compare their performance under different
workloads, memory sizes, and reference strings.
Through interactive visualization and step-by-step execution, the virtual memory simulator
provides a deeper understanding of how memory allocation decisions impact system
performance. It helps analyze important metrics including page fault rate, frame utilization,
algorithm efficiency, and overall response time. The tool serves not only as an academic
learning aid but also as a platform for experimentation, enabling users to simulate real-world
scenarios, evaluate algorithms, and observe the impact of changing system parameters.
Overall, the Virtual Memory Simulator bridges the gap between theoretical knowledge and
practical understanding of memory management in operating systems. It enhances conceptual
clarity, supports hands-on learning, and provides valuable insights into optimizing memory.
INTRODUCTION
Virtual memory is one of the most important concepts in modern operating systems, as it allows a
computer to efficiently manage limited physical memory while running multiple applications
simultaneously. Unlike traditional memory systems where programs directly access physical
RAM, virtual memory creates an illusion for each process that it has access to a large, continuous
block of memory. This is achieved by mapping virtual addresses to physical addresses using data
structures like page tables. When the required data is not available in physical memory, the
operating system retrieves it from secondary storage such as a hard disk. This mechanism ensures
efficient utilization of memory, provides process isolation, and enables systems to run large
programs even when physical RAM is limited.
A Virtual Memory Simulator is a software tool that imitates this behavior of an operating system's
memory management. Instead of relying on actual hardware, the simulator models key
components such as virtual address spaces, page tables, frames, and the process of handling page
faults. It allows users to observe how memory addressing works internally when pages are
requested by processes. The simulator also demonstrates how data is moved between physical
memory and disk, providing a clear visualization of concepts like swapping and paging. By
replicating these internal operations, the simulator acts as a comprehensive learning tool for
understanding how operating systems manage memory behind the scenes.
One of the most important features of a virtual memory simulator is its ability to implement and
compare different page replacement algorithms. In real systems, when physical memory becomes
full and a new page is needed, the operating system must decide which existing page to remove.
Algorithms such as FIFO (First-In First-Out), LRU (Least Recently Used), and Optimal
Replacement play a crucial role in determining system performance. The simulator allows users to
input a reference string and watch how each algorithm behaves, how pages are loaded into frames,
and how often page faults occur. This provides valuable insights into the efficiency of different
algorithms and helps students understand why certain strategies are preferred in real operating
system.
SYSTEM ANALYSIS
1. Introduction to System Analysis
System analysis is the process of carefully studying and understanding the
requirements, components, and behavior of a system before developing it. For the
Virtual Memory Simulator, system analysis helps in identifying how real operating
systems manage memory and how these concepts can be replicated in a simulation
environment. It involves observing the flow of data, understanding user needs,
examining system constraints, and dividing the project into clear functional modules.
Through system analysis, we gain a complete picture of how virtual memory works—
how pages are allocated, how page faults occur, how page replacement algorithms
function, and what outputs are needed for the user. This lays the foundation for
designing a simulator that is accurate, user-friendly, and efficient.
2. Existing System
In the traditional or existing system, understanding virtual memory is mostly done
through theoretical explanation in textbooks and classroom lectures. Students typically
learn concepts like paging, page tables, and page replacement only through diagrams
and mathematical examples. There is no practical tool available for many learners to
visualize how pages move in and out of memory or how different algorithms affect
performance. As a result, students often struggle to understand dynamic processes such
as page faults, memory hits, the behavior of FIFO or LRU algorithms, and how memory
frames are filled. Existing systems also lack interactive platforms that allow users to
experiment with different reference strings or frame sizes. Therefore, learning remains
passive, limited, and dependent on imagination rather than real visualization.
3. Limitations of the Existing System
The major limitation of the existing method is the absence of real-time simulation.
Without a tool, students cannot view step-by-step operations of page replacement,
making these topics difficult to grasp. Theoretical learning provides no mechanism to
test different scenarios, compare algorithms, or analyze performance changes. Another
limitation is that manual calculations are time-consuming and prone to errors,
especially when dealing with long reference strings. There is also no automated way to
display hit/miss ratios, total page faults, or memory usage patterns.
4. Proposed System
The proposed system introduces a Virtual Memory Simulator that provides an
interactive and visual representation of how memory management works. The
simulator allows users to enter a reference string, select a page replacement algorithm,
and observe how pages are placed into frames at each step. It automatically detects page
faults, performs replacements, updates the page table, and displays frame statuses
clearly. By simulating algorithms like FIFO, LRU, and Optimal, the system helps users
compare performance and understand why certain strategies are more efficient. This
proposed system eliminates manual calculations, reduces errors, and transforms
theoretical learning into practical understanding. It also makes learning engaging by
providing real-time visualization of memory behavior.
5. Advantages of the Proposed System
The proposed system is highly beneficial for learners, educators, and developers. It
offers a clear, step-by-step visualization of page replacement operations, making
complex concepts easier to understand. It improves accuracy by performing automatic
calculations and eliminates the time taken for manual work. The system also enhances
learning by allowing users to test multiple scenarios and compare algorithms. It
increases interactivity, allows performance analysis through fault count and hit ratio,
and provides hands-on experience that normal classroom learning cannot offer.
Overall, the proposed system enhances conceptual clarity and supports deeper
understanding of operating system memory management.
ALGORITHM
Step 1:
Start the program and initialize all the essential variables, data structures, and
memory components required for the virtual memory simulation. This includes
arrays or lists for frames, counters for page hits and page faults, and any additional
storage required for the selected page replacement algorithm.
Step 2:
Input the total number of frames available in the physical memory. These frames
represent the limited memory slots that can hold pages during the simulation.
Initializing this correctly is important because the number of frames directly affects
the number of page faults and overall performance.
Step 3:
Input the reference string, which contains the sequence of page numbers requested
by the process. The reference string acts as the main input for the simulator, and the
algorithm will process each page in this sequence one by one to determine whether it
results in a hit or a fault.
Step 4:
Select the page replacement algorithm to be used for the simulation. Common
options include FIFO (First-In First-Out), LRU (Least Recently Used), and Optimal
Replacement. This selection determines how the simulator decides which page
should be removed from memory when all frames are full.
Step 5:
Initialize all the frames to an empty state at the beginning of the simulation. This
means no pages are loaded into memory initially. Some simulators use special
symbols like -1 or NULL to indicate empty frames.
Step 6:
For each page in the reference string, check whether the page is already present in
any of the frames. If the page is found in memory, this is considered a page hit, and
no further action is required except updating usage information if the algorithm is
LRU.
Step 7:
If the page is not found in the frames, record this event as a page fault. Check
whether there is at least one empty frame available. If an empty frame exists, load
the new page into that frame without removing any existing page. This step also
updates the page table or tracking structure.
Step 8:
If all frames are full and the requested page is still not present, apply the selected
page replacement algorithm. The algorithm determines which existing page should
be removed from memory. For example, FIFO removes the oldest loaded page, LRU
removes the least recently used page, and Optimal removes the page that will not be
used for the longest time in the future.
Step 9:
After replacing or loading the required page, update the frame contents accordingly.
Also update counters for page hits, page faults, and any algorithm-specific data such
as timestamps, usage order, or future reference indexes. This step ensures that the
simulation accurately reflects the behavior of real virtual memory management.
Step 10:
Once all pages in the reference string have been processed, display the final results of
the simulation. This includes the total number of page faults, the number of page
hits, the hit ratio, the final state of frames, and the step-by-step visualization of how
memory changed throughout the process. These results help in analyzing the
efficiency of the chosen page replacement algorithm
SOURCE CODE
#include <stdio.h>
#include <stdbool.h>
bool isHit(int frames[], int n, int page) {
for (int i = 0; i < n; i++)
if (frames[i] == page)
return true;
return false;
}
int getOptimalIndex(int pages[], int frames[], int n, int current, int total) {
int index = -1, farthest = current;
for (int i = 0; i < n; i++) {
int j;
for (j = current; j < total; j++) {
if (frames[i] == pages[j]) {
if (j > farthest) {
farthest = j;
index = i;
}
break;
}
}
if (j == total) return i;
}
return (index == -1) ? 0 : index;
}
int getLRUIndex(int counter[], int n) {
int min = counter[0], index = 0;
for (int i = 1; i < n; i++)
if (counter[i] < min) {
min = counter[i];
index = i;
}
return index;
}
int main() {
int frames[10], counter[10], pages[50];
int n, total, choice;
int faults = 0;
printf("Enter number of frames: ");
scanf("%d", &n);
printf("Enter number of pages: ");
scanf("%d", &total);
printf("Enter reference string: ");
for (int i = 0; i < total; i++)
scanf("%d", &pages[i]);
printf("\nSelect Algorithm:\n");
printf("1. FIFO\n");
printf("2. LRU\n");
printf("3. Optimal\n");
scanf("%d", &choice);
for (int i = 0; i < n; i++)
frames[i] = -1;
int pointer = 0;
for (int i = 0; i < total; i++) {
printf("\nProcessing Page: %d\n", pages[i]);
if (!isHit(frames, n, pages[i])) {
faults++;
if (choice == 1) {
frames[pointer] = pages[i];
pointer = (pointer + 1) % n;
}
else if (choice == 2) {
int replace = getLRUIndex(counter, n);
frames[replace] = pages[i];
counter[replace] = i;
}
else if (choice == 3) {
int replace = getOptimalIndex(pages, frames, n, i+1, total);
frames[replace] = pages[i];
}
}
printf("Frames: ");
for (int j = 0; j < n; j++) {
if (frames[j] == -1) printf("- ");
else printf("%d ", frames[j]);
}
printf("\n");
}
printf("\nTotal Page Faults = %d\n", faults);
return 0;
}
SYSTEM TESTING
System testing is an essential phase in the development of the Virtual Memory Simulator, as
it ensures that the entire system functions correctly as a whole. After the individual modules
—such as page-hit detection, page-fault calculation, and algorithm execution—are developed
and unit-tested, they are integrated together and tested as one complete system. The purpose
of system testing is to verify that the simulator behaves exactly as expected under different
conditions, correctly implements the selected page replacement algorithms, and produces
accurate results for various reference strings and frame sizes. This testing phase also checks
whether the system meets all the functional and non-functional requirements identified during
system analysis.
During system testing, the simulator is executed with different sets of input data to validate
its accuracy. Multiple reference strings with varying lengths and complexity are used to
observe how the system handles page hits, page faults, and replacements. The simulator is
tested with FIFO, LRU, and Optimal algorithms to ensure that it selects the correct victim
page in every scenario. For example, FIFO should always replace the oldest page in memory,
LRU should replace the least recently used page, and Optimal should replace the page that
will not be used for the longest future time. By comparing the simulator’s output with
manually calculated results, the correctness and reliability of the system are thoroughly
validated.
Another important aspect of system testing is checking how the simulator handles boundary
conditions and unusual cases. Tests are performed for situations such as empty reference
strings, maximum frame capacity, repeated pages, very long input sequences, and reference
strings where every page is unique. These tests help ensure that the simulator does not crash,
produce incorrect outputs, or behave unpredictably. The system is also tested for stability to
ensure it can handle continuous processing without errors.
User interface testing is also part of system testing. The simulator is checked to make sure
inputs are accepted without issues, the algorithm selection works correctly, and the frame-by-
frame output is displayed clearly and consistently. The results, including total page faults and
hit ratio, must be presented in a clean and understandable format. The testing process ensures
that the user experience is smooth, the program flow is logical, and error messages—if any—
are meaningful.
Overall, system testing confirms that the Virtual Memory Simulator operates accurately,
efficiently, and reliably under all tested conditions. It ensures that the final product is ready
for educational use, providing users with the correct visualization and performance analysis
of virtual memory operations. This testing phase guarantees that the project meets its
objectives and performs successfully in real-world usage scenarios.
OUTPUT
Enter number of frames: 3
Enter number of pages: 10
Enter reference string: 7 0 1 2 0 3 0 4 2 3
Select Algorithm:
1. FIFO
2. LRU
Choice: 1
Processing Page: 7
Frames: 7 - -
Processing Page: 0
Frames: 7 0 -
Processing Page: 1
Frames: 7 0 1
Processing Page: 2
Frames: 2 0 1
Processing Page: 0
Frames: 2 0 1
Processing Page: 3
Frames: 2 3 1
Processing Page: 0
Frames: 2 3 0
Processing Page: 4
Frames: 4 3 0
Processing Page: 2
Frames: 4 2 0
Processing Page: 3
Frames: 4 2 3
Total Page Faults =
SYSTEM REQUIREMENTS
[Link] Requirements
Component Minimum Requirement Recommended
Processor (CPU) Intel/AMD 1.0 GHz Intel i3/i5 or above
RAM 1 GB 4 GB or higher
Storage 50 MB free disk space 200 MB free
Display 800 × 600 resolution Full HD
Input Devices Keyboard Keyboard & Mouse
64-bit preferred
System Type 32-bit or 64-bit
[Link] Requirements
Category Requirement
Operating System Windows / Linux / macOS
Programming Language C (GCC), or any compiler supporting standard C
Turbo C / GCC / Code::Blocks / Dev-C++ / Visual Studio
Compiler/IDE
Code
Libraries Used Standard I/O (stdio.h), basic runtime libraries
Execution Environment Terminal / Command Prompt
Simulation Tools
Any OS simulator or emulator for demonstration
(optional)
CONCLUSION
The Virtual Memory Simulator effectively demonstrates how an operating system
manages memory using techniques such as paging and page replacement algorithms.
Through this simulation, we can understand the interaction between physical memory and
virtual memory, observe how page faults occur, and evaluate the efficiency of different
page replacement policies.
The simulator provides insights into memory access patterns and helps in analyzing
system performance under various scenarios. It highlights the importance of efficient
memory management in improving system responsiveness and resource utilization.
Overall, this project reinforces key concepts of operating systems, including memory
hierarchy, demand paging, and process isolation, while offering a practical tool for
learning and experimentation. The simulator can also be extended in the future to include
more complex algorithms or larger memory configurations to further study performance
optimization.
FUTURE ENHANCEMENS
1. Incorporation of Advanced Page Replacement Algorithms: Extend the simulator to
include Least Frequently Used (LFU), Optimal, and Clock algorithms to analyze and
compare their performance in different scenarios.
2. Graphical User Interface (GUI): Develop an interactive GUI that visually represents
page tables, frame allocation, page faults, and memory access, making it easier for users
to understand memory operations.
3. Multi-Process Simulation: Enable simulation of multiple concurrent processes,
showing how virtual memory is managed for each process and how shared memory
affects page replacement.
4. Detailed Performance Metrics: Provide statistics such as hit ratio, miss ratio, page fault
rate, and memory utilization, helping in performance evaluation of different algorithms.
5. Integration of Disk/Swap Space Simulation: Simulate disk-based virtual memory
management, including swap in/out operations, to reflect real-world OS behavior more
accurately.
6. Custom Memory Access Patterns: Allow users to input custom memory reference
sequences to test and analyze how different access patterns affect performance.
7. Educational Tools & Animations: Include animations and step-by-step explanations of
memory operations, making it an effective teaching and learning tool for OS students.
REFERENCE
1. Silberschatz, A., Galvin, P. B., & Gagne, G. (2018). Operating System Concepts (10th
Edition). Wiley.
2. Tanenbaum, A. S., & Bos, H. (2015). Modern Operating Systems (4th Edition).
Pearson.
3. Stallings, W. (2018). Operating Systems: Internals and Design Principles (9th
Edition). Pearson.
4. Bovet, D. P., & Cesati, M. (2005). Understanding the Linux Kernel (3rd Edition).
O’Reilly Media.
5. Online Resources:
GeeksforGeeks: Virtual Memory in Operating Systems
TutorialsPoint: Operating System - Virtual Memory