
Segmentation and paging are two memory management schemes used to manage how processes are stored in memory. Both techniques are designed to solve the issues of contiguous...
Segmentation and paging are two memory management schemes used to manage how processes are stored in memory. Both techniques are designed to solve the issues of contiguous memory allocation (which suffers from fragmentation) and to make memory management more efficient and flexible. Let’s dive into each of these concepts in detail.
Segmentation is a memory management scheme that divides a program into logically distinct segments. Unlike contiguous memory allocation, where the memory is divided into fixed-size partitions, segmentation divides memory based on the program's logical structure (such as code, data, stack, etc.).
In segmentation, a program is divided into segments, where each segment is a separate entity that holds a particular type of data. For example:
Each segment has its base address and length, which means that the segment is stored in a logical sequence in memory but not necessarily in a contiguous block. This allows processes to have non-contiguous allocation of memory, which helps to overcome fragmentation problems seen in contiguous allocation.
Each process has a segment table to store the base address and length of each segment. The logical address (also called a segment number and offset) generated by the CPU is translated using the segment table:
Paging is another memory management technique in which the physical memory is divided into fixed-size blocks called pages and physical memory is divided into page frames of the same size. A program is also divided into pages, but instead of the program’s logical divisions (like code, data, and stack), a program is divided into small, fixed-size pages.
A program’s logical address is split into two parts:
The logical address is translated to a physical address using the page table. The page table maps the page number to the frame number in physical memory.
The page table holds the mapping from a process’s logical pages to physical frames. Each entry in the page table stores the frame number corresponding to the page, along with additional bits such as valid/invalid and access permissions.
| Feature | Segmentation | Paging |
|---|---|---|
| Memory Division | Divides memory into logical segments (e.g., code, data). | Divides memory into fixed-size pages. |
| Size | Segments can be variable in size. | Pages are of fixed size. |
| Fragmentation | External fragmentation can occur. | Internal fragmentation occurs within pages. |
| Address Translation | Requires segment table and offset. | Uses page table for address translation. |
| Ease of Sharing | Segments like code can be easily shared among processes. | Pages may be shared but less naturally than segments. |
| Efficiency | More complex due to variable segment sizes. | Simpler but has the overhead of page tables. |
| Use Case | Suitable for programs with distinct logical divisions. | Suitable for programs requiring contiguous memory without fragmentation. |
Here’s an example of how paging works:
Suppose the process has:
| Page Number | Frame Number |
|---|---|
| 0 | 2 |
| 1 | 3 |
| 2 | 0 |
| 3 | 1 |
If the logical address has a page number of 2 and an offset of 5, we look up page 2 in the page table and find that it is mapped to frame 0. The final physical address is the frame number + offset.
Modern operating systems often use a combination of segmentation and paging. For example, x86-64 architecture uses paging for memory management but also incorporates segmentation for certain tasks such as code and data separation, although segmentation is less common in modern systems.
Open this section to view and download past papers
Click on Show Past Papers to load available exam papers.