Paging and Segmentation are important memory management techniques used by an operating system to organize, allocate, protect, and access memory. Both techniques divide a process into smaller logical or physical units, but the way those units are created and managed is different.
Paging divides memory into fixed-size blocks, while segmentation divides a program according to its logical structure into variable-size segments. Understanding both techniques is important for learning Operating System Memory Management, virtual memory, address translation, fragmentation, and memory protection.
After studying this chapter, you should be able to:
Paging is a memory management technique in which the logical address space of a process is divided into fixed-size blocks called pages, while physical memory is divided into blocks of the same size called frames.
Since every page and frame has the same size, any page can be placed into any available frame in physical memory. Therefore, a complete process does not have to occupy one continuous region of physical memory.
| Term | Meaning |
|---|---|
| Page | A fixed-size block of a process's logical address space. |
| Frame | A fixed-size block of physical memory. |
| Page Table | Data structure used to map page numbers to frame numbers. |
| Page Number | Identifies a particular page in the logical address space. |
| Offset | Identifies the exact byte or word inside a page. |
| Frame Number | Identifies the physical memory frame containing a page. |
Figure 1: Pages of a process are mapped to available frames in physical memory.
The important point is that the pages of a process do not necessarily have to be placed in consecutive physical frames. The operating system maintains a page table to remember where each page is located.
In a simple contiguous memory allocation system, a process may require one large continuous block of memory. Over time, allocation and deallocation can create small gaps between allocated blocks. Even when the total free memory is sufficient, a process may fail to find one sufficiently large continuous region.
Paging addresses this problem by allowing the pages of a process to be placed in different physical frames.
Suppose a process requires four pages and physical memory currently has four available frames at different locations:
| Process Page | Allocated Frame |
|---|---|
| Page 0 | Frame 5 |
| Page 1 | Frame 2 |
| Page 2 | Frame 8 |
| Page 3 | Frame 1 |
The pages are physically separated, but the page table allows the operating system to locate them correctly.
Figure 2: Logical address translation using a page table in paging.
When a CPU generates a logical address, the operating system and memory-management hardware divide the address into two components:
The page number is used to search the page table. The corresponding page-table entry gives the frame number. The frame number is then combined with the original offset to construct the physical address.
The address contains a page number and an offset.
The page number identifies which page contains the required data.
The page table provides the frame number associated with that page.
The operating system or memory-management hardware obtains the physical frame containing the required page.
The frame number and offset are combined to obtain the physical address.
The processor accesses the required location in physical memory.
Figure 3: General paging address-translation process.
A page table is a data structure maintained for a process to map logical page numbers to physical frame numbers.
Consider the following page table:
| Page Number | Frame Number |
|---|---|
| 0 | 4 |
| 1 | 7 |
| 2 | 1 |
| 3 | 6 |
This means:
The page table therefore provides the mapping required to translate logical addresses into physical addresses.
A page-table lookup introduces additional memory-access overhead. To reduce this overhead, computer systems commonly use a small, fast associative cache called the Translation Lookaside Buffer (TLB).
The TLB stores recently used page-to-frame mappings. When a logical address is generated, the system can first check the TLB.
If the required page number is found in the TLB, the corresponding frame number can be obtained quickly. This is called a TLB hit.
If the page number is not present in the TLB, the system must consult the page table. This situation is called a TLB miss.
Page size determines the number of bits required for the offset portion of a logical address.
For example, if the page size is 1024 bytes:
If the logical address contains 16 bits, then:
Therefore, the logical address can contain:
Consider a system with:
According to the page table:
A system uses a page size of 512 bytes. Suppose logical address 1000 is generated and the page table contains:
| Page | Frame |
|---|---|
| 0 | 3 |
| 1 | 6 |
| 2 | 1 |
Page Number:
Offset:
Page 1 is stored in Frame 6.
Physical Address:
Paging eliminates external fragmentation because a page can be placed into any available frame. However, paging may produce internal fragmentation.
Internal fragmentation occurs when the final page of a process is not completely filled.
Suppose:
The process requires three pages:
The remaining 500 bytes in the final page are unused.
Segmentation is a memory management technique in which a program is divided into logical units called segments.
Unlike pages, segments are not required to have a fixed size. Their sizes depend on the logical requirements of the program.
Common examples of logical segments include:
The operating system maintains a segment table to keep information about each segment.
A typical segment table entry contains:
| Segment | Meaning | Base | Limit |
|---|---|---|---|
| 0 | Code | 2000 | 600 |
| 1 | Data | 3000 | 400 |
| 2 | Stack | 1200 | 200 |
Figure 4: Segmentation converts a logical segment address into a physical address.
A logical address in segmentation consists of:
The segment number is used to locate the corresponding segment-table entry. The base address and limit are then used to validate and translate the address.
Consider the following segment table:
| Segment | Base Address | Limit |
|---|---|---|
| 0 | 2000 | 600 |
| 1 | 3000 | 400 |
| 2 | 1200 | 200 |
Segment number = 1
Offset = 150
Segment 1 has:
Since the offset is within the segment boundary, the address is valid.
Segment 2 has a limit of 200.
The requested offset is 250, which exceeds the segment's permitted range.
Figure 5: Segmentation address translation with a boundary check.
One important advantage of segmentation is that different logical portions of a program can have different protection requirements.
For example:
| Segment | Possible Protection |
|---|---|
| Code | Read and Execute |
| Data | Read and Write |
| Stack | Read and Write |
This logical separation can make memory protection easier to express because permissions can be associated with meaningful program components.
Segmentation can also support sharing of logical program components. For example, a read-only code segment may be shared by multiple processes running the same program.
Sharing can reduce the amount of physical memory required because multiple processes may refer to the same physical segment when appropriate protection rules are satisfied.
Since segments can have different sizes, segmentation can suffer from external fragmentation.
When segments are repeatedly allocated and released, free spaces of different sizes can appear between allocated segments.
The total free memory may be large, but it may be divided into several smaller holes that cannot satisfy a large segment request without additional memory management.
Paging and segmentation solve memory-management problems using different approaches. Paging uses fixed-size units, while segmentation uses variable-size logical units.
| Feature | Paging | Segmentation |
|---|---|---|
| Basic Unit | Page | Segment |
| Size | Fixed size | Variable size |
| Physical Memory Unit | Frame | Segment occupies a contiguous memory region in the basic model |
| Logical Address | Page number + offset | Segment number + offset |
| Main Table | Page table | Segment table |
| Table Mapping | Page → Frame | Segment → Base + Limit |
| Fragmentation | Internal fragmentation | External fragmentation |
| Program View | More focused on fixed-size memory management | Closely represents logical program structure |
| Protection | Can be implemented through page-level mechanisms | Natural logical protection boundaries at segment level |
| Sharing | Possible through suitable page mappings | Can naturally correspond to shared logical segments |
| Allocation | Frames are equal-sized | Variable-sized memory regions |
| Virtual Memory | Widely used as a foundation for virtual memory | Can be combined with paging in systems using segmented address spaces |
Paging and segmentation are not necessarily mutually exclusive. A system can conceptually combine the two approaches so that a program is first organized into logical segments and those segments are then managed using paging.
In such an arrangement, segmentation provides the logical organization while paging provides fixed-size memory management.
Try to solve the following questions before opening the solutions. These problems are useful for semester examinations, competitive examinations, technical interviews and Operating System revision.
A system has a page size of 512 bytes. The page table is:
| Page | Frame |
|---|---|
| 0 | 3 |
| 1 | 6 |
| 2 | 1 |
Find the physical address for logical address 1000.
A page size is 1024 bytes. Find the page number and offset for logical address 2500.
Consider:
| Segment | Base | Limit |
|---|---|---|
| 0 | 500 | 300 |
| 1 | 1200 | 150 |
Determine the result for logical address (0, 250).
Segment 1 has base address 1200 and limit 150. Determine whether logical address (1, 180) is valid.
Which technique uses fixed-size logical and physical blocks: paging or segmentation?
Paging is a memory management technique that divides a process's logical address space into fixed-size pages and physical memory into equal-sized frames. A page table maps pages to frames.
A page is a fixed-size block of a process's logical address space.
A frame is a fixed-size block of physical memory. Its size is equal to the page size.
A page table stores the mapping between logical page numbers and physical frame numbers.
Translation Lookaside Buffer is a small, fast cache that stores recently used page-to-frame mappings to reduce address-translation overhead.
Paging can cause internal fragmentation, especially in the final page of a process when that page is not completely filled.
Standard paging eliminates external fragmentation because any available frame can hold a page of the appropriate size.
Segmentation divides a program into variable-size logical units such as code, data, stack and heap.
A segment table stores information such as the base address and limit associated with each logical segment.
A logical address in segmentation is generally represented as:
After validating the offset against the segment boundary, the physical address is calculated as:
Segmentation can suffer from external fragmentation because segments have variable sizes and allocation can leave scattered free spaces.
Paging uses fixed-size pages and frames, whereas segmentation uses variable-size logical segments.
Segmentation provides a logical organization because segments can correspond to meaningful program components such as code, data and stack.
Paging allows individual fixed-size pages to be managed independently, making it suitable for loading and managing portions of a process rather than requiring the entire process to occupy contiguous physical memory.
Yes. A system can organize a program into logical segments and then use paging to manage the memory associated with those segments.
Page size determines the size of each page and frame and also determines how many bits of a logical address are used for the offset.
During a TLB miss, the required mapping is not found in the TLB, so the system must consult the appropriate page table to obtain the frame mapping.
Paging and segmentation are fundamental concepts in Operating System memory management. Although both divide a process into smaller units, they are based on different ideas.
Paging divides the logical address space into fixed-size pages and physical memory into equal-sized frames. A page table is used to determine where each page is located. Paging makes non-contiguous allocation possible and eliminates external fragmentation, although internal fragmentation can occur.
Segmentation, on the other hand, divides a program according to its logical structure. Code, data, stack and other meaningful components can become separate segments. Each segment is associated with information such as its base address and limit, allowing logical protection and sharing.
The most important distinction to remember is:
A clear understanding of these concepts provides a strong foundation for studying virtual memory, page replacement algorithms, memory protection, address translation and other advanced Operating System topics.