Open In App

Two Level Paging and Multi Level Paging in OS

Last Updated : 17 May, 2023
Like Article

Paging is the process in which we convert the entire process into equal-sized pages. Each page further consists of a fixed number of words (if it is word addressable). The Pages are represented by the Virtual Address generated by the CPU. These Pages are mapped to the Physical Address by the MMU. So, to help in this mapping we use the concept of Page Table. Like the array, in the Page Table, the indices represent the Page Numbers and the contents contain the address of the Frame Number where the process is actually loaded in the main memory. Because the virtual/Logical Address is relative to zero and should be mapped to the actual physical Address Space of the Main Memory. The size of the page table can be calculated from the fact that the size of each entry of the page table is given else if it is not given then we can find the number of bits required to address each frame in the main memory (this is not correct but should be used when nothing is given in question).

Page Table Size = No. of Page Table Entries(Total no. of Pages) * (size of each entry of page table)

When the size of the page table is less than the size of one Frame then we need not worry because we can directly put the page table in a frame of the main memory. Thus we can directly access the page table. But if the size of the page table is larger than the size of the Frame. Then the page table in return is to be divided into several pages and these pages of the page table are to be stored in the main memory. Thus, an Outer Page Table comes into the picture. This Outer Page Table would contain the address of the Frames which contain the pages of the Inner Page Table (i.e., Page Table one page) in the main memory. The size of this Outer Page is also calculated in the same way as explained above and was used to calculate the size of the inner page Table. Now if the size of the Outer Page Table is Less Than or Equal to the size of a Frame then we can stop here as we are able to keep the outermost table in a Single frame. This is called Two Level Paging. Example: Consider given,

Physical Address Space = 2(44) B
Virtual Address Space = 2(32) B

Page Entry = 4B
Page Size = 4KB

So, No.of Frame = 2(44) / 2(12) = 2(32)
No. of Pages Of the Process = 2(32) / 2(12)  = 2(20)
Page Table 1 size = 2(20) * 4B = 4MB 

As it is larger than 4KB (Frame size). Thus, this Page Table has to be converted to pages. No. of pages of Page Table 2 (Outer Page Table)

= (2(20) * 2(2)B) / 2(12)B = 2(10) pages 

So, the size of the Outer Page Table

= 2(10) * 4B = 4KB 

Thus here our Outer Page Table (Page Table 2) can be stored in one frame. Therefore, we can stop here. This is Two-level Paging because here we got 2-page tables. But If still the size of the page table is more than the Frame Size then we have to continue till we reach a stage where the size of Outer Most Table is less than the Frame Size. This Concept is called MultiLevel Paging. Our Target should be to keep the outermost Page Table in a single Frame.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads