Monday 9 November 2020

What is a Paging technique in OS?

 

Paging:

 

Paging is an efficient memory management scheme because it is a non-contiguous memory allocation method. The previous (single partition, multiple partition) methods support the contiguous memory allocation. The entire process is loaded in a partition. But in the paging, the process is divided into smaller parts and these are loaded into elsewhere in the main memory.

 

The basic idea of paging is the physical memory (main memory) is divided into fixed size blocks called frames, the logical address space (user job) is divided into fixed size blocks called pages; but page size and frame size should be equal. The size of the frame or a page is dependent on operating system. Generally, the page size is 4 KB.

 

In this scheme, OS maintains a data structure i.e. a page table. It is used for the mapping purpose. The page table specifies some useful information. It tells us which frames are allocated, which frames are available, and how many total frames are there, etc. The general page table consists of two fields, one is page number and other is frame number. Each operating system has its own methods for storing page tables. Most of them allocate a page table for each process.

 

Every address generated by the CPU is divided into two parts. One is page number (P) and second is page offset or displacement (D). The page number is used as an index in a page table. Consider the following fig:

Paging structure

Fig: Structure of paging scheme


The mapping between page number and frame number is done by page map table. The page map table specifies which page is loaded in which frame, but displacement is common. Consider the below example:

 

 

There are two jobs in the ready queue. The job sizes are 16 KB and 24 KB respectively. The page size is 4 KB and available memory is 72 KB (18 frames). So, job1 is a divided into 4 pages and job2 is divided into 6 pages. Each process maintains a program table. Consider the below figure for better understanding:


Paging example

Fig: An example of paging


4 pages of job1 are loaded in different locations in main memory. The OS provides a page table for each process. The page table specifies the location in main memory. The capacities of main memory in our example are 18 frames. But, the available jobs are two (10 pages). So, the remaining 8 frames are free. The scheduler can use these free frames to some other jobs.

 

 Advantages:

  1. It supports the time sharing system.
  2. It does not affect from fragmentation.
  3. It supports virtual memory.
  4. Sharing of common code is possible.

 

 Disadvantages:

  1. This scheme may suffer from page breaks. For ex: the logical address space is 17 KB, the page size is 4 KB. So, this job requires 5 frames. But, the 5th frame consists of only 1KB. So, the remaining 3 KB is wasted. This is called as a page break.
  2. If the numbers of pages are high, it is difficult to maintain page tables.

 

 

 Shared Pages:

 

In multiprogramming environment, it is possible to share the common code by number of processes at a time, instead of maintaining the number of copies of same code. The logical address space is divided into pages.  These pages can be shared by number of processes at a time. The pages which are shared by the number of processes is said to be shared pages.

 

For ex: consider a multiprogramming environment. It consists of a 10 users. Out of 10 users, 3 users wish to execute a text editor. They want to make their bio data in text editor. Assume that a text editor requires 150 KB and the user bio-data occupies 50 KB of data space. So, they would require 3x (150 + 50) = 600 KB. But, in shared paging, the text editor is shared to all jobs so it requires 150 KB, and the user files require 150 KB (50x3=150 KB).

 

Therefore, (150 + 150) = 300 KB is enough to manage these three jobs instead of 600 KB. So, this shared pages mechanism saves 300 KB of space. Consider the below figure for a better understanding:


Sharing a code in paging environment

Fig: Sharing a code in paging environment


The page size and the frame size is 50 KB. So, 3 frames are required for text editor and 3 frames are required for user files. Each process (P1, P2, and P3) has a page table. The page table shows the frame numbers. The first 3 frame numbers in each page table i.e. 3, 8, 0 are common. It means the three processes share the three pages. Main advantage of shared pages is efficient memory utilization is possible using this technique.


No comments:

Post a Comment