1. Introduction
Segmentation and paging are two important memory management techniques, each solving different problems.
Segmentation provides a logical view of a program, while paging eliminates external fragmentation.
However:
Segmentation suffers from external fragmentation
Paging ignores the logical structure of programs
To combine the advantages of both approaches, operating systems use Segmentation with Paging.
2. What is Segmentation with Paging?
Segmentation with paging is a hybrid memory management technique in which:
A process is first divided into logical segments
Each segment is further divided into fixed-size pages
Pages are stored in physical memory frames
Key Idea
Program
↓
Segments
↓
Pages
↓
Frames
This combines the logical organization of segmentation with the efficient allocation of paging.
3. Why Combine Segmentation and Paging?
Problem with Segmentation
Logical Structure ✓
External Fragmentation ✗
Problem with Paging
No External Fragmentation ✓
Logical Structure ✗
Combined Approach
Logical Structure ✓
No External Fragmentation ✓
4. Program Structure
Suppose a process contains:
| Segment | Purpose |
|---|---|
| Segment 0 | Code |
| Segment 1 | Data |
| Segment 2 | Stack |
| Segment 3 | Heap |
Instead of storing these segments directly in memory, each segment is divided into pages.
Example:
Code Segment
↓
Page 0
Page 1
Page 2
Data Segment
↓
Page 0
Page 1
Stack Segment
↓
Page 0
Page 1
5. Memory Organization
Physical memory is divided into fixed-size frames.
Example:
Frame 0
Frame 1
Frame 2
Frame 3
Frame 4
Frame 5
Frame 6
Frame 7
...
Pages from different segments can be placed in any available frame.
Example:
Code Page 0 → Frame 5
Code Page 1 → Frame 2
Data Page 0 → Frame 8
Stack Page 0 → Frame 3
6. Logical Address Structure
In segmentation with paging, a logical address has three components:
Logical Address
=
(Segment Number,
Page Number,
Offset)
or
(s, p, d)
7. Components of Logical Address
7.1 Segment Number (s)
Identifies the segment.
Example:
Code Segment
Data Segment
Stack Segment
7.2 Page Number (p)
Identifies the page within the selected segment.
Example:
Code Segment
Page 0
Page 1
Page 2
7.3 Offset (d)
Identifies the exact location within the page.
Example:
Byte 50
inside a page.
8. Data Structures Used
Two levels of translation are required.
8.1 Segment Table
Maps:
Segment Number
↓
Page Table Address
Each segment has an entry in the segment table.
8.2 Page Table
Each segment has its own page table.
Maps:
Page Number
↓
Frame Number
Key Insight
One Segment
↓
One Page Table
9. Segment Table Structure
A segment table entry typically contains:
Base address of page table
Segment length
Protection information
Example:
| Segment | Page Table Base |
|---|---|
| 0 | PT0 |
| 1 | PT1 |
| 2 | PT2 |
| 3 | PT3 |
10. Page Table Structure
Each page table maps pages to frames.
Example:
Segment 1 Page Table
| Page | Frame |
|---|---|
| 0 | 5 |
| 1 | 3 |
| 2 | 8 |
| 3 | 1 |
11. Address Translation Process
This is the most important concept.
Given:
Logical Address
(s, p, d)
the MMU performs translation in two stages.
12. Step-by-Step Address Translation
Step 1
Extract segment number.
s
Step 2
Access segment table.
Segment Number
↓
Page Table Address
Step 3
Use page number.
p
to access the selected page table.
Step 4
Obtain frame number.
Page Number
↓
Frame Number
Step 5
Combine frame number and offset.
(Frame Number, Offset)
to form the physical address.
13. Translation Flow
Logical Address
(s, p, d)
↓
Segment Table
↓
Page Table
↓
Frame Number
↓
Physical Address
14. Formula
After translation:
Physical Address
=
Frame Number + Offset
More precisely:
Physical Address
=
(Frame Number × Page Size)
+ Offset
15. Numerical Example
Given:
Logical Address
(s=1, p=2, d=50)
Segment Table:
Segment 1
↓
Page Table PT1
Page Table PT1:
| Page | Frame |
|---|---|
| 0 | 5 |
| 1 | 3 |
| 2 | 8 |
| 3 | 1 |
Step 1
Segment:
s = 1
Select PT1.
Step 2
Page:
p = 2
Lookup:
Page 2 → Frame 8
Step 3
Offset:
d = 50
Final Physical Address
(Frame 8, Offset 50)
or
Physical Address
=
Frame 8 + Offset 50
16. Protection Mechanism
Segmentation provides protection at the segment level.
Example:
| Segment | Permissions |
|---|---|
| Code | Read, Execute |
| Data | Read, Write |
| Stack | Read, Write |
| Shared Library | Read, Execute |
This provides better security than pure paging.
17. Sharing Support
Entire segments can be shared between processes.
Example:
Shared Library Segment
used by:
Process A
Process B
Process C
Benefits:
Saves memory
Reduces duplication
Improves efficiency
18. Fragmentation Analysis
External Fragmentation
Pure segmentation:
External Fragmentation Exists
Segmentation with paging:
External Fragmentation Eliminated
because paging allocates fixed-size frames.
Internal Fragmentation
Still possible.
Example:
Last page partially filled
Thus:
External Fragmentation ✗
Internal Fragmentation ✓
19. Advantages
Maintains Logical Structure
Segments correspond to actual program modules.
Eliminates External Fragmentation
Paging removes scattered free-space problems.
Better Protection
Protection at both segment and page levels.
Better Sharing
Logical modules can be shared easily.
Efficient Memory Utilization
Combines strengths of both approaches.
20. Disadvantages
High Complexity
Two levels of translation.
Additional Memory Overhead
Requires:
Segment table
Multiple page tables
Slower Translation
More lookups compared to simple paging.
Complex Hardware Support
MMU becomes more sophisticated.
21. Comparison with Paging and Segmentation
| Feature | Paging | Segmentation | Segmentation + Paging |
|---|---|---|---|
| Division Basis | Fixed Pages | Logical Segments | Segments + Pages |
| Logical View | No | Yes | Yes |
| External Fragmentation | No | Yes | No |
| Internal Fragmentation | Yes | No | Yes |
| Protection | Moderate | Good | Excellent |
| Sharing | Moderate | Good | Excellent |
| Complexity | Low | Medium | High |
22. Real-World Analogy
Think of a book.
Segmentation
Book
↓
Chapters
Each chapter represents a segment.
Paging
Chapter
↓
Pages
Each chapter is divided into pages.
Physical Memory
Pages stored on shelves
To find information:
Chapter
↓
Page
↓
Shelf Location
This is exactly how segmentation with paging works.
Most Important Point
Segmentation with Paging combines the logical view of segmentation and the efficient memory allocation of paging by dividing a process into segments and then dividing each segment into pages mapped onto physical memory frames.