Paging in operating system is a memory management technique that allows the system to allot non-contiguous physical address space to a process. The concept the paging resolves the problem of external fragmentation that occurs due to the continuous allocation of physical address space to processes.
Because of external fragmentation, though enough memory is available to allocate to a process but it is not in a contiguous manner. Thus, the concept of paging allows the system to allocate non-contiguous memory space to the processes. Let’s discuss the concept of paging in detail.
Paging in Operating System
What is Paging?
Paging is a memory management technique that helps in accomplishing the concept of virtual memory. Paging eliminates the need for continuous memory space by dividing the long process into pages. Further, the operating system divides the main memory into frames. The size of frames is equal to the size of pages.
Now whenever we have to execute the process, one page of the process is placed in one frame of the memory. The required pages of the process can be placed at frames present at the different memory locations of the main memory.
Although, at first the operating system tries to find the contiguous memory location so that contiguous frames can be allotted to the process. But if the contiguous frames are not available then pages are placed at the frames present at the different memory locations.
Also, only those pages of the processes are brought to the main memory that is required for the smooth execution of the processes, instead of placing all the pages of the process at once in the main memory. This helps the operating system in creating a multiprogramming environment.
Use of Paging in Operating System
Paging is useful when the system has to execute several programs simultaneously. And does not have enough main memory to store them.
How Does Paging Works?
Paging divides the main memory into fixed-size blocks that we refer to as frames. And the program is divided into blocks of the same size as frames and we refer to them as pages.
When the system has to execute a process, it loads the pages of the program into available frames of main memory. Now to start the execution of a process CPU generates a logical address. The logical address includes page number (p) and page offset (d).
The system uses the page number as an index to trace the page table which has the base address of each page in the main memory i.e., frame (f). The base address (f) is then combined with the page offset (d) to compute the page’s physical address in the block of the main memory.
The image below shows the working of the paging in the operating system.
Advantages of Paging
- Paging enables the system to allocate non-contiguous memory space to the process.
- As pages and frames are of equal size swapping between them becomes very easy.
- Paging supports the concept of virtual memory.
- Paging is helpful when we have limited main memory.
- With the concept of paging, we do not require external fragmentation.
Disadvantages of Paging
- Paging leads to internal fragmentation.
- The system has to maintain a page table that helps in translating the logical address provided by the CPU into the physical address where the page is stored. But the page tables consume additional space in the system.
- To access the pages from the frames (main memory) the system has to first access the page table which ultimately increases the memory access time.
- For each process, the system needs to maintain a separate page table.
The concept of paging is close from an operating system point of view. As it is difficult for the users or programmers to view their programs as blocks of fixed-size frames. So, there is another concept that supports the virtual memory technique i.e., Segmentation.
In segmentation, the system divides a program into segments on the basis of its functional components. Like a segment that has the main () function, and another segment that has stack memory requirements of the program.