Table of contents
1.
Introduction 
2.
What is Paging?
3.
What is Segmentation?
4.
Difference Between Paging and Segmentation
5.
Frequently Asked Questions 
5.1.
Define overhead in the OS 
5.2.
What is the difference between internal and external fragmentation? 
5.3.
What are the drawbacks of Paging over Segmentation?
6.
Conclusion
Last Updated: Jul 9, 2024
Easy

Difference between Segmentation and Paging

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction 

Both segmentation and paging are memory management techniques used to facilitate the efficient allocation and management of memory in computer systems. Segmentation divides memory into variable-sized segments based on logical units such as functions or data structures, while paging divides memory into fixed-sized blocks or pages. Segmentation allows flexibility in memory allocation, while paging simplifies memory management and provides better utilization of memory.

Operating Systems

In this article, we will be learning about Paging and Segmentation and the difference between them in detail.

To understand the differences, we must know what Paging and Segmentation are. Let us have a brief look at what Paging entails in the non-contiguous allocation first:

Also see, Segmented Paging

What is Paging?

Paging is a storage method that allows the operating system to fetch processes from secondary storage and store them in the main memory in the form of pages.

Furthermore, Paging is a non-contiguous memory allocation technique that divides secondary and main memory into equal-sized divisions. Secondary memory partitions are referred to as pages, whereas primary(main) memory partitions are referred to as frames.

Frames and Pages

 

They are separated into equal-sized segments to maximize main memory use and minimize external fragmentation. It is worth noting that the page size and the frame size must be the same. 

Some important points are: 

  • Pages of a process are brought into main memory only when necessary; otherwise, they are stored in secondary storage.
  • One page of a process is primarily kept in one of the memory frames. Furthermore, the pages might be placed in various locations across the memory, but the major aim is always to discover contiguous frames.
Mapping
  • The CPU generates the logical address to fetch the process from the secondary memory, unaware of the fact that the main memory is in between them( CPU -> Main Memory -> Secondary Memory). 

So, in order to access the main memory, there always needs a Physical address. To translate the logical address into the physical address, a translator is required. 

Illustration Image

Mapping(Translation) is done with the help of MMU(Memory management unit) which further utilizes the page table to fetch the exact location of the input stored in secondary memory. 

A page table includes the frame number associated with a given process's page number. As a result, each process will have its own page table. The Page Table Base Register (PTBR) is a register that stores the page table's base value.

  • It's simple to swap out equal-sized pages and frames, although there can be a chance that paging leads to internal fragmentation. It is possible that the process is too tiny and does not acquire the complete frame size.
  • For every process, there is a page table. Maintaining an equal number of page tables could lead to an overhead. 
     

Let us know have a look at what exactly Segmentation entails:

Recommended Topic, Internal and External Fragmentation

What is Segmentation?

We were blindly diving the process into fixed-size pages in paging, but in segmentation, we split the process into modules for better visibility. In this case, each segment or module has the same set of functions. For example, the main function may be contained in one segment while the library function could be included in other segments, and so on. Memory is partitioned into variable-size sections due to the varying size of segments. 

Suppose you have written a program in the C language in which you define the add() function that adds the two numbers. Now you make a call to the add() function, in paging, there can be a chance that the code is divided into two equal-sized pages/frames. Now, if the CPU generates the logical address for calling the add() function, the output can be wrong due to the fixed-sized partitioning. Whereas, in segmentation, the modules are divided into variable-sized partitioning that can avoid such types of circumstances. 

Some important points are: 

  • Since a CPU always generates a logical address, we require a physical address to access the main memory. The segment table is used by the MMU (memory management Unit) to do the mapping.

A segment table stores the base address of each segment in the main memory. It has two sections: Base and Limit. The Base here indicates the base address or starting address of the segment in the main memory. The limit specifies the length of that segment. A register known as the Segment Table Base Register (STBR) stores the segment table's base value. The segment table is also kept in the main memory.

Illustration Image
  • The size of the segment table is less than that of the page table.
  • Internal fragmentation does not exist.
  • When processes are loaded and unloaded (during swapping) from the main memory, free memory regions are fragmented, resulting in external fragmentation.

Let us now discuss all the potential differences between Segmentation and Paging. 

Difference Between Paging and Segmentation

Sr. No.

Parameters

Paging

Segmentation

1

Memory Size In paging, a process address space is divided into fixed-sized chunks called pages. In Segmentation, a process addresses space divided into various sized chunks known as sections.

2

Accountability The Operating System is responsible for the division of the memory into pages. The compiler is in charge of calculating the segment size, the virtual address, and the actual address.

3

Size Page size is determined by available memory. Section size is determined by the user. Hence it is said that segmentation works on the user’s point of view. 

4

Speed Paging technique is faster in terms of memory access. Segmentation is slower in terms of memory access than paging. 

5

Fragmentation Internal fragmentation might result from paging because certain pages may go unused. Segmentation can cause external fragmentation as some memory blocks may not be used at all.

6

Logical Address During paging, a logical address is divided into page number and page offset. During segmentation, a logical address is divided into section number and section offset.

7

Data Storage The page data is stored in the page table. Segmentation table stores the segmentation data.


You can also read about the interleave memory.

Frequently Asked Questions 

Define overhead in the OS 

Any combination of extra or indirect computing time, memory, bandwidth, or other resources necessary to complete a task is referred to as overhead.

What is the difference between internal and external fragmentation? 

When the memory allocator leaves additional space unfilled inside a block of memory that has been allocated for a process, internal fragmentation occurs. When free memory is divided into small blocks and interleaved with assigned memory, external fragmentation occurs.

What are the drawbacks of Paging over Segmentation?

  • When compared to segmentation, memory lookup times are longer.
  • Internal fragmentation is a possibility.
  • Additional memory is used by page tables.
  • Memory reference overhead may result from multi-level paging.

Conclusion

To summarise the discussion we’ve briefly looked at the two different types of non-contiguous memory allocation: Paging and Segmentation. We’ve also discussed major differences between them which are very important in university-level exams, Gate, and for interview purposes. PAGING and SEGMENTATION both seem tricky to understand at first instance yet very easy if we understand them in-depth. 

Recommended Reading:

Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, Uber, Microsoft, etc. on Code360.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Code360.

I hope the article provided you with great insight. Stay connected for more amazing content. 

Happy Learning Ninja. 

Live masterclass