0% found this document useful (0 votes)
22 views4 pages

lp1 Assigment4

Uploaded by

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

lp1 Assigment4

Uploaded by

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

Assignment No.

:4

Problem Statement:

Write a Java Program (using OOP features) to implement paging simulation using

1. FIFO

2. Least Recently Used (LRU)

3. Optimal algorithm

Objectives:

1. To study page replacement policies to understand memory management. 2. To understand


efficient frame management using replacement policies.

Theory:

CONCEPT OF PAGE REPLACEMENT:

1. Page Fault: Absence of page when referenced in main memory during paging leads to a page
fault.

2. Page Replacement: Replacement of already existing page from main memory by the required new
page is called as page replacement. And the techniques used for it are called as page replacement
algorithms.

NEED OF PAGE REPLACEMENT:

Page replacement is used primarily for the virtual memory management because in virtual memory
paging system principal issue is replacement i.e. which page is to be removed so as to bring in the
new page, thus the use of the page replacement algorithms. Demand paging is the technique used
to increase system throughput. To implement demand paging page replacement is primary
requirement. If a system has better page replacement technique it improves demand paging which
in turn drastically yields system performance gains.

PAGE REPLACEMENT POLICIES:

1. Determine which page to be removed from main memory.

2. Find a free frame.

1) If a frame is found use it

2) if no free frame found, use page replacement algorithm to select a victim frame.

3) Write the victim page to the disk.

3. Read the desired page into the new free frame, change the page and frame tables. 4. Restart the
user process.
PAGE REPLACEMENT ALGORITHMS:

1. FIFO

This is the simplest page replacement algorithm. In this algorithm, the operating system keeps track
of all pages in the memory in a queue, the oldest page is in the front of the queue. When a page
needs to be replaced page in the front of the queue is selected for removal.

2. OPTIMAL PAGE REPLACEMENT ALGORITHM:

Replace the page that will not be used for longest period of time as compared to the other pages in
main memory. An optimal page replacement algorithm has lowest page fault rate of all algorithm. It
is called as OPT or MIN.

ADVANTAGE:

1) This algorithm guarantees the lowest possible page-fault rate for a fixed no. of frames.

DISADVANTAGE:

1) The optimal page replacement algorithm is very difficult to implement, as it requires the
knowledge of reference strings i.e. strings of memory references

. 3. LEAST RECENTLY USED (LRU):

LRU algorithm uses the time of the page’s last usage. It uses the recent past as an approximation of
the near future, then we can replace the page that has not been used for the longest period of the
time i.e. the page having larger idle time is replaced.

ADVANTAGE:

1) The LRU policy is often used for page replacement and is considered to be good.

DISADVANTAGES:

1) It is very difficult to implement.

2) Requires substantial hardware assistance.

3) The problematic determination of the order for the frames defined by the time of last usage

Algorithm/Flowchart:

1. FIFO :

1. Start the process

2. Read number of pages n

3. Read number of pages no

4. Read page numbers into an array a[i]

5. Initialize avail[i]=0 .to check page hit


6. Replace the page with circular queue, while re-placing check page availability in the frame Place
avail[i]=1 if page is placed in the frame Count page faults

7. Print the results.

8. Stop the process.

2. LEAST RECENTLY USED

1.Start the process

2. Declare the size

3. Get the number of pages to be inserted

4. Get the value

5. Declare counter and stack

6. Select the least recently used page by counter value

7. Stack them according the selection.

8. Display the values

9. Stop the process

3. OPTIMAL ALGORTHIM:

1. Start Program

2. Read Number Of Pages And Frames

3.Read Each Page Value

4. Search For Page In The Frames

5. If Not Available Allocate Free Frame

6. If No Frames Is Free Replace The Page With The Page That Is Least Used 7.Print Page Number Of
Page Faults

8.Stop process.

Input:

1. Number of frames

2. Number of pages

3. Page sequence

Output:

1. Sequence of allocation of pages in frames (for each algorithm)

2. Cache hit and cache miss ratio.

Test Cases:

1. Test the page hit and miss ratio for different size of page frames.
2. Test the page hit and miss ratio for both algorithms with different page sequences.

Software Requirement:

1. Fedora

2. Eclipse

3. JDK

Hardware Requirement:

Conclusion: Successfully implemented all page replacement policies.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy