what is paging

Have you ever ever considered the magic behind being able to smoothly navigate through dozens of tabs, play music and a video editing program simultaneously on your computer? Beneath this polyphany and multitasking capability is one of the most sophisticated solutions in computer science: Paging. So what then is this word we keep on hearing yet could not be fully aware of?

Paging is in simplest terms a scheme of memory management utilized by the operating system of a computer to efficiently manage the physical memory (RAM). This is one of the techniques used in the principle of virtual memory that enables a system to execute programs whose memory space is bigger than the physically available space.

Paging, Principles of Paging: Pages and Frames.

The operating system starts by dividing the logical address space of a process into a fixed size (pages) block. Likewise, the physical memory (RAM) of the computer is partitioned into blocks of equal size, which is referred to as frames. Upon a program being scheduled to execute it does not need to be loaded into the RAM as a whole. Rather, only essential pages of the program are loaded in the available frames of the physical memory.

The central part of this process is a data unit known as the Page Table. Each process has a separate page table which is maintained by the operating system. This table serves as a map, and it is used to track which virtual pages of a program are stored in which physical frames in RAM. This page table is used to convert the virtual address into a physical address when the CPU requires accessing an address.

Why Do We Need Paging? Its Advantages

These are a few convincing arguments why Paging is essential to the contemporary operating systems:

  • Effective Utilisation of Physical Memory: The physical RAM space is utilised more effectively as only parts of a program that are required are loaded rather than the entire program. This enables the execution of more programs.
  • Eliminates External Fragmentation: It avoids the issue of external fragmentation, where tiny and unusable holes of free memory are formed as processes are loaded and unloaded. Paging is more organized in the way it controls the memory space since paging operates on fixed-size blocks.
  • Allows Virtual Memory: It allows the Virtual Memory that is probably its greatest strength. Even in a situation when the memory requirement of a particular program is greater than the available physical RAM, the program can still run without any problem. The necessary pages are loaded in the RAM (small memory) used, and the pages that are not used are transferred to the disk. The process is referred to as swapping.

Quick Process startup: A program does not need to wait until all of the code has loaded into memory before the program begins running. It only takes a few initial pages to load and therefore, execution can start and thus, provide a faster user experience.

What is a Page Fault?

Now, what about an instance when the CPU needs a page that is not presently in the RAM? This process is referred to as a Page Fault. Though this may sound like a mistake, this is a natural process of how a paging system works. When a page fault occurs:

  • The operating system comes into play.
  • It finds the necessary page in the hard disk.
  • It acquires a free frame in RAM (assuming that there are no free frames, it replaces a page of empty space).
  • It retrieves the page needed in disk into the free space frame in the RAM.
  • It also updates the page table so as to reflect the new location.
  • It restarts the teaching which resulted in the fault, as though nothing had occurred.

To concisely put, the Paging of the modern day memory management is Paging which exploits the limited physical resources of our computer in a clever way to create that illusion of the infinite. Whenever you easily multi-task in using several applications, it is this brilliant system that silently and efficiently works in the background.