Page Table and Mapping

The page table is a data structure used by a virtual memory in a computer OS to store the mapping between virtual addresses and physical addresses.

It maps the page number to its frame number where that particular page is stored. CPU generates the logical address of the page, but the main memory recognizes the Physical address. Then, the Page Table maps the logical address to the Physical address.

Main characteristics of page Table

  • When a process is loaded to execute, then its page table is also loaded in the main memory. The page table contains the information about every entry of the page, which is loaded into the frame of main memory.
  • The size of the page table varies from process to process. Having more entries in the page table will increase the size and vice versa.
  • The page size of the process is always equal to the frame size of the main memory. If the page size is 2Bytes, the frame size is also 2Bytes because pages are loaded into frames of main memory.
  • Each process has its unique independent table.

The greater the number of entries in the page table of a process, the higher the size of the page table. If the page table size is greater than the frame size of the main memory, then Multi-level paging comes into the picture. Look at a diagram of the page table given below for more details.

Page table in operating system

Logical to Physical Address mapping through Page Table

There are four main steps for mapping the logical to physical address through the page table.

1. Generation of logical address

CPU creates a logical address for each page of the process. This created address holds two things:

  • page number: it tells the required page of process
  • offset: it tells the specific byte from that page

2. Scaling

CPU uses the page table base register to store the base address of the page table. The value of the page table base register is added to the page number so that the actual location of that page in the page table can be obtained.

3. Generation of Physical Address

When the required page is found in the page table, then its corresponding value, which is the frame number, is easily obtained. It is the physical address because it is the address of the main memory where the actual data is present.

The physical address also has two parts

  • The frame number is the address of the main memory where the CPU request page is present.
  • Offset: The offset of the logical address is similar to the offset of the physical address. So, it will copy from the logical address to the physical address.

4. Getting Actual Frame Number

The frame number and offset of the physical address are mapped to the main memory so that the actual byte or word address can be accessed.

Let’s explain Page Table and Mapping with an example.

Let processes P1 and P2 have the size 10Bytes and 8Bytes, respectively, and exist in secondary memory. There are 5 pages of process 1 and 4 pages of process 2, but each page is 2 bytes in size. Suppose 4 pages of process 1 and 4 pages of process 2 exist in the main memory. But the page table contains the whole record of its pages whether they are loaded in main memory or not. Suppose the CPU request for the 2nd byte of the 5th page of process 1 exists in the main memory. Then the explanation with diagram is.

Mapping through page table in operating system

Step 1: Generation of Logical address:

1001 is the Logical address where page No is 100 and 1 is offset.

Step 2: Scaling

Base address registers value 000 because page table base register value is 000.

By adding of page no and page table base register, the result is 100. Then 100 is the CPU required page.

Step 3: Generation of Physical address

The corresponding frame of page 100 is 01001.

Copy the offset of the logical address and add it to frame no. Then, the result is 010011. So, 010011 is the required frame number in the main memory.

Step 4: Getting actual page no.

So, 010011 is the actual physical address where the data of the required page is present. Now, the CPU can get the required data quickly.

In the very next lectures, we will see the page table entries.