Paging
Paging
5 February, 2025
Non-Contiguous Memory Allocation
Non-contiguous memory allocation is a memory allocation technique.
It allows to store parts of a single process in a non-contiguous fashion.
Thus, different parts of the same process can be stored at different places in
the main memory.
There are two popular techniques used for non-contiguous memory allocation :
1. Paging
2. Segmentation
Paging
Paging is a fixed size partitioning scheme.
In paging, secondary memory and main memory are divided into equal fixed
size partitions.
The partitions of secondary memory are called as pages.
The partitions of main memory are called as frames.
Each process is divided into parts where size of each part is same as page size.
The size of the last part may be less than the page size.
The pages of process are stored in the frames of main memory depending
upon their availability.
Translating Logical Address into Physical Address
CPU always generates a logical address.
A physical address is needed to access the main memory.
Following steps are followed to translate logical address into physical address-
Step-01:
Page Number specifies the specific page of the process from which CPU wants to read the data.
Page Offset specifies the specific word on the page that CPU wants to read.
Step-02:
Step-03:
The frame number combined with the page offset forms the required physical
address.
Frame number specifies the specific frame where the required page is stored.
Page Offset specifies the specific word that has to be read from that page.
The advantages of paging are-
It allows to store parts of a single process in a non-contiguous fashion.
It solves the problem of external fragmentation.
Page Cleanup: When a process terminates, the operating system frees the
memory allocated to the process and cleans up the corresponding entries in
the page tables.
A page replacement algorithm is used only when memory is full and a new page needs to be
loaded. The OS must replace an existing page using algorithms like:
FIFO (First-In-First-Out): Replaces the oldest page in memory with a new one. It’s simple but
can cause issues if pages are frequently swapped in and out, leading to thrashing.
LRU (Least Recently Used): Replaces the page that hasn’t been used for the longest time. It
reduces thrashing more effectively than FIFO but is more complex to implement.
Optimal Page Replacement is one of the Algorithms of Page Replacement. In this algorithm,
pages are replaced which would not be used for the longest duration of time in the future.
Hit Ratio = Number of page hits / Total number of pages = 8/20 = 0.4
Miss Ratio = Number of page miss / Total number of pages = 12/20 = 0.6
Numerical of LRU
Consider the reference string 1, 2, 3, 4, 5, 1, 3, 1, 6, 3, 2, 3, for a memory with four
frames and calculate number of page faults by using LRU Page replacement
algorithms. Also calculate Hit ratio and miss ratio
Total Page Fault = 8
Total Page Hit = 4
Hit Ratio = Number of page hits / Total number of pages = 8/12 = 0.67
Miss Ratio = Number of page miss / Total number of pages = 4/12 = 0.33
Numerical of Optimal