What is Paging in Operating System?

Paging is a fixed-sized memory allocation, storage, and management scheme.

Paging does two types of memory division:

  1. The main memory is divided into small fixed-sized blocks of physical memory which are known as Frames. The main memory can be referred to as the Collection of Frames.
  2. The logical or Secondary Memory is divided into small fixed-sized blocks which are known as Pages.
  3. Paging keeps track of all the free frames of main memory and loads the pages of secondary memory or processes for the CPU to work with.

Translation of Logical Address into Physical Address

The address generated by the CPU is not the actual address in the main memory. The address generated by the CPU is known as a Logical Address and the address of the main memory is termed a Physical Address.

The logical address generated by the CPU has two parts-

  1. Page Number: Page number contains the base address of each page present in the physical memory. Page number is denoted with p.
  2. Page Offset: Page Offset is the number of bits required to represent a word of data into the page. Page offset is denoted with d.

The Logical Address is translated into the Physical Address by MMU (Memory Management Unit). This translation of logical memory to physical memory is known as address translation. Address translation results in the actual location of the instruction present in the RAM.

The physical address has two parts-

  1. Frame Number: The page table provides the corresponding base address of the frame which is known as frame number. Frame number indicates the specific frame where the page is to be stored. The frame number is denoted with f.
  2. Page Offset: Offset is the number of words that have to be read from that page. Page offset is denoted with d.

Both offset and page numbers are used in address translation. Operating Systems also uses a data structure (page table) to track the pages.

Advantages of Paging in OS

  • Paging allows the data to be stored in a non-contiguous manner.
  • Paging helps to solve the external fragmentation issue because the frame size is the same as the page size; hence, a page can be easily loaded into a frame without any loss of data.
  • Swapping of pages is easy due to the same size.
  • Paging is also a very simple algorithm for memory management.
  • With the help of TLB cache, Paging is even faster.