0% found this document useful (0 votes)
4 views

OS assignment 3

os

Uploaded by

TUSHAR AHUJA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

OS assignment 3

os

Uploaded by

TUSHAR AHUJA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Q1.

Consider a page reference string 7, 2, 3, 1, 2, 5, 3, 4, 6, 7, 1, 0


and assume a system with four page frames using demand paging.
Using an AI/ML-enabled tool or framework (such as Python
combined with libraries like NumPy and Pandas to simulate page
replacement algorithms), determine the total number of page faults
that would occur for each of the following page replacement
algorithms: FIFO (First-In First-Out), LRU (Least Recently Used),
and Optimal Replacement. Describe how AI/ML can assist in
optimizing page replacement strategies by analyzing page access
patterns and predicting page requirements.
ANS. Page Replacement Algorithms
1. FIFO (First-In, First-Out)
FIFO is a simple page replacement algorithm that replaces the oldest page in
memory when a new page needs to be loaded, i.e., the page that has been in
memory the longest is replaced.
2. LRU (Least Recently Used)
LRU keeps track of the most recently used pages. When a page needs to be loaded,
it replaces the least recently used page, which is the one that hasn't been used for
the longest time.
3. Optimal Replacement
Optimal page replacement algorithm replaces the page that will not be used for the
longest time in the future. It is considered the best theoretical algorithm, but it
requires future knowledge of page references to work, which makes it impractical in
real-world systems. However, it is useful for comparison purposes.

Steps for Page Fault Calculation


Let's calculate the page faults for each algorithm.
FIFO Algorithm
 Start with an empty frame list.
 For each page reference in the string, check if the page is in memory (i.e., in
the frame list):
o If the page is already in memory, no page fault.
o If the page is not in memory, a page fault occurs, and the page is
added to memory.
o If the memory is full, replace the oldest page (FIFO).
LRU Algorithm
 Start with an empty frame list.
 For each page reference:
o If the page is in memory, move it to the "most recently used" position.
o If the page is not in memory:
 If memory is full, replace the least recently used page.
 If memory is not full, simply add the page.

Optimal Replacement Algorithm


 Start with an empty frame list.
 For each page reference:
o If the page is in memory, no page fault occurs.
o If the page is not in memory:
 If memory is full, replace the page that will not be needed for the
longest time in the future.
 If memory is not full, simply add the page.
Results of the Page Faults
The result from running this Python code for each algorithm would give us the total
page faults for FIFO, LRU, and Optimal.

AI/ML for Optimizing Page Replacement


AI and Machine Learning (ML) can help in optimizing page replacement strategies by
analyzing patterns in page access. Here's how:
1. Page Access Pattern Prediction: Machine learning models (like decision
trees, neural networks, or time series forecasting models) can be trained on
historical page access patterns. These models can predict which pages are
likely to be accessed next, thereby improving the page replacement decision.
2. Reinforcement Learning: Reinforcement learning (RL) algorithms could be
used to learn the optimal page replacement strategy by exploring different
actions (page replacements) and receiving rewards (based on page faults).
Over time, the RL agent would learn to make better page replacement
decisions, reducing the number of page faults.
3. Predictive Algorithms: AI models can help predict future page accesses,
allowing systems to preemptively load pages into memory, reducing the
likelihood of page faults.
4. Data-Driven Optimization: By continuously collecting data on page
accesses, an AI/ML-based approach can dynamically adjust the page
replacement algorithm based on real-time system conditions, such as memory
usage, access frequency, or workload changes.

You might also like