12 Difference Between Paging And Segmentation In OS

Paging And Segmentation

Paging in operating systems, is a memory management scheme whereby a computer stores and retrieves data from secondary storage for use in main memory. In this scheme, operating system retrieves data from secondary storage in same-size blocks referred to as pages.

The main idea behind the paging is to divide each process in the form of pages. The main memory will also be divided in the form of frames and therefore one page of the process is to be stored in one frames of the memory.

Paging decreases the efficiency of the system as it can divide the same function into different pages which may or may not be loaded into memory at the same time.

Segmentation on the other hand, is a memory management technique in which, the memory is divided into the variable size parts. Each part is then referred to as segment, that means, it can be allocated to a process.

Though paging is more close to operating system rather than the user because it divides all the processes into the form of pages, segmentation is far better because it divides the process into segments whereby each segment constitutes same type of functions such as main function being in one segment and library function being in the other segment.

Advantages and Disadvantages Of Segmentation

Advantages

  • There is less overhead in segmentation
  • It is very much simpler to relocate segments than entire address space.
  • There absence of internal fragmentation, because external fragmentation has to be done.
  • The segment table is of lesser size when compared to the page table in paging.
  • The average size of the segment is relatively larger to the actual size of the page.

Disadvantages

  • It may contain external fragmentation
  • It is difficult to allocate contagious memory to partition because of its variable size.
  • This memory management technique is too costly.

Key Difference

  1. Segmentation allows programs, data and codes to break up into independent address spaces. These spaces help in protection and sharing of the programs. Paging on the other hand, is utilized when getting a large linear address. This is usually done without having to purchase more physical memory.
  2. In segmentation, the segmented table maps the logical address to the physical address and it contains segmented number and offset (segment limit). In paging, the page table maps the logical address to the physical address and it contains base address of each page stored in the frames of physical memory space.
  3. Segmentation allows for the sharing of procedures whereas paging does not allow any sharing of procedures.
  4. Segmentation can be able to differentiate between and secure procedures and data separately whereas paging fails to distinguish and secure procedures and data in a separate fashion.
  5. Segmentation may lead to external fragmentation as the memory is filled with the variable sized blocks. On the contrary, paging may lead to internal fragmentation as the page is of fixed block size, but it may happen that the process does not acquire the entire block size which will generate the internal fragmentation in memory.
  6.  One among other advantages of segmentation is that, it is visible and can be seen by developers. This process can manage the overall growth of modularity, data structure and provide support for the exchange and protection of data. On the other hand, advantage of paging is that, the units that move across the main memory are of the same size and fixed. Hence, complicated memory management algorithms for exploiting the program’s behavior are not possible.
  7. Segmentation consists of dynamic linking and dynamic loading whereas paging consists of static linking and dynamic loading.
  8.  In segmentation, change in data or procedure requires compiling only affected segment not entire program. On the other hand, in paging, change in data or procedure requires compiling entire program.
  9. In segmentation, there is availability of many independent address spaces whereas in paging, address space is one dimensional.
  10. In segmentation, the size of the segmented page is specified by the user. On the other hand, in paging, the size of the page is decided or specified by the hardware.
  11. In segmentation, the user specifies the address in two quantities i.e segment number and offset.  In paging, the user only provides a single integer as the address which is divided by the hardware into a page number and offset.
  12. Segmentation makes it possible for the programmers to have prior knowledge of the memory limits. This is usually done as the programmer attempts to allocate memory space function, variables and strives to reach the read only memory violation that eventually results in segmentation faults. On the other hand, paging is transparent and clear for programmers as the system manages it automatically.

READ FURTHER: Difference Between Logical And Physical Address In Operating System

Paging Vs. Segmentation In Tabular Form

BASIS OF COMPARISON SEGMENTATION PAGING  
When Is Used Segmentation allows programs, data and codes to break up into independent address spaces. These spaces help in protection and sharing of the programs. Paging is utilized when getting a large linear address. This is usually done without having to purchase more physical memory.  
Table Maps In segmentation, the segmented table maps the logical address to the physical address and it contains segmented number and offset (segment limit). In paging, the page table maps the logical address to the physical address and it contains base address of each page stored in the frames of physical memory space.  
Sharing of procedures Segmentation allows for the sharing of procedures.   Paging does not allow any sharing of procedures.
Differentiation of secure procedures & data Segmentation can be able to differentiate between and secure procedures and data separately.   Paging fails to distinguish and secure procedures and data in a separate fashion.
Result Segmentation may lead to external fragmentation as the memory is filled with the variable sized blocks. Paging may lead to internal fragmentation as the page is of fixed block size, but it may happen that the process does not acquire the entire block size which will generate the internal fragmentation in memory.  
Advantage Advantage of segmentation is that, it is visible and can be seen by developers. This process can manage the overall growth of modularity, data structure and provide support for the exchange and protection of data.   Advantage of paging is that, the units that move across the main memory are of the same size and fixed. Hence, complicated memory management algorithms for exploiting the program’s behavior are not possible.                
Constituents Segmentation consists of dynamic linking and dynamic loading.   Paging consists of static linking and dynamic loading.
Change In Data In segmentation, change in data or procedure requires compiling only affected segment not entire program. In paging, change in data or procedure requires compiling entire program.  
Address Spaces In segmentation, there is availability of many independent address spaces. In paging, address space is one dimensional.  
Size Of The Page In segmentation, the size of the segmented page is specified by the user.   In paging, the size of the page is decided or specified by the hardware.                
The User In segmentation, the user specifies the address in two quantities i.e segment number and offset.    In paging, the user only provides a single integer as the address which is divided by the hardware into a page number and offset.
Programmers Segmentation makes it possible for the programmers to have prior knowledge of the memory limits. Paging is transparent and clear for programmers as the system manages it automatically.  

Also Read: Difference Between Process And Thread