Paging is a storage mechanism that allows OS to retrieve processes from the secondary storage into the main memory in the form of pages. In the Paging method, the main memory is divided into small fixed-size blocks of physical address, which are called frames. The size of a frame should be kept the same as that of a page to have maximum utilization of the main memory and to avoid external fragmentation. Paging is used for faster access to data, and it is a logical concept.
In this Paging vs Segmentation tutorial, you will learn:
- What is Paging in OS?
- What is Segmentation in OS?
- Difference between Paging and Segmentation
- Advantages of Paging
- Advantages of Segmentation
- Disadvantages of Paging
- Disadvantages of Segmentation
Segmentation method works almost similarly to paging, the only difference between the two is that segments are of variable length whereas, in the paging method, pages are always of fixed size. A program segment includes the program’s main function, data structures, utility functions, etc. The OS maintains a segment map table for all the processes. It also includes a list of free memory blocks along with their size, segment numbers, and its memory locations in the main memory or virtual memory.
- A page is of the fixed block size whereas a segment is of variable size.
- In Paging, the hardware decides the page size while the segment size is specified by the user.
- The paging technique is faster for memory access but segmentation is slower than paging method.
- In paging, the user just provides a single integer as the address while in segmentation, there is the availability of many independent address spaces
- Page table stores the page data while Segmentation table stores the segmentation data.
Here are the differences between Paging and Segmentation in OS:
|A page is of the fixed block size.||A segment is of variable size.|
|It may lead to internal fragmentation.||It may lead to external fragmentation.|
|In Paging, the hardware decides the page size.||The segment size is specified by the user.|
|A process address space is broken into fixed-sized blocks, which is called pages.||A process address space Is broken in differing sized blocks called sections.|
|The paging technique is faster for memory access.||Segmentation is slower than paging method.|
|Page table stores the page data||Segmentation table stores the segmentation data.|
|Paging does not facilitate any sharing of procedures.||Segmentation allows for the sharing of procedures.|
|Paging fails to distinguish and secure procedures and data separately.||Segmentation can be able to separate secure procedures and data.|
|Paging address space is one dimensional||In segmentation, there is the availability of many independent address spaces|
|In paging, the user just provides a single integer as the address, that is divided by the hardware into a page number and offset.||In the segmentation method, the user specifies the address in two quantities 1)segment number 2)offset.|
Here are the pros/benefits of using Paging method:
- On the programmer level, paging is a transparent function and does not require intervention.
- Frames do not have to be contiguous.
- Easy to use memory management algorithm
- Swapping is easy between equal-sized pages and page frames.
Here are the pros/benefits of Segmentation:
- Simple to relocate segments than the entire address space.
- The absence of internal fragmentation as external fragmentation has to be done.
- The segment table is of lesser size compared with the page table in paging.
- The average size of the segment is larger to the actual size of the page
- Offer protection within the segment
- Not offers internal fragmentation
- Segment tables use lesser memory than paging
- As it offers the small segment table, memory reference is simple, which lends itself to sharing data among processes.
Here are the cons/drawbacks of Paging:
- Paging causes internal fragmentation on older systems.
- Longer memory lookup times compared to segmentation
- It may cause internal fragmentation
- Page tables consume additional memory.
- Multi-level paging may lead to memory reference overhead.
Here are the cons/drawbacks of Segmentation:
- Un-equal size of segments is not good in the case of swapping.
- Porting Linux to different architectures is difficult to process because it offers very limited support for segmentation.
- It demands programmer intervention.
- It is hard to allocate contagious memory to partition as it is of its variable size.
- This is costly memory management algorithm.