Sunday 25 June 2017

What is paging and why do we need it?

  No comments
As I mentioned in my previous posts about the disadvantages of fixed partitioning and dynamic partitioning, the processes in memory are not allowed to be at different places. They have to be continuous. And it was because of this very reason we faced internal and external fragmentation.

Paging is one of the most popular methods and is still in use. In this technique, we divide the process into equal size small parts. These parts are called as pages. We then divide the main memory into small parts called frames. The division is such that size of the pages and frames are equal.

Whenever the process wants to execute we transfer the pages of the process from the secondary storage to main memory. But we don't transfer all the pages. Only the pages which are required are transferred to the main memory. Whenever the execution completes for the process the pages are wiped of the frames. But the question might arise how do we keep track of pages of the processes.

For this, we use page table. For every process, we have a unique page table. The page table tells which page is stored in which frame. To better understand it let's look at an illustration.

Consider the following diagram. In this, the size of the process is 1 KB. And main memory size is 1 MB. Assume the page size allowed in our computer is 1 Byte.


Now we divide the process into pages. Since each page size is 1 Byte, the process will contain 1024 pages of size 1 Byte. Similarly, when we divide the main memory into frames, it will contain 2^20 frames each of size 1 Byte.
Now as an when the pages are requested they are brought into main memory and are stored in frames. They need not be stored continuously. They can be allocated anywhere in the memory except the reserved space.

The page table keeps track of the pages of the process. In the above diagram, we can see page table 1 keeps track of process 1 pages and page table 2 keeps track of process 2 pages. The entries in the page table keep on updating as and when the pages move in and out of the memory.

Now because of paging many of the disadvantages of fixed and dynamic partitioning are removed.

  • There is no external fragmentation.
  • The degree of multiprogramming increases.
There is internal fragmentation but it is negligible. As the maximum space wasted could only be approximately one page.

There is a lot more to be discussed about paging like how paging work with virtual memory? how frames are allocated to pages? All this will be explained in the next post.

This was all about this topic. As always if you like the post, share it. If you have any queries, or you want to suggest something you can always ping me on Facebook or mention in the comments section below. I will be happy to help. You can follow me on Facebook or google+. Don't forget to follow the blog.

No comments :

Post a Comment