You are on page 1of 19

Segmentation Technique in Operating System

Atul Harsha
Senio r Manager Co ntent

Updated on Oct 13, 2023 13:32 IST


Have you ever found yourself tapping your fingers impatiently while your computer
takes its sweet time to load a program or file? It’s a common problem that many of
us face, and it makes us wonder: isn’t there a better way for computers to handle
tasks more quickly and smoothly?
Well, there might be a solution in the form of “Segmentation in Operating Systems”.
But what is segmentation, and how can it help solve the slow-downs we often
experience with our computers? Think of it as a smart organizer in your computer
that breaks down information into smaller, easy-to-handle pieces, making it quicker
to find and use what it needs.

In this article, we will learn about the concept of segmentation in Operating system.
It is a fundamental yet often overlooked aspect that plays helps in enhancing
computer performance. Just as we categorize different files in separate folders for

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
easy access, segmentation technique works behind the scenes to organize data
and programs into distinct sections, facilitating quicker access and optimized
performance.

For computer grads like you, understanding Segmentation technique can be a


game-changer in grasping how operating systems can be fine-tuned to function
more efficiently. Let’s take a closer look at segmentation, a simple strategy that is
essential in computing. Let’s explore how segmentation works and how it makes the
operating systems more efficient.

Must Check: History of Operating Systems

Explore Interprocess Communication in Operating System

Table of contents
Introduction to Segmentation T echnique

What is Segmentation in OS?

Why is Segmentation required?

Difference between paging and Segmentation with example

T abular Comparison of Paging vs Segmentation

Disadvantages of using segmentation

How Does Segmentation Work?

Key Concepts related to Working of Segmentation in OS

T ranslation of Logical address into physical address by segment table

Step by Step working of Segmentation in OS

Segmentation T echnique in different OS

Segmentation Example

Introduction to Segmentation Technique

In the computing world, the efficiency of an operating system is often dictated by

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
how well it manages memory. Segmentation is a technique that plays a pivotal role
in this aspect. Segmentation is a memory management technique whereby data
items are stored in segments on the storage media. It divides the process or user-
accessible space into fixed-sized blocks, called segments. To understand this better,
let’s draw a parallel with the product categorization system in the Amazon app.

Amazon App: Bef ore Implement at ion of Product Cat egorizat ion

Imagine logging into the Amazon app where all products – electronics, clothing,
groceries, and books – are all mixed up without any categorization or filtering
options. As a user, you would find it:
Extremely challenging to locate the specif ic product you want.

T ime-consuming to browse through a jumble of unrelated products.

Frustrating, as the user experience would be f ar f rom smooth and ef f icient.

This scenario is similar to a computer system without segmentation, where data and
programs are scattered randomly across the memory, making it a herculean task for

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
the operating system to manage and allocate memory efficiently.

Implement ing Product Cat egorizat ion: The Amazon App Transf ormat ion

To enhance user experience and efficiency, Amazon implements product


categorization, akin to segmentation in operating systems. Now, products are
organized into various categories, such as:
Electronics: Where you can f ind all gadgets and electronic appliances

Clothing: A section dedicated to apparel, shoes, and accessories

Groceries: Where you can quickly locate daily essentials and f ood items

Books: A segment that houses a vast collection of literature across genres

This structured approach not only makes it easier for users to find what they are
looking for but also optimizes the space, avoiding clutter and enhancing the overall
user experience.

Segment at ion in Operat ing Syst ems: The Technical Parallel

In the context of operating systems, segmentation functions in a similar manner. It


divides the memory into different segments, each designated for a specific type of
data or program. This organized setup:
Facilitates Quicker Access: Helps in locating and managing data more swif tly.

Prevents Memory Wastage: Avoids f ragmentation and optimizes memory space usage.

Enhances Performance: Boosts the overall perf ormance of the computer by


streamlining operations.

Just as product categorization in the Amazon app revolutionized online shopping by


offering a streamlined and efficient browsing experience, segmentation in operating
systems serves as a vital tool in enhancing computer performance by organizing
memory in a structured and efficient manner.

What is Segmentation in OS?


Segmentation divides memory into logical chunks called segments.

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Each segment has a unique identif ier called a segment number.

T he segment number is used to locate the segment in memory.

T he operating system uses segment tables to store the inf ormation about each segment.

Segment protection prevents one program f rom accessing the segments of another
program.

Segment sharing allows multiple programs to share the same segment.

Segmentation can be used to implement virtual memory.

Segmentation is a memory management technique that divides an application’s


virtual address space into distinct sections or chunks.

By splitting the memory into different sections, the operating system can quickly
figure out which parts are being used and which ones are free. This neat
arrangement makes it much faster and easier to give out and take back memory
space for the system. Interestingly, these memory sections are not all the same size
and don’t sit side by side. Due to this flexible setup, there’s no wasted space in
these sections. This problem is often referred to as ‘ internal fragmentation ‘. The
size of each little section is chosen based on what job it has in a specific program.

Let’s understand this with a simple example:

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Imagine you are organizing a large bookshelf, where each shelf represents a
segment of memory. Instead of placing books randomly on the shelves (memory),
you decide to organize them based on categories like fiction, non-fiction, science,
and history. Each category represents a segment.

In the context of an operating system:


Fiction Shelf (Code Segment): T his is where all the executable instructions of a
program are stored, similar to a collection of f iction books that tell dif f erent stories
(programs).

Non-Fiction Shelf (Data Segment): T his shelf stores the global variables and static
data, akin to a non-f iction section that contains f actual inf ormation (data) that the
stories (programs) might ref er to.

Science Shelf (Stack Segment): T his segment is like a science shelf , where new
books (data) are added and removed f requently. It operates in a Last-In-First-Out (LIFO)
manner, storing local variables and f unction inf ormation.

History Shelf (Heap Segment): T his is a f lexible space, similar to a history section
where books (data) can be added or removed as needed. It is used f or dynamic memory
allocation, where variables are allocated and deallocated at runtime.

So, when a program runs, it knows exactly where to find the necessary instructions
and data, just like how you can easily find a book in the organized bookshelf. This
not only makes the memory usage more efficient but also speeds up the program
execution, enhancing your computer’s overall performance.

Why is Segmentation Technique Required?

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Benefit Before Segmentation After Segmentation

Enhanced A large program is treated as a T he program is divided into smaller,


organization single entity. more manageable segments.

T he operating system needs T he operating system can quickly


Ef f iciency and to search the entire memory identif y the segment that contains the
speed space to f ind a particular piece data and then locate the data within the
of data. segment.

Flexible All programs are allocated the


Programs are allocated memory
memory same amount of memory,
according to their needs.
usage regardless of their needs.

Prevention of
Internal f ragmentation occurs Internal f ragmentation is prevented or
internal
f requently. minimized.
f ragmentation

Improved Memory allocation and


Memory allocation and deallocation is
system deallocation is slow and
f aster and more ef f icient.
perf ormance inef f icient.

Enhanced Programs are isolated f rom each other,


Programs can access each
security and preventing unauthorized access or
other’s memory.
isolation alterations.

Segmentation is a memory management technique that divides a program into


modules, called segments. This is unlike paging, which divides a program into pages.
Segments can be of different sizes and can be loaded into memory independently.
Segmentation can help to prevent internal fragmentation, which is when free
memory is not large enough to accommodate a requesting process.

Also read: Real-time operating system

Must explore: Distributed operating system

Dif f erence Between Paging and Segmentation with Example

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Some of you might be confused about the difference between segmentation and
paging. Let me clear that up.

The first figure above depicts the paging concept. In paging, a program is divided
into fixed-size pages. These pages are then stored in the main memory. The second
figure depicts the segmentation concept. In segmentation, a program is divided into
variable-sized segments. These segments can be loaded into the main memory
independently.

Segmentation allows users to partition their programs into modules. These modules

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
are independent pieces of code that can be loaded into memory as needed. This
can improve the performance of a program by reducing the amount of time that the
operating system spends searching for the code that it needs.

Here are some other key differences between segmentation and paging:
Segmentation is a logical view of memory, while paging is a physical view of
memory. T his means that segments are def ined by the programmer, while pages are
def ined by the operating system.

Segments can be of different sizes, while pages are always the same size. T his
allows segmentation to better f it the needs of the program, while paging can lead to
internal f ragmentation.

Segments can be loaded into memory independently, while pages must be loaded
in blocks. T his allows segmentation to be more ef f icient, while paging can lead to
external f ragmentation.

Tabular Comparison of Paging vs Segmentation

Feature Paging Segmentation Example

A word processing
program with a small
Systems with a memory f ootprint would
Systems with a large
small amount of be a good candidate
amount of memory to
Usage memory to prevent f or paging. A database
provide better
external program with a large
security and f lexibility.
f ragmentation. memory f ootprint would
be a good candidate
f or segmentation.

T he program is T he program is
divided into pages divided into segments
A program that is 100
and stored in the and stored in the
pages long is divided
main memory. When secondary memory.
into 4KB pages in
the program needs When the program
paging. In
Working to access a page, needs to access a
segmentation, the
the operating segment, the
program is divided into
system transf ers it operating system
3 segments: code, data,
f rom the secondary transf ers it f rom the
and stack.

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
f rom the secondary transf ers it f rom the
and stack.
memory to the main secondary memory to
memory. the main memory.

In paging, the page size


is typically 4KB. In
Page size Fixed Variable segmentation, the
segment size can be
any size.

In paging, all pages of a


process must be
loaded into memory
Loading of bef ore the process can
Dependent Independent
pages be executed. In
segmentation, pages
can be loaded into
memory independently.

Paging can lead to


internal f ragmentation
because a f ree page
may not be large
enough to
Prevention of
accommodate a
internal No Yes
requesting page.
fragmentation
Segmentation can
prevent internal
f ragmentation because
segments can be of
dif f erent sizes.

Paging can prevent


external f ragmentation
because pages are
loaded into memory in
Prevention of
blocks. Segmentation
external Yes No
cannot prevent external
fragmentation
f ragmentation because
segments can be
loaded into memory
independently.

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
independently.

T he memory
management overhead
Memory
in paging is lower than
management Lower Higher
in segmentation
overhead
because paging is a
simpler technique.

Paging cannot provide


as much security as
segmentation because
Security Lower Higher
segments can be
loaded into memory
independently.

Paging is less f lexible


than segmentation
Flexibility Lower Higher because pages must be
loaded into memory in
blocks.

Paging is f aster than


Performance Faster Slower segmentation because
it is a simpler technique.

Read more: Difference between Paging and Segmentation

Also read: What is Operating Systems (OS) – T ypes, Functions, and Examples.

Int erprocess Communicat ion in Operat ing Syst em


Pro cesses in o perating system needs to co mmunicate with each o ther.That is
called Interpro cess co mmunicatio n.If yo u want to kno w mo re abo ut it then read
this article which will co ver different types...re ad m o re

CPU Scheduling Algorit hm: Operat ing Syst em


Scheduling o f pro cesses is very impo rtant thing in an o perating system.We have
co vered impo rtant CPU Scheduling Algo rithms in this article, with so lved
examples and pro per explanatio n.

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Funct ions of Operat ing Syst em
Operating system is an interface between hardware and so ftware applicatio ns.
This article will tell yo u abo ut o perating system and its functio ns.

How Does Segmentation Work?

Segmentation is a memory management technique that divides the process address


space into variable-sized segments. The CPU generates logical addresses that are
references to these segments. To access a memory location within a segment, the
CPU must first translate the logical address into a physical address. This is done by
looking up the segment number in the segment table. The segment table is a data
structure that maps segment numbers to physical addresses. The physical address
is then calculated by adding the base address of the segment from the segment
table to the offset within the segment.

Key Concepts related to Working of Segmentation in OS

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Concept Description

Segment A unique identif ier f or a memory segment. It is used to locate the memory
number segment in the segment table.

Segment T he number of bytes in a memory segment. It is used to determine the range


size of addresses that can be used to access the memory segment.

Logical A virtual address that is generated by the CPU. It is not a physical address,
address but rather a ref erence to a memory segment.

A data structure that maps segment numbers to physical addresses. It is used


Segment
by the CPU to f ind the physical address of a memory segment given its
table
segment number.

Main T he physical memory of a computer. It is where the CPU stores data and
memory instructions.

An error can occur if the logical address is invalid or if the segment table is
Error
corrupt.

T he starting address of a memory segment in main memory. It is used to


Base
calculate the physical address of a memory location within the memory
address
segment.

T he distance f rom the base address of a memory segment to the desired


Of f set memory location. It is used to calculate the physical address of the memory
location.

NOT E: The base address is the starting address of a memory segment in main
memory. It is used to calculate the physical address of a memory location within the
memory segment.

Translation of Logical address into physical address by segment


table

Problem: The segment table for a process has 16 entries, each of which is 4 bytes
long. The logical address space of the process is 2^32 bytes. The segment table is
located at physical address 0x1000. The logical address is 0x12345678.

Solution:

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
T he segment number f or the logical address is 0x12.

T he of f set f or the logical address is 0x345678.

T he physical address of the segment is f ound by multiplying the segment number by the
size of a segment table entry, which is 4 bytes. In this case, the physical address of the
segment is 0x12 * 4 = 0x48.

T he physical address of the memory location is f ound by adding the of f set to the
physical address of the segment. In this case, the physical address of the memory
location is 0x48 + 0x345678 = 0x345726.

Here how the translation process is done:

Copy code

Logical address: 0x12345678


Segment number: 0x12
Of f set : 0x345678
Segment t able: 0x1000
Segment t able ent ry size: 4 byt es
Physical address of segment : 0x12 * 4 = 0x48
Physical address of memory locat ion: 0x48 + 0x345678 = 0x345726

Step by Step working of Segmentation in OS

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Step Description

1.CPU generates T he logical address is a virtual address that is generated by the CPU.
a logical It is not a physical address, but rather a ref erence to a memory
address. segment.

2. Logical
address is T he segment number identif ies the memory segment that the logical
divided into two address ref ers to. T he of f set identif ies the specif ic location within the
parts: the memory segment. T he of f set depicts the distance f rom the base
segment number address of the segment to the desired memory location. T he size of
and the of f set the segment is stored in the segment table.
(d).

3. CPU looks up T he segment table is a data structure that maps segment numbers to
the segment physical addresses. T he CPU uses the segment table to f ind the
number in the physical address of the memory segment that the logical address
segment table. ref ers to.

4. CPU adds the


of f set to the
T he base address is added to the of f set to get the f inal physical
base address of
address of the memory location that the logical address ref ers to.
the memory
segment.

5. CPU checks if T he CPU checks if the of f set is less than or equal to the limit of the
d<=limit. segment. If it is not, then an error is generated.

6. T he CPU
accesses the
memory location T he CPU now has the physical address of the memory location that
at the f inal the logical address ref ers to. It can now access this memory location
physical
address.

NOT E: The concept of d<=limit means that the offset must be less than or equal to
the limit of the segment. This is to ensure that the CPU does not access memory
that is outside of the segment.

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Process Management in Operat ing Syst em
There are different pro cesses in o perating system.So there is need to manage
them pro perly.This article will tell yo u ho w an o perating system manages
different pro cesses.

Process Scheduling: Operat ing Syst em


This article includes to pics like pro cess scheduling,different types o f schedulers
and their co mpariso n

Operat ing Syst em Int erview Quest ions


In this article yo u will find impo rtant o perating system questio ns which are
likeable to be asked in interview.

Segmentation Technique in dif f erent OS

OS Segment table Memory management

Each process has its own T he operating system uses the segment table
Microsof t segment table, which maps to keep track of which parts of memory are
Windows segment numbers to being used by each process and to prevent
physical addresses. conf licts between processes.

T he segment table is not T his allows Linux to save space in memory and
Linux stored in memory. Instead, to make it easier to move processes between
it is stored in a f ile on disk. dif f erent computers.

Each application has its T his allows the operating system to keep track
own segment table, which of which parts of memory are being used by
Android
maps segment numbers to each application and to prevent conf licts
physical addresses. between applications.

T he segment table is
stored in a special area of T his allows the operating system to have more
macOS
memory called the kernel control over the memory of each process.
space.

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Segmentation Example

Let’s see and understand how PUBG used the concept of segmentation during their
development:

In PUBG, each player has their own process. The process contains the code and
data for the player’s character, as well as the game environment that the player is
currently in.

The operating system uses the segment table to keep track of the physical
addresses of the code, data, and game environment segments for each player
process. When a player tries to access a memory location, the operating system
looks up the segment number in the segment table. The segment table then tells
the operating system the physical address of the memory location.

For example, let’s say a player is trying to access the memory location where the
player’s character’s health is stored. The operating system looks up the segment
number for the player’s character’s data segment in the segment table. The
segment table tells the operating system that the physical address of the memory
location is 0x1000.

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
The operating system then transfers the data from the memory location with the
physical address 0x1000 to the CPU. The CPU can then read the player’s health
from the memory.

This is just a simple example of how games like PUBG can use segmentation. In
reality, the process of segmentation is much more complex.

Segmentation is a powerful memory management technique for improving the


performance and security of games. In PUBG, segmentation can be used to:

Protect dif f erent parts of the game f rom each other. For example, the operating system
can use segmentation to prevent a player f rom accessing the code f or another player’s
character.

Handle memory sharing between dif f erent players. For example, the operating system can
use segmentation to allow two players to share the same game environment.

Allocate large, contiguous blocks of memory f or games that need it. For example, a game
that uses a lot of 3D graphics may need to allocate large, contiguous blocks of memory
f or the textures and models.

Improve the perf ormance of memory access. For example, the operating system can use
segmentation to cache f requently accessed memory locations in the CPU’s memory
cache.

Conclusion

Segmentation is a memory management technique that divides the process address


space into variable-sized segments. This allows the operating system to better
manage its memory use and improve the performance of the system. For example,
segmentation can be used to:
Allocate large, contiguous blocks of memory f or programs that need it.

Protect dif f erent parts of the memory f rom each other.

Handle memory sharing between dif f erent processes.

Segmentation is a powerful memory management technique that can be used to


improve the performance of an operating system. If you liked this article, please
share it with your friends.

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Happy Learning!!!

Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.

You might also like