Segmentation and Paged Segmentation in OS: Working, Examples and Differences
Segmentation becomes confusing when students try to learn it exactly like paging. In paging, a process is divided into equal-size pages. Segmentation follows a completely different idea.
A program naturally contains different logical parts such as code, data, heap and stack. Segmentation keeps these logical parts separate and calls each part a segment.
Paged Segmentation combines both ideas: first divide the program into logical segments and then divide every segment into fixed-size pages.
Segmentation is a memory management technique in which a process is divided into variable-size logical units called segments. Each segment has a base address and a limit. A logical address contains a segment number and an offset.
Paged Segmentation combines segmentation and paging. A program is first divided into logical segments, and each segment is then divided into equal-size pages. The address therefore contains a segment number, page number and offset.
Why Does Segmentation Feel Difficult?
The concept itself is not difficult. The confusion usually comes from mixing segmentation with paging.
Segmentation = Divide program by meaning
Paging = Divide program by equal size
Paged Segmentation = Divide by meaning first, then divide each segment into equal-size pages
What Is Segmentation in Operating System?
A program is not one meaningless block. It contains several logical parts.
For example:
- Program instructions or code
- Global and static data
- Heap
- Stack
- Different procedures or modules
Segmentation treats these logical parts as separate memory units.
Segmentation is a memory management technique in which a process is divided into variable-size logical units called segments. Each segment represents a meaningful part of the program.
How a Program Is Divided Into Segments
Segments Can Have Different Sizes
This is one of the biggest differences between paging and segmentation.
There is no rule saying that all four segments must have the same size.
What Is a Segment Table?
Since each segment may be stored at a different physical memory location, the operating system needs a table that tells where each segment begins and how large it is.
This table is called the Segment Table.
A Segment Table stores information about each segment, mainly its Base Address and Limit.
What Do Base and Limit Mean?
Base tells where the segment starts in physical memory.
Limit tells the size of the valid address range inside that segment.
Logical Address in Segmentation
A logical address in segmentation contains two parts:
- Segment Number
- Offset
Segment Number
Tells which logical segment contains the required address.
Offset
Tells the position inside that segment.
How Address Translation Works in Segmentation
Logical Address to Physical Address
Segmentation Address Translation Solved Example
Given
Logical address:
Segment Table entry for Segment 1:
Step 1: Check the Offset
Offset is 450 and limit is 700.
Step 2: Calculate Physical Address
Physical Address = 4450
Invalid Segment Address Example
Suppose:
First check the offset.
The operating system must reject this access instead of calculating a normal physical address.
Segmentation Address Calculator
Enter the base, limit and offset for a segment.
Fragmentation in Segmentation
Segments have variable sizes. This allows memory to match logical program units more naturally.
But variable-size memory allocation creates an important problem: External Fragmentation.
Simple Example
Total free memory:
Now suppose a segment requires 200 KB continuously.
The request may fail because the largest single hole is only 120 KB.
Advantages and Disadvantages of Segmentation
Advantages
- Matches the logical structure of a program.
- Code, data and stack can be managed separately.
- Protection can be applied segment by segment.
- Sharing specific segments can be easier.
- Different segments can grow independently.
Disadvantages
- External fragmentation can occur.
- Variable-size allocation is more difficult to manage.
- Compaction may sometimes be needed.
- Segment table adds management overhead.
Protection and Sharing in Segmentation
Segmentation is useful because each logical unit can be protected separately.
For example:
- Code segment may be read-only.
- Data segment may allow read and write access.
- Stack may remain private to a process.
- A shared library segment may be shared between processes.
What Is Paged Segmentation?
Segmentation gives a program a meaningful logical structure, but variable-size segments can cause external fragmentation.
Paging avoids external fragmentation by using equal-size pages and frames.
Paged Segmentation combines both ideas.
Paged Segmentation is a memory management technique in which a process is first divided into logical segments and each segment is then divided into fixed-size pages.
Logical Address in Paged Segmentation
Because we now have both segments and pages, the logical address needs three parts.
Page Number tells which page inside that segment.
Offset tells the exact position inside the page.
How Paged Segmentation Works Step by Step
- CPU generates a logical address containing segment number, page number and offset.
- Segment number selects an entry in the segment table.
- The segment-table entry identifies the page table belonging to that segment.
- Page number selects an entry in that page table.
- The page-table entry gives the physical frame number.
- The offset remains unchanged.
- Frame number and offset produce the final physical address.
Simple Paged Segmentation Mapping
Code
Data
Stack
Paged Segmentation Solved Example
Given
Segment 1 has its own page table.
Suppose the page table contains:
Step 1: Select Segment
Segment Number = 1.
Therefore, use the page table belonging to Segment 1.
Step 2: Select Page
Page Number = 2.
Step 3: Calculate Physical Address
Physical Address = 6444
Why Combine Paging and Segmentation?
Segmentation gives us logical program organization.
Paging gives us fixed-size physical allocation.
Paged Segmentation tries to get advantages from both.
Fragmentation in Paged Segmentation
Pure segmentation can suffer from external fragmentation because segments are variable-sized continuous memory blocks.
In paged segmentation, each segment is divided into fixed-size pages. These pages are placed into frames.
Memory Overhead in Paged Segmentation
Paged Segmentation improves flexibility, but it requires more translation information.
The system may need:
- A Segment Table
- A separate Page Table for each segment
- Additional address translation steps
- Hardware support for efficient translation
Segmentation vs Paging vs Paged Segmentation
| Basis | Segmentation | Paging | Paged Segmentation |
|---|---|---|---|
| Division | Program divided into logical segments | Program divided into fixed-size pages | Program divided into segments, then pages |
| Block Size | Variable | Fixed | Segments variable, pages fixed |
| Logical Meaning | High | Pages do not represent logical program units | Logical segments are preserved |
| Address Format | Segment Number + Offset | Page Number + Offset | Segment Number + Page Number + Offset |
| Main Table | Segment Table | Page Table | Segment Table and Page Tables |
| External Fragmentation | Can occur | Avoided | Avoided in physical frame allocation |
| Internal Fragmentation | Generally not caused by fixed block size | Can occur | Can occur in last page of a segment |
| Physical Allocation | Each segment needs a continuous physical area | Pages can occupy separate frames | Pages of each segment can occupy separate frames |
| Protection | Natural segment-level protection | Page-level protection | Segment-level logic with page-level allocation |
| Complexity | Moderate | Moderate | Higher because two levels are involved |
Segmentation vs Paging in the Simplest Possible Way
What logical part of the program is this?
Code? Data? Stack? Heap?
Which equal-size page is this and which frame contains it?
Which segment?
Which page inside that segment?
Which physical frame?
Common Student Confusions
Are segments fixed in size?
No. Different segments can have different sizes.
Is Segment 1 always stored after Segment 0?
No. Different segments may be placed at different physical memory locations.
Is offset checked against limit?
Yes. In pure segmentation, the offset must be inside the valid limit of the selected segment.
Does Segmentation have external fragmentation?
Yes. Variable-size segments can create scattered free holes.
Does Paged Segmentation use a Page Table?
Yes. Each segment can have its own page table.
Does Paged Segmentation need a Segment Table too?
Yes. The segment table helps identify information about the selected segment, including the page table associated with it.
Does Paged Segmentation completely remove memory waste?
No. It avoids the external-fragmentation problem of pure segmentation, but internal fragmentation can still occur in the final page of a segment.
One-Minute Revision
Segmentation and Paged Segmentation Exam Preparation
2-Mark Segmentation Definition
Segmentation is a memory management technique in which a process is divided into variable-size logical units called segments.
2-Mark Paged Segmentation Definition
Paged Segmentation combines segmentation and paging by dividing a process into logical segments and then dividing every segment into fixed-size pages.
Segment Table Short Answer
A Segment Table stores information about each segment, mainly the segment's base address and limit.
Segmentation Address Translation
Paged Segmentation Address Translation
For a 5-Mark Answer
- Define segmentation.
- Explain logical segments.
- Explain segment table.
- Explain Base and Limit.
- Show one address translation example.
For a 10-Mark Answer
- Introduction to segmentation.
- Logical view of a program.
- Code, data, heap and stack segments.
- Segment Table.
- Base and Limit.
- Logical address format.
- Address translation steps.
- Solved numerical example.
- External fragmentation.
- Advantages and disadvantages.
- Meaning of Paged Segmentation.
- Segment Table and Page Tables.
- Paged Segmentation address format.
- Paged Segmentation translation.
- Difference from Paging and pure Segmentation.
Frequently Asked Questions
What is Segmentation in Operating System?
Segmentation is a memory management technique in which a process is divided into variable-size logical units called segments.
What is a Segment Table?
A Segment Table stores information about every segment, mainly its base physical address and limit.
What is Base in Segmentation?
Base is the starting physical address of a segment in memory.
What is Limit in Segmentation?
Limit defines the valid size or address range inside a segment.
What is the Logical Address Format in Segmentation?
A logical address in segmentation contains a segment number and an offset.
How is Physical Address Calculated in Segmentation?
The offset is first checked against the segment limit. If the address is valid, physical address is calculated as Segment Base plus Offset.
What Fragmentation Occurs in Segmentation?
Pure segmentation can suffer from external fragmentation because segments have variable sizes.
What is Paged Segmentation?
Paged Segmentation divides a program into logical segments and then divides each segment into fixed-size pages.
What is the Address Format in Paged Segmentation?
The logical address contains Segment Number, Page Number and Offset.
What is the Main Difference Between Segmentation and Paged Segmentation?
Pure segmentation allocates variable-size segments, while Paged Segmentation divides every segment into fixed-size pages that can be placed into physical frames.
Conclusion
Segmentation organizes a process according to its logical structure. Instead of cutting a program into equal-size blocks, it divides the program into meaningful parts such as code, data, heap and stack.
Every segment has information such as a Base Address and Limit. The logical address contains a segment number and an offset.
The operating system first checks whether the offset is valid. If it is valid, physical address is calculated by adding the offset to the segment base.
Pure segmentation can suffer from external fragmentation.
Paged Segmentation solves this problem differently. The program is still divided into logical segments, but every segment is further divided into fixed-size pages.
Address translation therefore becomes a two-level process: first select the segment and then select the page inside that segment.
Segmentation = Logical Parts
Segment Address = Segment Number + Offset
Segment Table = Base + Limit
Physical Address = Base + Offset
Pure Segmentation = External Fragmentation Possible
Paged Segmentation = Segment → Pages → Frames
Paged Segmentation Address = Segment Number + Page Number + Offset
