What are the basic concepts of demand paging?
In this tutorial, we are going to uncover all crucial details regarding the concept of demand paging in OS!
This process is defined as a vital process to transfer data from the secondary memory to the main memory on demand. In other words, it means that all types of data will not be saved in the primary storage memory or RAM as RAM may have limited execution space.
In case of demand paging, the program codes are split into pages so that the processor will access it quickly.
Here, in this blog post, we will look closely at the concept or working of demand paging by knowing about all the essential terms that are mostly used in this concept.
Without any delay, let’s get started!
Demand paging in operating system
In the operating system, demand paging refers to the memory management technique where modern operating systems help in the management of memory. The basic objective of demand paging would be to allow an operating system to only load the parts of a given program which are needed by the computer memory.
When any program is launched, your operating system may not load it entirely into the main memory at the single go. Rather, it loads that program in parts so as to accurately start the execution of the program.
When the program requires more memory, your operating system will run the additional parts of that program that havent been used for a long time. This particular process is called swapping.
It is touted as an effective technique as it basically allows your operating system to make an efficient use of memory. The CPU will demand this process to remove the data from a system’s secondary memory to let it use by the main memory.
Key point to note
When we are talking about demand paging in the OS, we can call a pager as a swapper that usually deals with the individual pages. The page will only be brought into the main memory when it is requested by the CPU.
At first, you may need to load the page directly that will be required by your CPU. They may not directly get access to physical memory. Though, you can use it whenever you want.
Purpose of demand paging
In the process, there are so many pages. Though, to put all those pages into the main memory can add to its consumption. To resolve this problem, the concept of demand paging comes into being.
It is defined as a method where the pages are brought into the main memory only after they are requested by the CPU. Let’s consider an example;
A user is involved in a program to calculate the overall cost of the fencing that is needed in a field. For that, there would be different pages required to code.
Page 1: Cost to fence
Page 2: Labour cost
Page 3: Field surface area
The user can easily calculate the overall cost required for fencing. There will not be a need to load all the three pages as the demand paging concept would be sufficient to play the needed role in this case. Only page 1 will be loaded in this case.
Terms used in demand paging
When you are studying the field of demand paging, you should know about all the vital terms that are used in this field:
Page fault: You may notice a miss in case the reference page will not be present in the main memory. This term is known as page fault or page miss. Your CPU can look for all missing pages in the secondary memory. If the number of pages is vital, the effectiveness of your system may dramatically increase.
Swapping: This comprises erasing of all the pages in the required process from your main memory to either mark them so as to remove them via the replacement process. When any process is suspended, it may not be able to run ideally. Your system may swap the entire process in the main memory over a period of time. The condition of thrashing will occur which is defined as a process where all the pages will be swapped in and out of memory
Thrashing: It is touted as the technique where you can effectively access the time that is required by a CPU to read all words from the secondary memory. It also helps in identifying the page faults so that the CPU will only read the pages from the main memory.
Working of demand paging in OS
Whenever a CPU will request an access of any page, the page table will be used to find all the pages in a main memory. If the page found is good otherwise a default will occur.
Page fault occurs when the CPU needs access from your main memory. For this, you can make use of the swapping technique for the main memory. The program will be reversed back from the hard drive to the main memory.
Your secondary memory in this case will load the other pages. Moreover, there will be valid or invalid bits to check if the page is present in the main memory or not. All valid bits means that the page is legal and is present in the main memory. Though, the invalid bit means that the page is not there in the main memory.
Additional learning - Master Theorem
When we are studying all the crucial concepts of operating systems and computer fundamentals, we can also study the concept of the master theorem. In the case of analysing algorithms, the master theorem will provide recurrences of divide and conquer algorithms for doing asymptotic analysis for recurrence relationships. Users can apply this theorem to get adequate results for varied types of algorithms.
Wrapping up
Learn all the essentials of demand paging in the OS with the help of this guide. Know about its working and implement this concept in an ideal way.
Happy learning!