Operating System - Paged Segmentation and Segmented Paging



The paged segmentation and segmented paging are two hybrid memory management techniques that combine the benefits of both paging and segmentation. In previous sections, we have learned about paging and segmentation. This chapter will focus on explaining paged segmentation and segmented paging.

Segmented Paging

In segmented paging, the memory is divided into segments, and each segment is further divided into fixed-size pages. Combining the both techniques can overcome the limitations of each individual technique. The operating system maintains a segment table to keep track of the segments and their corresponding page tables. Each entry in the segment table contains a pointer to the page table for that segment.

How Segmented Paging Works?

The image below shows the working of segmented paging −

Segmented Paging

Here, we explain the steps involved in translating a logical address to a physical address using segmented paging:

1. Generating Logical Address

First the CPU generates a logical address that consists of three parts: segment number, page number, and offset within the page.

< Segment # , Page # , Offset >
  • Segment Number − It identifies the segment to which the address belongs.
  • Page Number − It identifies the specific page within the segment.
  • Offset − It specifies the exact location within the page.

2. Segment Table Lookup

The segment number is used to index into the segment table to get the base address of the page table for that segment. The Segment # from the logical address is used as an index. The OS checks the limit to ensure the segment access is valid and retrieves the base address of the page table for that segment.

$\mathrm{\text{Base Address of Page Table} = \text{Segment Table}[\text{Segment #}].\text{Base Address}}$

Segment #  ->  Base Address of Page Table

Segment 0 -> 0x2000
Segment 1 -> 0x3000
Segment 2 -> 0x4000
...

3. Page Table Lookup

The page number is then used to index into the page table to get the frame number where the page is stored in physical memory. The page table will contain the mapping of page numbers to frame numbers for that segment.

$\mathrm{(\text{Physical Address} = (\text{Frame Number} \times \text{Page Size}) + \text{Offset}}$

Page #  ->  Frame #

Page 0 -> Frame 0
Page 1 -> Frame 1
Page 2 -> Frame 3
... 

4. Physical Address Calculation

Finally, the physical address is calculated by combining the frame number with the offset within the page.

$\mathrm{\text{Physical Address} = (\text{Frame Number} \times \text{Page Size}) + \text{Offset}}$

Paged Segmentation

The paged segmentation is different from segmented paging. Here, the paged segmentation is used to refer the technique of paging the segment table. If a process has a massive number of segments, the Segment Table itself becomes too large to fit in one contiguous block of memory. So the segment table is treated as a process and is divided into pages. Each page of the segment table can be loaded into memory as needed, similar to how pages of a process are loaded in paging.

How Paged Segmentation Works?

The image below shows the working of paged segmentation −

Paged Segmentation

Here, we explain the steps involved in translating a logical address to a physical address using paged segmentation:

1. Generating Logical Address

The CPU generates a logical address in the following format:

< Page Table Index (PTI), Segment Table Index (STI), Offset >

Here, the logical address consists of three parts: Page Table Index (PTI), Segment Table Index (STI), and Offset within the segment.

  • Page Table Index (PTI) − It identifies the page of the segment table.
  • Segment Table Index (STI) − It identifies the specific segment within that page.
  • Offset − It specifies the exact location within the segment.

2. Outer Page Table

The outer page table (also called page directory) contains the base addresses of the pages of the segment table. Each entry in the outer page table points to a page of the segment table. This tells which segment table page contains the required segment entry.

Outer Page Table:
PTI  ->  Base Address of Segment Table Page
0    -> 0x5000
1    -> 0x6000
2    -> 0x7000
...

3. Accessing the Segment Table Page

Each page of the segment table contains multiple segment entries. Each segment entry stores the base address and limit of a segment.

Segment Table Page:
STI  -> Segment Base Address , Limit
0    -> 0x8000 , 0x1000
1    -> 0x9000 , 0x2000
2    -> 0xA000 , 0x3000
...

The STI selects the correct segment entry inside the page. The offset is checked against the limit to ensure the access is valid. If the offset exceeds the limit, a segmentation fault occurs.

4. Physical Address Formation

The physical address is formed by adding the segment base address to the offset within the segment, provided the access is valid (i.e., offset is within the limit).

$\mathrm{\text{Physical Address} = \text{Segment Base Address} + \text{Offset}}$

Paged Segmentation vs Segmented Paging

The paged segmentation and segmented paging are two different concepts. Both are often used interchangeably, in general discussions about hybrid memory management techniques. However, in strict technical terms, they refer to different approaches to combining paging and segmentation. Here, we summarize the key differences between paged segmentation and segmented paging: −

Aspect Paged Segmentation Segmented Paging
Definition Paging is applied to the segment table itself. Segmentation is applied to the pages of a process.
Structure The segment table is divided into pages, and each page contains multiple segment entries. The memory is divided into segments, and each segment is further divided into fixed-size pages.
Address Translation Logical address consists of Page Table Index (PTI), Segment Table Index (STI), and Offset. Logical address consists of Segment Number, Page Number, and Offset.
Use Case Used when the segment table is too large to fit in memory as a single block. Used to combine the benefits of both paging and segmentation for memory management.

Conclusion

Both paged segmentation and segmented paging are hybrid memory management techniques that have benefits of both paging and segmentation. You can choose either technique based on your system requirements and design considerations.

Advertisements