ALL >> Education >> View Article
Working Of Demand Paging In Operating System

Have you ever thought of how a computer provides you with all the information without crashing or running multiple of your requests without messing them up?
Well, this is done with the help of a phenomenon called paging and sometimes demand paging.
In the paging approach, the system code is divided into smaller codes that a processor can easily manage. After that, with the help of the demand paging technique, only the required page is provided to the main memory. In this way, you get the required process or program that you wish without facing any crashes.
But the main question is, how this whole process is carried out in such a small period?
To help you understand how demand paging in OS works, we have come up with this comprehensive guide.
Check out everything that you need to know about demand paging in this post!
Understanding Demand Paging in OS
Demand paging is simply a scheme to manage the memory used to manage the physical memory resources available to be used by modern operating systems.
It is a process to move the data from secondary storage to RAM when ...
... demanded. This simply means that all the data is not present in the main memory because of the limited space.
Therefore, when the CPU demands a certain page or process and RAM does not have that page, it performs swapping. It shifts a page from RAM and gets the demanded page to RAM.
Let's understand demand paging in OS with a real-life example:
For instance, you have been to a store to buy clothes. Now, the shopkeeper will check if the products you have asked for are available in the shop or not.
To check that, he will first check the maintained records. However, if it is not available in the shop, he will ask the helper to get the same from the warehouse.
In that way, he will only bring the item that you have demanded. Keep note that not everything will be available in the shop because it has very limited space.
Other than this, the customer will only visit the shop to get things rather than going to the warehouse.
In the same way, when you ask for a page from RAM, if it is not available in it, it will ask for the same from the secondary storage.
Why is demand paging required?
Now that you have understood what demand paging in the OS is, let's discuss why you need one.
The main reason behind performing demand paging is to make efficient use of the existing resources of the system.
Now that you are aware that there are multiple pages available in a system, however, keeping all of them in the main memory is not suitable.
Therefore, the only efficient method to save space in RAM is through paging and loading pages only those which are in demand.
Other than this, one of the major advantages to use demand paging is that it decreases the time required to respond to all requests made by the user and hence, increases the performance of the system.
To understand better, consider an example to run a program to calculate the cost of painting your room.
For this, you can use different codes. Consider that three pages are available which have different codes.
P1: This page will calculate the labour cost.
P2: This page will calculate the paint cost
P3: This page will calculate the overall surface area.
In case, the user wishes to calculate the labour cost only. In that case, the CPU will only get page number 1. However, if there was no concept of pages 2 and 3, the whole program would have loaded which takes more space.
Working on demand paging
When a demand for a certain page is made, the system will refer to the page table to check if the required page is available. In case the required page is available in the main memory, the program will be executed.
However, if it is not available, the page fault situation will occur.
Now, in the case of a page fault, we will have to perform a swapping of the page. For that, we will have to remove the page from the hard disk and it will be then put into the RAM or main memory of the computer.
In the demand paging technique, you will also come across valid and invalid bits that are generally present in each entry of the page table.
Therefore, when the CPU attempts to find any page in the memory, it will also check for invalid and valid bits related to the page.
Invalid bits: In case a particular bit is invalid, it simply means that the required page is either not available currently on the disk or the page is no longer valid.
Valid bits: In case a particular bit is valid, the required page is then considered valid and legal.
Steps Involved In Demand Paging
To begin with, when you make a request on any page, the page table will be consulted. In case any of the available frames are invalid, the following steps will be performed.
=> In case there is a page fault, it will generate an interruption.
When an interruption occurs, the operating system will move to the blocked state.
=> After this, the requested process will be searched in the secondary memory.
=> You need to now check if any free frame is available. In case any free frame is not available, a page replacement algorithm will be used.
It will then replace the page.
=> After replacement, the CPU is informed that the pages have been updated. It will then execute the process.
Conclusion
The paging process is very important to ensure the proper functioning of multiprogramming operating systems and other OS. It helps the operating system to manage all the processes in the limited memory space.
The demand paging process is quite important for modern operating systems to ensure that each of the required processes has proper access to the memory.
Add Comment
Education Articles
1. Gavin Mccormack Journey As An Education ChangemakerAuthor: selinclub
2. What Makes Dubai An Ideal Destination For Global Business Conferences?
Author: All Conference Alert
3. D365 Functional Course In Ameerpet | Dynamics 365 Course
Author: Hari
4. Best Sre Certification Course | Sre Training Online In Bangalore
Author: krishna
5. Best Google Cloud Ai Training In Ameerpet | Visualpath
Author: visualpath
6. Azure Ai Engineer Course In Bangalore | Azure Ai Engineer
Author: gollakalyan
7. What To Expect At The Vermont Dmv Driving Test
Author: Ravinder Malik
8. Key Highlights Of Punyam Academy’s Iso 9001 Lead Auditor Training Course
Author: Emma
9. Ai With Aws Training | Ai With Aws Online Training Bangalore
Author: naveen
10. Salesforce Devops Training | Salesforce Devops With Copado
Author: himaram
11. How Does Cpr Affect High-risk Professions Like Healthcare, Sports, And More?
Author: Christopher Bayer
12. Best Bba Colleges In Hyderabad For Students Seeking A Corporate Career
Author: SSDC
13. Why We Charge A Training Fee At Pydun Technology
Author: Pydun Technology Private Limited
14. Informatica Idmc | Informatica Online Training In Hyderabad
Author: gollakalyan
15. Best Snowflake Course | Snowflake Training In India
Author: Pravin