0% found this document useful (0 votes)
166 views3 pages

Page Replacement Algorithms

The document discusses page replacement algorithms, which determine which memory page to replace when a new page needs to be loaded into main memory. It describes three common algorithms: optimal page replacement, least recently used (LRU), and first-in first-out (FIFO). The document also discusses concepts like page faults, thrashing, demand paging, and the role of the memory management unit in translating logical to physical addresses.

Uploaded by

Lavi Kukreti
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
166 views3 pages

Page Replacement Algorithms

The document discusses page replacement algorithms, which determine which memory page to replace when a new page needs to be loaded into main memory. It describes three common algorithms: optimal page replacement, least recently used (LRU), and first-in first-out (FIFO). The document also discusses concepts like page faults, thrashing, demand paging, and the role of the memory management unit in translating logical to physical addresses.

Uploaded by

Lavi Kukreti
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

Page Replacement Algorithms

The page replacement algorithm decides which memory page is to be replaced. The process of
replacement is sometimes called swap out or write to disk. Page replacement is done when the
requested page is not found in the main memory (page fault).

There are two main aspects of virtual memory, Frame allocation and Page Replacement. It is very
important to have the optimal frame allocation and page replacement algorithm. Frame allocation is all
about how many frames are to be allocated to the process while the page replacement is all about
determining the page number which needs to be replaced in order to make space for the requested
page.

What If the algorithm is not optimal?

1. if the number of frames which are allocated to a process is not sufficient or accurate then there can
be a problem of thrashing. Due to the lack of frames, most of the pages will be residing in the main
memory and therefore more page faults will occur.

2. If the page replacement algorithm is not optimal then there will also be the problem of thrashing. If
the number of pages that are replaced by the requested pages will be referred in the near future then
there will be more number of swap-in and swap-out and therefore the OS has to perform more
replacements then usual which causes performance deficiency.

Types of Page Replacement Algorithms

There are various page replacement algorithms. Each algorithm has a different method by which the
pages can be replaced.

1. Optimal Page Replacement algorithm → this algorithms replaces the page which will not be
referred for so long in future. Although it can not be practically implementable but it can be
used as a benchmark. Other algorithms are compared to this in terms of optimality.

2. Least recent used (LRU) page replacement algorithm → this algorithm replaces the page
which has not been referred for a long time. This algorithm is just opposite to the optimal page
replacement algorithm. In this, we look at the past instead of staring at future.

3. FIFO → in this algorithm, a queue is maintained. The page which is assigned the frame first will
be replaced first. In other words, the page which resides at the rare end of the queue will be
replaced on the every page fault.
Paging with Example

In Operating Systems, Paging is a storage mechanism used to retrieve processes from the secondary
storage into the main memory in the form of pages.

One page of the process is to be stored in one of the frames of the memory. The pages can be stored
at the different locations of the memory but the priority is always to find the contiguous frames or holes.

Pages of the process are brought into the main memory only when they are required otherwise they
reside in the secondary storage.

Different operating system defines different frame sizes. The sizes of each frame must be equal.
Considering the fact that the pages are mapped to the frames in Paging, page size needs to be as same
as frame size.

There are 4 processes in the system that is P1, P2, P3 and P4 of 4 KB each. Each process is divided into
pages of 1 KB each so that one page can be stored in one frame.

Let us consider that, P2 and P4 are moved to wait instate after some time. Now, 8 frames become
empty and therefore other pages can be loaded in that empty place. The process P5 of size 8 KB (8
pages) is waiting inside the ready queue.

Given the fact that, we have 8 non contiguous frames available in the memory and paging provides the
flexibility of storing the process at the different places. Therefore, we can load the pages of process P5
in the place of P2 and P4.

Memory Management Unit

The purpose of Memory Management Unit (MMU) is to convert the logical address into the physical
address. The logical address is the address generated by the CPU for every page while the physical
address is the actual address of the frame where each page will be stored.

The logical address has two parts.

1. Page Number

2. Offset
Demand Paging

According to the concept of Virtual Memory, in order to execute some process, only a part of the process needs
to be present in the main memory which means that only a few pages will only be present in the main memory
at any time.

However, deciding, which pages need to be kept in the main memory and which need to be kept in the
secondary memory, is going to be difficult because we cannot say in advance that a process will require a
particular page at particular time.

Therefore, to overcome this problem, there is a concept called Demand Paging is introduced. It suggests keeping
all pages of the frames in the secondary memory until they are required. In other words, it says that do not load
any page in the main memory until it is required.

Whenever any page is referred for the first time in the main memory, then that page will be found in the
secondary memory.

What is a Page Fault?

If the referred page is not present in the main memory then there will be a miss and the concept is
called Page miss or page fault.

The CPU has to access the missed page from the secondary memory. If the number of page fault is very
high then the effective access time of the system will become very high.

What is Thrashing?

If the number of page faults is equal to the number of referred pages or the number of page faults are
so high so that the CPU remains busy in just reading the pages from the secondary memory then the
effective access time will be the time taken by the CPU to read one word from the secondary memory
and it will be so high. The concept is called thrashing.

If the page fault rate is PF %, the time taken in getting a page from the secondary memory and again
restarting is S (service time) and the memory access time is ma then the effective access time can be
given as;

1. EAT = PF X S + (1 - PF) X (ma)

You might also like