Difference Between Paging and Segmentation

Learn via video courses
Topics Covered

Key Difference Between Paging and Segmentation

The key difference between Paging and Segmentation lies in how they organize and manage memory.

  • In segmentation, memory is divided into logical segments, each representing a different type of data or code within a process. Segments can vary in size and are defined by the programmer. This method offers flexibility in managing memory but may lead to fragmentation issues, as segments can be of varying sizes.

  • Paging, on the other hand, divides memory into fixed-sized blocks called pages. The main memory is divided into fixed-sized blocks known as frames. In this scheme, the logical address space of a process is split into fixed-sized pages, and these pages are mapped to physical frames in the main memory. Paging eliminates fragmentation problems associated with segmentation but may lead to inefficient memory utilization if pages are not fully used.

What is Paging in the OS?

Paging is a memory management technique in which the operating system fetches the processes from the secondary storage into the main memory in the form of fixed-size memory blocks. These fixed-size blocks are called pages. Paging is a logical concept and it is used for quick access to data.

In this technique, the main memory is split into small blocks of physical address (memory). These small blocks are called frames.

In paging, the frame size is fixed. The frame size must be equal to the page size in order to utilize the main memory completely and to avoid external fragmentation.

What is Segmentation in OS?

Segmentation is another memory management technique, similar to paging. In this technique, the process is divided into segments (blocks) of different sizes. Every segment of a program holds a different logical address space. The segments of a program include the main function of the program, data structures (like stack and queue), functions, etc.

In the segmentation technique, the operating system maintains a segment map table that contains important details related to each segment. This includes a list of available memory blocks and their size, the segment numbers, and the memory locations of each segment.

Difference Between Paging and Segmentation

Following are the differences between paging and segmentation.

Sr. No.PagingSegmentation
1The address space of a process is broken into blocks of fixed size called pages.The address space of a process is broken into blocks of different sizes.
2The memory is divided into pages by the Operating System.The segment size, virtual address, and actual address are calculated by the compiler.
3Page size depends on the memory available.Segment size is determined by the programmer.
4Memory access is faster in Paging.Memory access is slower in Segmentation.
5Internal fragmentation can be caused by Paging because some pages may be underutilized.External fragmentation can be caused by Segmentation because some memory blocks may not be used.
6The logical address gets split into page offset and page number.The logical address gets split into section offset and section number.
7Page data is stored in page table.Segmentation data is stored in segmentation table.
8Data structures can not be handled efficiently.Data structures are handled efficiently.
9Paging is not visible to the user.Segmentation is visible to the user.
10The OS should maintain a free frame list.The OS should maintain a list of holes in the main memory.
11To calculate the absolute address, the processor needs page number and offset.To calculate the full address, the processor needs segment number and offset.
12Sharing of procedures between processes is difficult.Segmentation facilitates sharing of procedures between the processes.

Advantages of Paging and Segmentation

Advantages of Paging

Following are the advantages of paging:

  1. Paging is an easy to use algorithm for memory management.
  2. Paging does not require intervention from the programmer.
  3. Frames don't need to be contiguous.
  4. Equal-sized pages and page frames make swapping easy.

Advantages of Segmentation

Following are the advantages of segmentation:

  1. It is easier to relocate segments compared to the whole address space.
  2. Internal fragmentation does not happen.
  3. The segment table is smaller in size compared to the page table.
  4. It provides protection within the segment.
  5. Segment tables use lesser memory than paging
  6. Because of the small segment table, the reference to the memory is simple.

Disadvantages of Paging and Segmentation

Disadvantages of Paging

Following are the disadvantages of paging:

  1. Internal fragmentation is caused on older systems.
  2. The memory lookup time is more in paging compared to segmentation.
  3. Additional memory is consumed by the page tables.
  4. Multi-level paging can cause memory reference overhead.

Disadvantages of Segmentation

Following are the disadvantages of segmentation:

  1. Different segment sizes are not good for swapping.
  2. Porting from the Linux architecture to different architectures is difficult to process because it offers very limited support for segmentation.
  3. Segmentation requires intervention from the programmer.
  4. Because of the variable segment size, it is difficult to allocate contagious memory to partition.
  5. Segmentation is an expensive memory management algorithm.

Conclusion

  • Segmentation and paging are two different memory management techniques in the operating system.
  • Paging vs Segmentation: In paging, the pages are of the same size. In segmentation, the segments are of different sizes.
  • The page size in paging depends on the hardware, while the segment size in segmentation is determined by the programmer.
  • Memory access in paging is faster than segmentation.
  • Segmentation is visible to the user, while paging is not.
  • In summary, segmentation focuses on dividing memory into logical units defined by the programmer, offering flexibility but potentially leading to fragmentation, while paging divides memory into fixed-sized blocks, promoting efficient memory usage but lacking the flexibility of segmentation. The choice between these techniques depends on the specific requirements of an operating system and the trade-offs between flexibility and efficient memory management.