Professional Documents
Culture Documents
Atul Harsha
Senio r Manager Co ntent
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.
Table of contents
Introduction to Segmentation T echnique
Segmentation 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.
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.
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
Groceries: Where you can quickly locate daily essentials and f ood items
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.
Prevents Memory Wastage: Avoids f ragmentation and optimizes memory space usage.
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 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.
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.
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.
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.
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
Prevention of
Internal f ragmentation occurs Internal f ragmentation is prevented or
internal
f requently. minimized.
f ragmentation
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.
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.
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.
Also read: What is Operating Systems (OS) – T ypes, Functions, and Examples.
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.
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.
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.
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.
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.
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 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.
Copy code
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.
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.
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.
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
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.