Open In App

Prepaging in Operating System

Last Updated : 11 Jun, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite – Virtual Memory in Operating System

As suggested by the concept of virtual memory, it is not necessary that the entire process should be loaded into the main memory at the given time. The process can be executed efficiently if only some of the pages are present in the main memory at a particular time. Now the question which arises here is what is the basis of the selection of pages to be loaded into the main memory for execution of a process beforehand?

The answer to the problem presented here is Demand Paging. According to this concept, any page is not loaded into the main memory unless it is being referenced by the process at any stage of execution. In contrast, the concept of Prepaging presents a different approach where the Operating System presents a guess for which page the process will require and pre-loads it into the memory.

The concept of Prepaging is used as an attempt to reduce the large number of page faults that occur at the start of a process where the basic strategy is to bring all the pages into the memory that will be needed at the same time before they are actually referenced by the process. 

Prepaging is used to overcome a major drawback of demand paging. A major drawback of Demand Paging is a significantly large number of page faults which may occur as soon as a process starts to execute. The situation is an outcome of an effort to load the initial locality into memory. The same situation may arise repeatedly. For example, when a process is restarted after being swapped-out,all its pages are present on the disk and hence each one of the pages must be brought back to the main memory for execution of the process by its own page fault in the worst case.
If a system uses a Working – Set Model, a list of pages is maintained with each process in its working set. If a process is suspended due to lack of free frames or an I/O wait, the working set of the process is not lost. When a process is resumed, the entire working set is brought back into the memory before the process begins to execute again.
The major advantage of Prepaging is that it might save time when consecutive addresses are referenced by a process. In this case, it is easy for the Operating System to guess and load the appropriate pages and, as there is a high probability of the guess being right for many pages, there will be fewer page faults occur.

Prepaging may not be always beneficial. The advantage of Prepaging is based on the answer to a simple question that whether the cost of implementing Prepaging is less than the cost of servicing the corresponding page faults. Please note here that it may be the case that a considerably large number of pages brought back into the memory by Prepaging are not used. The disadvantage of the concept is that there is a wastage of resources like time and memory if the pre-loaded pages are unused.

Difference between Demand Paging and Prepaging :

Demand Paging

Pre-Paging

Any page is not loaded into the main memory unless it is being referenced by the process at the present instant. All the pages are loaded into the memory that will be needed at the same time in near future but before they are actually referenced by the process. 
The number of page faults is significantly high. The number of page faults may be reduced in certain specific cases.
The time taken to load the pages can not decrease in any situation. The time taken to load the pages decreases when consecutive addresses are referenced by a process.
The pages loaded in the main memory are certainly used. The pages loaded in the main memory might or might not be used.
There is no wastage of resources as a page is loaded as and when needed. There is a wastage of resources as there is a high chance that the pages might be unused.

Let the number of pages pre-paged is: s, and the fraction of these pages actually used by a process is : m, where (0 ≤ m ≤ 1). Now check if the s*m save page faults are greater or less than the cost of prepaging s*(1-m) unnecessary pages and proceed with the procedure which has a less relative value.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads