Segmentation & Paged Segmentation in OS: Working, Examples & Differences

OPERATING SYSTEM - CHAPTER 23

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.

Quick Answer:

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?

Segmentation & Paged Segmentation in OS: Working, Examples & Differences

The concept itself is not difficult. The confusion usually comes from mixing segmentation with paging.

1
Segments Are Not Equal Code, data, heap and stack can have different sizes.
2
Base and Limit Every segment has its own starting physical address and valid size.
3
Paged Segmentation Adds Pages Each segment is divided again into pages, creating one more level of address translation.
Easy Memory Trick:

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.

Simple Definition:
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

Logical Process
Segment 0 - Code
Segment 1 - Data
Segment 2 - Heap
Segment 3 - Stack
→
Physical Memory
Free Space
Segment 3 - Stack
Free Space
Segment 0 - Code
Segment 1 - Data
Free Space
Segment 2 - Heap
Different segments of the same process do not have to be stored next to each other in physical memory.

Segments Can Have Different Sizes

This is one of the biggest differences between paging and segmentation.

Code Segment = 18 KB Data Segment = 7 KB Heap Segment = 11 KB Stack Segment = 5 KB

There is no rule saying that all four segments must have the same size.

In segmentation: Segment sizes can be different.
In paging: all pages use the same fixed page 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.

Simple Definition:
A Segment Table stores information about each segment, mainly its Base Address and Limit.
Segment
Base
Limit
0
1200
500
1
4000
700
2
7600
350
3
9000
600

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:

  1. Segment Number
  2. Offset
Segmentation Logical Address
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

SEGMENTATION ADDRESS TRANSLATION

Logical Address to Physical Address

Segment Number + Offset
→
Find Segment Table Entry
→
Check Offset Against Limit
→
Physical Address = Base + Offset
STEP 1 Select Segment
Use Segment Number to select table entry
STEP 2 Check Limit
Offset must be smaller than Limit
STEP 3 Physical Address
Physical Address = Base + Offset

Segmentation Address Translation Solved Example

Given

Logical address:

Segment Number = 1 Offset = 450

Segment Table entry for Segment 1:

Base = 4000 Limit = 700

Step 1: Check the Offset

Offset is 450 and limit is 700.

450 is smaller than 700 Therefore: Address is valid.

Step 2: Calculate Physical Address

Physical Address = Base + Offset = 4000 + 450 = 4450
Final Answer:
Physical Address = 4450

Invalid Segment Address Example

Suppose:

Segment Number = 2 Base = 7600 Limit = 350 Offset = 400

First check the offset.

Offset = 400 Limit = 350 400 is not smaller than 350
The address is invalid because the requested offset is outside the valid size of Segment 2.

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.

Segmentation Translation Lab

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.

External fragmentation happens when enough total free memory exists, but that memory is divided into separate small holes.

Simple Example

Free Hole 1 = 100 KB Free Hole 2 = 80 KB Free Hole 3 = 120 KB

Total free memory:

100 + 80 + 120 = 300 KB

Now suppose a segment requires 200 KB continuously.

The request may fail because the largest single hole is only 120 KB.

Segmentation can suffer from external fragmentation because segments are variable in size.

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.
Segmentation provides protection at a logical program-unit level.

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.

Simple Definition:
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.
PAGED SEGMENTATION STRUCTURE
Process
→
Segments
→
Pages Inside Each Segment
Example: The Code Segment may contain Pages 0, 1 and 2. The Data Segment may contain Pages 0 and 1. Every segment can have its own page table.

Logical Address in Paged Segmentation

Because we now have both segments and pages, the logical address needs three parts.

Paged Segmentation Logical Address
Segment Number
Page Number
Offset
Segment Number tells which segment.

Page Number tells which page inside that segment.

Offset tells the exact position inside the page.

How Paged Segmentation Works Step by Step

TWO-LEVEL ADDRESS TRANSLATION
Segment Number
→
Segment Table
→
Page Table of Selected Segment
→
Frame Number + Offset
  1. CPU generates a logical address containing segment number, page number and offset.
  2. Segment number selects an entry in the segment table.
  3. The segment-table entry identifies the page table belonging to that segment.
  4. Page number selects an entry in that page table.
  5. The page-table entry gives the physical frame number.
  6. The offset remains unchanged.
  7. Frame number and offset produce the final physical address.

Simple Paged Segmentation Mapping

EXAMPLE
Segment 0
Code
→
Page Table 0
→
Frames 3, 7, 9
Segment 1
Data
→
Page Table 1
→
Frames 4, 9, 6
Segment 2
Stack
→
Page Table 2
→
Frames 2, 12

Paged Segmentation Solved Example

Given

Segment Number = 1 Page Number = 2 Offset = 300 Page Size = 1024 bytes

Segment 1 has its own page table.

Suppose the page table contains:

Page 0 → Frame 4 Page 1 → Frame 9 Page 2 → Frame 6

Step 1: Select Segment

Segment Number = 1.

Therefore, use the page table belonging to Segment 1.

Step 2: Select Page

Page Number = 2.

Page 2 → Frame 6

Step 3: Calculate Physical Address

Physical Address = Frame Number × Page Size + Offset = 6 × 1024 + 300 = 6144 + 300 = 6444
Final Answer:
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.

L
Logical Structure Program can still be divided into code, data, stack and other segments.
P
Paging Inside Segments Every segment is divided into equal-size pages.
M
Flexible Memory Placement Pages can be placed into free physical frames.

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.

This removes the need to place an entire segment inside one large continuous physical-memory block and therefore avoids the external fragmentation problem associated with pure segmentation.
Paged Segmentation can still have internal fragmentation, especially in the last page of a segment.

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
Paged Segmentation is more flexible than pure segmentation, but its address translation mechanism is also more complex.

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

Segmentation asks:
What logical part of the program is this?

Code? Data? Stack? Heap?
Paging asks:
Which equal-size page is this and which frame contains it?
Paged Segmentation asks both:

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 Divides a process into logical variable-size units.
Segment A logical part such as code, data, heap or stack.
Segment Table Stores Base and Limit information for segments.
Segmentation Address Segment Number + Offset.
Physical Address Base + Offset after a valid limit check.
External Fragmentation Can occur in pure segmentation.
Paged Segmentation Each logical segment is divided into pages.
Paged Address Segment Number + Page Number + Offset.
Two-Level Mapping Segment Table → Page Table → Frame.

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

Logical Address = Segment Number + Offset Check: Offset must be smaller than Segment Limit Physical Address = Segment Base + Offset

Paged Segmentation Address Translation

Logical Address = Segment Number + Page Number + Offset Segment Number → Segment Table Page Number → Page Table of selected segment Page Table → Frame Number Physical Address = Frame Number × Page Size + Offset

For a 5-Mark Answer

  1. Define segmentation.
  2. Explain logical segments.
  3. Explain segment table.
  4. Explain Base and Limit.
  5. Show one address translation example.

For a 10-Mark Answer

  1. Introduction to segmentation.
  2. Logical view of a program.
  3. Code, data, heap and stack segments.
  4. Segment Table.
  5. Base and Limit.
  6. Logical address format.
  7. Address translation steps.
  8. Solved numerical example.
  9. External fragmentation.
  10. Advantages and disadvantages.
  11. Meaning of Paged Segmentation.
  12. Segment Table and Page Tables.
  13. Paged Segmentation address format.
  14. Paged Segmentation translation.
  15. 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.

Final Memory Trick:

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

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Join Telegram Exam updates and free resources