Practice
Data Structures and Algorithms
Machine Coding Round (LLD)
System Design & Architecture (HLD)
Frontend UI Machine Coding
Resources
Career Advice and Roadmaps
Data Structures and Algorithms
Machine Coding Round (LLD)
System Design & Architecture (HLD)
Backend Development
Frontend Development
Project Ideas for Software Developers
Core Computer Science
Companies
SDE Jobs & Internships
Interview Questions
Compare Companies
IDE
Online IDE
Collaborative IDE

Segmentation in Operating System (OS) | Core Computer Science

Ujjwal Abhishek
Ujjwal Abhishek

What is Segmentation?

Segmentation is another memory management technique that gives the user's view of a process. The user's view is mapped into the Physical Memory.

In Segmentation, a process is divided into multiple segments. The size of each segment is not necessarily the same which is different from paging. In Paging, a process was divided into equal partitions called pages. The module contained in a segment decides the size of the segment.

Why Segmentation is needed?

We used Paging as one of the memory management techniques. In Paging, the process was divided into equal-sized pages irrespective of the fact that what is inside the pages. It also divides some relative parts of a process into different pages which should be loaded on the same page. It decreases the efficiency of the system and doesn't give the user's view of a process.

In Segmentation, similar modules are loaded in the same segments. It gives the user's view of a process and also increases the efficiency of the system as compared to Paging.

Types of Segmentation

There are two types of Segmentation. These are:

  1. Simple Segmentation - In Simple Segmentation, each process is divided into multiple segments and all of them are loaded into the memory at run time. They can be at non-contagious locations.
  2. Virtual Memory Segmentation - In Virtual Memory Segmentation, each process is divided into multiple segments and all of them do not reside at one point at a time.

Segment Table

  • Segment Table stores the information about all the segments of a process.
  • It helps in the mapping of the two-dimensional logical addresses to the physical addresses.
  • It is stored in the main memory.
  • There are two entries in the Segment Table.
  1. Base Address - It is the starting physical address of the particular segment inside the main memory.
  2. Limit - It denotes the size of a particular segment.

Translation of Logical Address into Physical Address

The CPU generates the logical address which consists of two parts:

  1. Segment Number(s) - It is the number of bits required to represent a Segment. It is used as an index in the Segment Table.
  2. Segment Offset(d) - It is the number of bits required to represent the size of a Segment.

Segment Number from the Segment Table gives the base address of a Segment in the main memory and Segment Offset gives the size of that Segment. These two together give the Physical Address of a Segment in the memory. If Offset(d)<Limit then the segment is fetched from the memory else there is an error. 

Advantages of Segmentation

  • There is no Internal Fragmentation.
  • It gives the user's view of a process.
  • It helps in dividing a program into similar modules which are called segments.
  • Segment Table consumes less space than Page Table.

Disadvantages of Segmentation 

  • When Process is removed from the memory, it breaks memory into small pieces which leads to External Fragmentation.

 

Ujjwal Abhishek
Ujjwal Abhishek
Ujjwal is final-year CSE Undergraduate, a competitive coder, and a web developer passionate about problem-solving and data structures and algorithms.
SDE Bootcamp - Become a software engineer at a product-based company
Practice Data Structures & Algorithms
Learning Resources
Interview Prep Resources
Community
Join our community
Blog
  • Career Advice and Roadmaps
  • Data Structures & Algorithms
  • Machine Coding Round (LLD)
  • System Design & Architecture
  • Backend Development
  • Frontend Development
  • Awesome Project Ideas
  • Core Computer Science
Practice Questions
  • Machine Coding (LLD) Questions
  • System Design (HLD) Questions
  • Topic-wise DSA Questions
  • Company-wise DSA Questions
  • DSA Sheets (Curated Lists)
  • JavaScript Interview Questions
  • Frontend UI Machine Coding Questions
Online Compilers (IDE)
  • Online Java Compiler
  • Online C++ Compiler
  • Online C Compiler
  • Online Python Compiler
  • Online JavaScript Compiler
Topic-wise Problems
  • Dynamic Programming Interview Questions
  • Linked List Interview Questions
  • Graph Interview Questions
  • Backtracking Interview Questions
  • Arrays Interview Questions
  • Trees Interview Questions
Company-wise Problems
  • Amazon Interview Questions
  • Microsoft Interview Questions
  • Google Interview Questions
  • Flipkart Interview Questions
  • Adobe Interview Questions
  • Facebook Interview Questions
DSA Sheets (Curated Lists)
  • Top Interview Questions
  • FAANG Interview Questions
  • Most Asked Interview Questions
  • 6 month DSA Practice Sheet
  • 3 month DSA Practice Sheet
  • Last minute DSA Practice Sheet