Tag: Memory Management of OS

Page Table | Paging in Operating System

Paging in OS-

 

Before you go through this article, make sure that you have gone through the previous article on Paging in OS.

 

We have discussed-

  • Paging is a non-contiguous memory allocation technique.
  • The logical address generated by the CPU is translated into the physical address using the page table.

 

In this article, we will discuss about Page Table.

 

Page Table-

 

  • Page table is a data structure.
  • It maps the page number referenced by the CPU to the frame number where that page is stored.

 

Characteristics-

 

  • Page table is stored in the main memory.
  • Number of entries in a page table = Number of pages in which the process is divided.
  • Page Table Base Register (PTBR) contains the base address of page table.
  • Each process has its own independent page table.

 

Working-

 

 

  • Page Table Base Register (PTBR) provides the base address of the page table.
  • The base address of the page table is added with the page number referenced by the CPU.
  • It gives the entry of the page table containing the frame number where the referenced page is stored.

 

Page Table Entry-

 

  • A page table entry contains several information about the page.
  • The information contained in the page table entry varies from operating system to operating system.
  • The most important information in a page table entry is frame number.

 

In general, each entry of a page table contains the following information-

 

 

1. Frame Number-

 

  • Frame number specifies the frame where the page is stored in the main memory.
  • The number of bits in frame number depends on the number of frames in the main memory.

 

2. Present / Absent Bit-

 

  • This bit is also sometimes called as valid / invalid bit.
  • This bit specifies whether that page is present in the main memory or not.
  • If the page is not present in the main memory, then this bit is set to 0 otherwise set to 1.

 

NOTE

  • If the required page is not present in the main memory, then it is called as Page Fault.
  • A page fault requires page initialization.
  • The required page has to be initialized (fetched) from the secondary memory and brought into the main memory.

 

3. Protection Bit-

 

  • This bit is also sometimes called as “Read / Write bit“.
  • This bit is concerned with the page protection.
  • It specifies the permission to perform read and write operation on the page.
  • If only read operation is allowed to be performed and no writing is allowed, then this bit is set to 0.
  • If both read and write operation are allowed to be performed, then this bit is set to 1.

 

4. Reference Bit-

 

  • Reference bit specifies whether that page has been referenced in the last clock cycle or not.
  • If the page has been referenced recently, then this bit is set to 1 otherwise set to 0.

 

NOTE

  • Reference bit is useful for page replacement policy.
  • A page that has not been referenced recently is considered a good candidate for page replacement in LRU page replacement policy.

 

5. Caching Enabled / Disabled-

 

  • This bit enables or disables the caching of page.
  • Whenever freshness in the data is required, then caching is disabled using this bit.
  • If caching of the page is disabled, then this bit is set to 1 otherwise set to 0.

 

6. Dirty Bit-

 

  • This bit is also sometimes called as “Modified bit“.
  • This bit specifies whether that page has been modified or not.
  • If the page has been modified, then this bit is set to 1 otherwise set to 0.

 

NOTE

In case the page is modified,

  • Before replacing the modified page with some other page, it has to be written back in the secondary memory to avoid losing the data.
  • Dirty bit helps to avoid unnecessary writes.
  • This is because if the page is not modified, then it can be directly replaced by another page without any need of writing it back to the disk.

 

To gain better understanding about Page Table Entry,

Watch this Video Lecture

 

Next Article- Paging Important Formulas

 

Get more notes and other study material of Operating System.

Watch video lectures by visiting our YouTube channel LearnVidFun.

Paging | Memory Management | Operating System

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.

 

Techniques-

 

There are two popular techniques used for non-contiguous memory allocation-

 

 

  1. Paging
  2. Segmentation

 

In this article, we will discuss about Paging.

Learn about 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.

 

Example-

 

  • Consider a process is divided into 4 pages P0, P1, P2 and P3.
  • Depending upon the availability, these pages may be stored in the main memory frames in a non-contiguous fashion as shown-

 

 

Also Read- Contiguous Memory Allocation

 

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:

 

CPU generates a logical address consisting of two parts-

  1. Page Number
  2. Page Offset

 

 

  • 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:

 

For the page number generated by the CPU,

  • Page Table provides the corresponding frame number (base address of the frame) where that page is stored in the main memory.

 

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.

 

Diagram-

 

The following diagram illustrates the above steps of translating logical address into physical address-

 

 

Advantages-

 

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.

 

Disadvantages-

 

The disadvantages of paging are-

  • It suffers from internal fragmentation.
  • There is an overhead of maintaining a page table for each process.
  • The time taken to fetch the instruction increases since now two memory accesses are required.

 

To gain better understanding about Paging,

Watch this Video Lecture

 

Next Article- Page Table | Page Table Entry

 

Get more notes and other study material of Operating System.

Watch video lectures by visiting our YouTube channel LearnVidFun.