0% found this document useful (0 votes)
5 views29 pages

Simple Page Replacement

This mini-project report titled 'SIMPLE PAGE REPLACEMENT' analyzes various page replacement algorithms in operating systems, focusing on Least Recently Used (LRU), First-In-First-Out (FIFO), and Optimal Page Replacement. The project aims to evaluate their performance, operational principles, and trade-offs in terms of page fault rates and memory utilization. By simulating these algorithms, the report seeks to provide insights into optimizing memory management and improving overall system efficiency.

Uploaded by

jeevayogi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views29 pages

Simple Page Replacement

This mini-project report titled 'SIMPLE PAGE REPLACEMENT' analyzes various page replacement algorithms in operating systems, focusing on Least Recently Used (LRU), First-In-First-Out (FIFO), and Optimal Page Replacement. The project aims to evaluate their performance, operational principles, and trade-offs in terms of page fault rates and memory utilization. By simulating these algorithms, the report seeks to provide insights into optimizing memory management and improving overall system efficiency.

Uploaded by

jeevayogi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

SIMPLE PAGE REPLACEMENT

21CSC202J - OPERATING SYSTEMS

A MINI-PROJECT REPORT

Submitted By

Jeevayogi.S[RA2311003020127]
Arjun Manish[RA2311003020126]
Clarence Jenny[RA2311003020115]

in partial fulfilment for the award of the degree


of
BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE AND ENGINEERING
of
FACULTY OF ENGINEERING AND TECHNOLOGY

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY


RAMAPURAM CAMPUS, CHENNAI-600089
OCTOBER 2024
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
(Deemed to be University U/S 3 of UGC Act, 1956)
BONAFIDE CERTIFICATE

Certified that this mini project report titled “SIMPLE PAGE


REPLACEMENT” is the bonafide work of “JEEVAYOGI.S
(RA2311003020127), ARJUN MANISH (RA2311003020126),
CLARENCE JENNY (RA2311003020115)”

SIGNATURE
Dr. C.SHANMUGANATHAN, M.E., Ph.D.,

Assistant Professor,

Computer Science and Engineering,


SRM Institute of Science and Technology,
Ramapuram Campus, Chennai.
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

RAMAPURAM, CHENNAI -600089

DECLARATION

We hereby declare that the entire work contained in this mini project report
titled “SIMPLE PAGE REPLACEMENT” has been carried out by
JEEVAYOGI.S [RA2311003020127], ARJUN MANISH
[RA2311003020126], CLARENCE JENNY [RA2311003020115] at SRM
Institute of Science and Technology, Ramapuram Campus, Chennai - 600089,

Place: Chennai

Date:
ABSTRACT

Page replacement is a critical component of memory management in


operating systems, addressing the challenge of efficiently managing
a limited amount of physical memory. When a process requires
more memory than is available, the operating system must decide
which pages to evict from memory to make space for new pages.
This paper explores simple page replacement algorithms, such as
Least Recently Used (LRU), First-In-First-Out (FIFO), and Optimal
Page Replacement. We analyze their operational principles,
performance metrics, and trade-offs in terms of page fault rates and
overhead. By providing a comparative analysis, we highlight the
strengths and weaknesses of each algorithm, illustrating their impact
on system performance under varying workloads. Understanding
these algorithms is crucial for optimizing resource utilization and
enhancing overall system efficiency in modern computing
environments.
TABLE OF CONTENTS

Chapter No. Title Page No.


ABSTRACT v
LIST OF TABLES viii
LIST OF FIGURES ix
LIST OF ABBREVIATIONS x
INTRODUCTION 1
1 1.1 Overview 1
1.2 Problem Statement 1
1.3 Objective of the Project 2
1.4 Scope of the Project 2
SOFTWARE AND HARDWARE 10
SPECIFICATIONS
2 2.1 Hardware Requirements 10
2.2 Software Requirements 10
PROJECT DESCRIPTION 12
3.1 Introduction 12
3 3.2 Architecture Diagram 13
3.3 Algorithm Used 14
3.4 Advantages of Algorithm used 16
3.5 Explanation of the Project 39
3.6 Output Results 42
3.7 Conclusion 46
APPENDIX 49
Source Code 49
LIST OF TABLES

Table No Table Name Page No.


2.1 Comparison of various models on 9
different datasets
2.1 Input Parameters 18
2.2 Spooky Author verification dataset - 18
Train
2.3 Spooky Author verification dataset - 18
Test

LIST OF FIGURES
Fig No. Figure Name Page No.
4.1 Use of RNN in the speaker 15
verification system
4.2 Use of CNN in the speaker 16
verification system
4.3 Architecture Diagram 17
4.4 Dataframe information 18
4.5 Dataset Row Counts 21
4.6 Random Seed 21
4.7 Pre-Processing of Each Word 22
4.8 Pre-Processing Architecture of Text 22
Data
4.9 Tokenization of Sentence 23
4.10 Normalization of text data 24
4.11 TF-IDF Vectorizer 25
4.12 Random Forest Hyperparameters 26
4.13 Random Forest Precision 27
4.14 Visual Representation of Random 28
Forest Classifier

LIST OF ABBREVIATIONS
CNN Convolutional Neural Network
RNN Recurrent Neural Network
NN Neural Network
ASR Automated Speech Recognition
NLTK Natural Language Toolkit
LSTM Long Short-Term Memory
GRU Gated Recurrent Unit
SV Speaker Verification
CHAPTER 1

INTRODUCTION

1.1 Overview

Page replacement is a vital aspect of memory management in


operating systems, ensuring efficient utilization of physical
memory. When a process exceeds the available memory, the
operating system must replace existing pages with new ones, a task
that can significantly affect system performance. Various algorithms
have been developed to address this challenge, each with its own
methodology and performance characteristics. Understanding these
algorithms is essential for optimizing memory usage and improving
application responsiveness.

1.2 Problem Statement

As applications become increasingly memory-intensive, the


inefficiency of page replacement algorithms can lead to higher page
fault rates, increased latency, and diminished overall system
performance. Existing page replacement strategies may not adapt
well to different workloads or usage patterns, resulting in
suboptimal memory management. Therefore, it is crucial to evaluate
and compare the effectiveness of various page replacement
algorithms to identify the most suitable approach for different
scenarios.

1.3 Aim of the Project

1
The primary aim of this project is to analyze and compare simple
page replacement algorithms, specifically Least Recently Used
(LRU), First-In-First-Out (FIFO), and Optimal Page
Replacement. The project seeks to:
1. Investigate the operational mechanisms of each algorithm.
2. Measure their performance in terms of page fault rates and
memory utilization.
3. Identify the conditions under which each algorithm performs
best.

1.4 Scope of the Project

This project will focus on the following aspects:

1. Algorithm Analysis: Detailed examination of LRU, FIFO,


and Optimal algorithms, including their theoretical
foundations and implementation details.

2. Performance Evaluation: Conduct experiments using


simulated workloads to measure and compare the performance
of each algorithm.

3. Recommendations: Provide insights on the practical


implications of using different algorithms based on workload
characteristics.

4. Limitations: Discuss the limitations of each algorithm and


suggest potential areas for future research and improvement.

2
The project will primarily target academic environments and
software development contexts where efficient memory
management is critical, thereby contributing valuable insights for
both researchers and practitioners in the field of operating systems.

CHAPTER 2

SOFTWARE AND HARDWARE SPECIFICATIONS

2.1 Hardware Requirements

 Processor:

 Minimum: Dual-core CPU (2.0 GHz or higher)

3
 Recommended: Quad-core CPU (3.0 GHz or higher)

 Memory (RAM):

 Minimum: 4 GB RAM

 Recommended: 8 GB RAM or more for better performance


during simulation.

 Storage:

 Minimum: 500 MB free disk space for software and


simulation data.

 Recommended: SSD for faster data access and improved


simulation speeds.

 Graphics:

 Basic integrated graphics sufficient; a dedicated GPU is not


essential but can enhance performance if graphical
visualization of results is included.

 Network:

 Internet connection for downloading libraries, tools, and


accessing research papers.

2.2 Software Requirements

1. Operating System:

o Windows, macOS, or Linux (any recent version).

2. Programming Language:
4
o Python (recommended) or C/C++ for implementing page
replacement algorithms.

3. Development Environment:

o An IDE or text editor (e.g., Visual Studio Code,


PyCharm, or Eclipse) for writing and debugging code.

4. Libraries/Frameworks:

o For Python: NumPy (for numerical computations) and


Matplotlib (for data visualization).

o For C/C++: Standard libraries for memory management


and data structures.

5. Simulation Tools:

o Any custom-built or existing simulation tools to model


and analyze page replacement algorithms. Alternatively,
tools like MATLAB can be used for more advanced
simulations.

6. Version Control:

o Git for tracking changes and collaborating if working in


a team.

By ensuring that these hardware and software requirements are met,


the project can be effectively developed and executed, allowing for
comprehensive analysis and evaluation of page replacement
algorithms.
5
6
CHAPTER 3

PROJECT DESCRIPTION

3.1 Introduction

In modern operating systems, effective memory management is


essential for maintaining performance and ensuring that multiple
processes can run smoothly. One of the key challenges faced by
operating systems is handling situations where the demand for
memory exceeds the available physical memory. This is managed
through a technique called paging, where the system breaks
memory into fixed-size blocks called pages. When a process
requests a page that is not currently loaded in memory, the system
generates a page fault and must decide which page in memory to
replace in order to load the new one.

The decision about which page to remove is crucial for system


efficiency, and this is where page replacement algorithms come into
play. These algorithms determine the best strategy for replacing
pages, with the goal of minimizing the number of page faults and
optimizing overall system performance. The efficiency of these
algorithms directly impacts how well an operating system manages
limited memory resources, affecting both speed and responsiveness.

In this project, we simulate four fundamental page replacement


algorithms used by operating systems: First-In-First-Out (FIFO),

7
Optimal, Least Recently Used (LRU), and Least Frequently Used
(LFU). Each algorithm follows a different approach:

 FIFO replaces the oldest page in memory.

 Optimal replaces the page that will not be used for the longest
period in the future.

 LRU replaces the page that has not been used for the longest
time.

 LFU replaces the page that has been used the least frequently.

By simulating these algorithms, we can observe how different


strategies impact memory utilization and the frequency of page
faults. Each algorithm offers its own trade-offs in terms of
complexity and efficiency, and understanding these trade-offs is
important for both system designers and developers.

This project serves as an educational tool to better understand how


operating systems manage memory under heavy demand, providing
practical insights into the role of page replacement algorithms in
optimizing system performance. Through this simulation, we will
compare the algorithms’ performance, highlight their strengths and
weaknesses, and see how they contribute to effective memory
management.

3.2 Algorithm Used

8
The project implements four fundamental page replacement
algorithms commonly used in operating systems: First-In-First-Out
(FIFO), Optimal, Least Recently Used (LRU), and Least Frequently
Used (LFU). Each of these algorithms approaches the task of
selecting which page to replace in memory in a unique way, with
varying implications on system performance, complexity, and
frequency of page faults. Below is a detailed explanation of each
algorithm:

1. First-In-First-Out (FIFO) Algorithm:

The FIFO page replacement algorithm is one of the simplest and


oldest algorithms used for managing memory. It operates on the
principle of removing the page that has been in memory the longest.
This "first in, first out" approach treats pages like items in a queue,
where the oldest page (the one loaded first) is the first to be
replaced.

 How It Works:

o When a new page needs to be loaded and memory is full,


the system selects the page that has been in memory the
longest and replaces it.

o No consideration is given to how frequently or recently


the page has been used, which can sometimes lead to
inefficiencies.

2. Optimal (OPT) Algorithm:

9
The Optimal page replacement algorithm is theoretically the best
possible algorithm, as it replaces the page that will not be needed for
the longest time in the future. However, in practice, it is not feasible
because it requires knowledge of future page requests, which is
impossible to predict. It is mainly used as a benchmark to compare
the performance of other algorithms.

 How It Works:

o For each page fault, the system scans the future sequence
of page requests and replaces the page that will not be
used for the longest duration.

3. Least Recently Used (LRU) Algorithm:

The LRU page replacement algorithm selects the page that has not
been used for the longest time. The logic behind LRU is that if a
page has not been accessed recently, it is unlikely to be used in the
near future, making it a good candidate for replacement. This
algorithm requires tracking the history of page usage, which can
introduce some computational overhead.

 How It Works:

o The system maintains a record of when each page was


last accessed.

o When a new page needs to be loaded and memory is full,


the system replaces the page that was least recently
accessed.
10
4. Least Frequently Used (LFU) Algorithm:

The LFU page replacement algorithm removes the page that has
been accessed the least frequently. The assumption here is that
pages with lower access frequency are less likely to be needed in the
future. This algorithm keeps a count of how many times each page
is accessed and selects the one with the lowest count when a
replacement is required.

 How It Works:

o The system tracks the frequency of accesses for each


page.

o When a page fault occurs and memory is full, the page


with the lowest access frequency is removed.

Advantages of Algorithm used

1. First-In-First-Out (FIFO) Algorithm:

 Advantages:

o Simple to implement.

o Requires minimal overhead for tracking page history.

 Disadvantages:

11
o Can lead to high page fault rates, especially in cases
where old pages are frequently accessed (known as the
"Belady’s Anomaly").

2. Optimal (OPT) Algorithm:

 Advantages:

o Guarantees the lowest possible number of page faults.

 Disadvantages:

o Impractical to implement in real-world systems due to


the need for future knowledge of page requests.

o Typically used only in theoretical or comparison studies.

3. Least Recently Used (LRU) Algorithm:

 Advantages:

o Generally offers better performance than FIFO because it


considers the actual usage history of pages.

o It avoids situations where frequently used pages are


removed from memory.

 Disadvantages:

o Requires additional memory and processing to track


usage history, which can slow down the system.

o More complex to implement compared to FIFO.

4. Least Frequently Used (LFU) Algorithm:


12
 Advantages:

o Effective in scenarios where certain pages are used


heavily over time and others are rarely accessed.

 Disadvantages:

o Pages that were accessed frequently in the past but are


no longer needed may still be retained, which can lead to
inefficiencies.

o It may require significant overhead for maintaining


access frequency data.

Architecture Diagram

13
RESULTS

The proposed system uses a combination of the neural networks,


particularly CNN and RNN. Then we use the multi-layer model of the neural
networks on the Spooky Author Verification Dataset. The layers used in this
multi-layer model are: Multi Head Self Attention, Transformer Block, Token,
and And Position Embedding. For a predetermined number of epochs we
trained the model. allowing the model to gradually learn and improve its
accuracy and minimizing its loss. By taking these predictions into the account
our model achieves highest accuracy averaging at 96.4%. In order to improve
representational capacities while managing network dimensionality and
utilizing less computing and training resources, a unique technique to speaker
verification has been put forth. The dconv model offers a cost-effective
solution and has the capability to extract high-resolution features during the
training process.

Output

The confusion matrix is a table that compares the estimated and actual
values with test data to show how well the classification model is
performing.It can be used to assess the system's performance in terms of
correctly identifying speakers and excluding impostors in the context of
speaker verification.

A confusion matrix for speaker verification can be created as follows:

 True Positive (TP): the quantity of instances where the system


successfully recognises a real speaker.
 False Positive (FP): how frequently a fake speaker is mistakenly
identified as a real one by the system.

14
 True Negative (TN): the quantity of instances where the system rejects
the imposter
 False Negative (FN): how many times a genuine speaker is mistakenly
rejected as a fake by the system.

Conclusion

The Simple Page Replacement Project serves as a comprehensive


exploration of memory management techniques in operating
systems, particularly focusing on page replacement algorithms.
Through the implementation and analysis of algorithms like FIFO,
LRU, and Optimal, participants gain valuable insights into how
operating systems handle memory efficiently.
It not only reinforces theoretical knowledge but also fosters
practical skills in memory management. It equips participants with a
deeper understanding of how operating systems function, preparing
them for future challenges in system design and optimization.
Through this project, learners gain a holistic view of the importance
of memory management strategies in achieving efficient and
effective computing systems

15
APPENDIX

Source Code

class PageReplacementSimulator:
def __init__(self, num_frames):
self.num_frames = num_frames
self.frames = []
self.page_faults = 0

def reset(self):
self.frames = []
self.page_faults = 0

def simulate(self, page_references, algorithm):


self.reset()
if algorithm == "FIFO":
return self.fifo(page_references)
elif algorithm == "Optimal":
return self.optimal(page_references)
elif algorithm == "LRU":
return self.lru(page_references)
elif algorithm == "LFU":
return self.lfu(page_references)
else:
raise ValueError("Unknown algorithm")

16
def fifo(self, page_references):
for page in page_references:
if page not in self.frames:
if len(self.frames) < self.num_frames:
self.frames.append(page)
else:
self.frames.pop(0)
self.frames.append(page)
self.page_faults += 1
print(f"Page: {page}, Frames: {self.frames}, Faults:
{self.page_faults}")
return self.page_faults

def optimal(self, page_references):


for i, page in enumerate(page_references):
if page not in self.frames:
if len(self.frames) < self.num_frames:
self.frames.append(page)
else:
future_pages = page_references[i+1:]
farthest_page = None
farthest_index = -1
for f in self.frames:
if f not in future_pages:
17
farthest_page = f
break
else:
index = future_pages.index(f)
if index > farthest_index:
farthest_index = index
farthest_page = f
self.frames[self.frames.index(farthest_page)] =
page
self.page_faults += 1
print(f"Page: {page}, Frames: {self.frames}, Faults:
{self.page_faults}")
return self.page_faults

def lru(self, page_references):


from collections import OrderedDict
page_order = OrderedDict()
for page in page_references:
if page not in self.frames:
if len(self.frames) < self.num_frames:
self.frames.append(page)
else:
lru_page = next(iter(page_order))
self.frames[self.frames.index(lru_page)] = page
del page_order[lru_page]
18
self.page_faults += 1
else:
del page_order[page]
page_order[page] = None
print(f"Page: {page}, Frames: {self.frames}, Faults:
{self.page_faults}")
return self.page_faults

def lfu(self, page_references):


from collections import defaultdict
page_frequency = defaultdict(int)
page_timestamp = defaultdict(int)
timestamp = 0
for page in page_references:
if page not in self.frames:
if len(self.frames) < self.num_frames:
self.frames.append(page)
else:
lfu_page = min(self.frames, key=lambda x:
(page_frequency[x], page_timestamp[x]))
self.frames[self.frames.index(lfu_page)] = page
del page_frequency[lfu_page]
del page_timestamp[lfu_page]
self.page_faults += 1
page_frequency[page] += 1
19
page_timestamp[page] = timestamp
timestamp += 1
print(f"Page: {page}, Frames: {self.frames}, Faults:
{self.page_faults}")
return self.page_faults

def get_user_input():
num_frames = int(input("Enter the number of frames: "))
reference_string = input("Enter the reference string (space-
separated integers): ")
page_references = list(map(int, reference_string.split()))
return num_frames, page_references

def main():
num_frames, page_references = get_user_input()
simulator = PageReplacementSimulator(num_frames)
algorithms = ["FIFO", "Optimal", "LRU", "LFU"]

for algorithm in algorithms:


print(f"\n{algorithm} Algorithm:")
faults = simulator.simulate(page_references, algorithm)
print(f"Total Page Faults ({algorithm}): {faults}")

if __name__ == "__main__":
main()
20
21

You might also like