0% found this document useful (0 votes)
41 views6 pages

Paging

ghfghfgh

Uploaded by

rupaliroman02
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)
41 views6 pages

Paging

ghfghfgh

Uploaded by

rupaliroman02
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/ 6

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.


The main idea behind the paging is to divide each process in the form of pages. The main memory
will also be divided in the form of frames.
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.

Example
Let us consider the main memory size 16 Kb and Frame size is 1 KB therefore the main memory will
be divided into the collection of 16 frames of 1 KB each.
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.
Initially, all the frames are empty therefore pages of the processes will get stored in the contiguous
way.
Frames, pages and the mapping between the two is shown in the image below.
Let us consider that, P2 and P4 are moved to waiting state 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.
When a page is to be accessed by the CPU by using the logical address, the operating system needs to
obtain the physical address to access that page physically.
The logical address has two parts.
1. Page Number
2. Offset
Memory management unit of OS needs to convert the page number to the frame number.
Example
Considering the above image, let's say that the CPU demands 10th word of 4th page of process P3.
Since the page number 4 of process P1 gets stored at frame number 9 therefore the 10th word of 9th
frame will be returned as the physical address.
Advantages and Disadvantages of Paging
Paging in operating systems offers streamlined memory management but presents challenges like
internal fragmentation and the overhead of managing page tables. Here are some of the key
advantages and disadvantages of paging in the OS.
Advantages of Paging
 Paging offers simplified memory management so that the programs need not worry about the
physical memory addresses.
 It allows efficient memory usage.
 Aids in eliminating external fragmentation.
 Provides memory protection by preventing unauthorized access.
 The mapping between virtual and physical addresses is quite simple.
Disadvantages of Paging
 Since the pages are of fixed size, there is a possibility for internal fragmentation.
 Page table overhead arises in systems that require large memory.
 Complex page replacement.
 An additional layer of memory access is created by paging.
 Too many pages in a physical memory at the same time lead to thrashing.

Page Replacement Algorithm :


In an operating system that uses paging for memory management, a page replacement algorithm is
needed to decide which page needs to be replaced when a new page comes in. Page replacement
becomes necessary when a page fault occurs and no free page frames are in memory.
However, another page fault would arise if the replaced page is referenced again. Hence it is
important to replace a page that is not likely to be referenced in the immediate future. Before
proceeding to actual page replacement algorithms, let’s first discuss Paging and Virtual Memory.
What is Paging?
Paging is a memory management technique operating systems use operating systems to
optimize computer memory usage. It divides memory into fixed-size pages that are mapped to
physical memory frames, reducing fragmentation and improving system performance . This method
allows for more efficient use of memory, which is crucial for modern operating systems and their
ability to handle multitasking effectively.
What is Page Fault?
A page fault happens when a running program accesses a memory page that is mapped into the virtual
address space but not loaded in physical memory. Since actual physical memory is much smaller than
virtual memory, page faults happen. In case of a page fault, the Operating System might have to
replace one of the existing pages with the newly needed page. Different page replacement algorithms
suggest different ways to decide which page to replace. The target for all algorithms is to reduce the
number of page faults.
What is Virtual Memory in OS?
Virtual memory in an operating system is a memory management technique that creates an illusion
of a large block of contiguous memory for users. It uses both physical memory (RAM) and disk
storage to provide a larger virtual memory space, allowing systems to run larger applications and
handle more processes simultaneously. This helps improve system performance and multitasking
efficiency.
Understanding page replacement algorithms is critical for exams like GATE, where operating systems
are a key focus area. To deepen your knowledge and enhance your exam preparation, consider
enrolling in the GATE CS Self-Paced Course . This course provides comprehensive coverage of
operating system concepts, including detailed explanations and examples of page replacement
algorithms, helping you to excel in your exams.
Page Replacement Algorithms
Page replacement algorithms are techniques used in operating systems to
manage memory efficiently when the virtual memory is full. When a new page needs to be loaded
into physical memory , and there is no free space, these algorithms determine which existing page to
replace.
If no page frame is free, the virtual memory manager performs a page replacement operation to
replace one of the pages existing in memory with the page whose reference caused the page fault. It is
performed as follows: The virtual memory manager uses a page replacement algorithm to select one
of the pages currently in memory for replacement, accesses the page table entry of the selected page
to mark it as “not present” in memory, and initiates a page-out operation for it if the modified bit of its
page table entry indicates that it is a dirty page.
Common Page Replacement Techniques
 First In First Out (FIFO)
 Optimal Page replacement
 Least Recently Used
 Most Recently Used (MRU)
operating systems use First In First Out (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.
Example 1: Consider page reference string 1, 3, 0, 3, 5, 6, 3 with 3 page frames.Find the number of
page faults.

Initially, all slots are empty, so when 1, 3, 0 came they are allocated to the empty slots —> 3 Page
Faults.
when 3 comes, it is already in memory so —> 0 Page Faults. Then 5 comes, it is not available in
memory so it replaces the oldest page slot i.e 1. —> 1 Page Fault. 6 comes, it is also not available in
memory so it replaces the oldest page slot i.e 3 —> 1 Page Fault. Finally, when 3 come it is not
available so it replaces 0 1 page fault.
Belady’s anomaly proves that it is possible to have more page faults when increasing the number of
page frames while using the First in First Out (FIFO) page replacement algorithm. For example, if we
consider reference strings 3, 2, 1, 0, 3, 2, 4, 3, 2, 1, 0, 4, and 3 slots, we get 9 total page faults, but if
we increase slots to 4, we get 10-page faults.
Optimal Page Replacement
In this algorithm, pages are replaced which would not be used for the longest duration of time in the
future.
Example-2: Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page frame. Find
number of page fault.

Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page faults
0 is already there so —> 0 Page fault. when 3 came it will take the place of 7 because it is not used
for the longest duration of time in the future.—> 1 Page fault. 0 is already there so —> 0 Page fault.
4 will takes place of 1 —> 1 Page Fault.
Now for the further page reference string —> 0 Page fault because they are already available in the
memory.
Optimal page replacement is perfect, but not possible in practice as the operating system cannot know
future requests. The use of Optimal Page replacement is to set up a benchmark so that other
replacement algorithms can be analyzed against it.
Least Recently Used
In this algorithm, page will be replaced which is least recently used.
Example-3: Consider the page reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page frames.
Find number of page faults.

Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page faults
0 is already their so —> 0 Page fault. when 3 came it will take the place of 7 because it is least
recently used —> 1 Page fault
0 is already in memory so —> 0 Page fault .
4 will takes place of 1 —> 1 Page Fault
Now for the further page reference string —> 0 Page fault because they are already available in the
memory.
Most Recently Used (MRU)
In this algorithm, page will be replaced which has been used recently. Belady’s anomaly can occur in
this algorithm.

Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page faults
0 is already their so–> 0 page fault
when 3 comes it will take place of 0 because it is most recently used —> 1 Page fault
when 0 comes it will take place of 3 —> 1 Page fault
when 4 comes it will take place of 0 —> 1 Page fault
2 is already in memory so —> 0 Page fault
when 3 comes it will take place of 2 —> 1 Page fault
when 0 comes it will take place of 3 —> 1 Page fault
when 3 comes it will take place of 0 —> 1 Page fault
when 2 comes it will take place of 3 —> 1 Page fault
when 3 comes it will take place of 2 —> 1 Page fault

You might also like