We do paging because we want a process to be stored in non contiguous manner in the main memory.
So we divide main memory in equal size partition called frames and secondary memory space also in equal size partition where each partition is called page such that
Size of page = size of frame.
here size of each frame is fixed so we have fixed size partitioning scheme thus leading to internal fragmentation in the main memory.
Since size of secondary memory > size of main memory(let)
so we will have more pages as compared to frames.
let there be 4 frames in main memory and 7 pages in secondary memory.
Suppose there is a process which occupies $3$ pages in secondary memory i.e. $P_1,P_2,P_3$ pages are occupied in secondary memory and the remaining pages are still free.
So we will now pick each of the page and find a frame for it to store it in main memory.
page |
frame allocated |
1 |
2 |
2 |
1 |
3 |
4 |
4 |
|
5 |
|
Suppose the allocation goes like shown above.
now only frame 3 is empty.
Now we store the above table(page table) also in a frame and we only have frame 3 left to allocate it as all other frames are occupied.
SO NOW MAIN MEMORY IS FULL SINCE ALL THE FRAME OF MAIN MEMORY IS OCCUPIED.
now suppose a new process is created in Secondary memory and it occupies $P_4,P_5,P_6$ so now we want to execute it so we again need frames but frames are full.
So we will deallocate the frames and delete the page table to process 1 and give it to pages and page table of process 2 now process 2 will execute.
If process 2 would have been of size 6 pages then concept of virtual memory would have been used.
So NO EXTERNAL FRAGMENTATION