Paging vs. Segmentation: Difference Between Memory Management Techniques
One of the primary functions of the operating system (OS) is memory management. It is a fundamental aspect that efficiently allocates, tracks, and optimizes the use of a computer’s main memory (RAM). There are various memory management techniques, with Paging and Segmentation being the most widely used techniques.
| Key Takeaways: |
|---|
|
This article explores paging and segmentation in depth, compares their mechanisms, advantages, and disadvantages, and highlights their key differences.
What is Memory Management in the Operating System?
Memory management in operating systems handles primary memory (RAM), ensuring efficient allocation, deallocation, and tracking of memory for processes. It maximizes CPU utilization, supports multitasking, and uses techniques like paging, segmentation, and virtual memory to ensure processes run efficiently without interfering with one another.
Key Aspects of Memory Management
- Allocation/Deallocation: Processes are assigned memory when they begin execution, and memory is freed up when processes terminate or finish.
- Tracking: Memory management keeps track of parts of memory currently used.
- Protection & Security: It protects the memory from getting corrupted or accessed by another process without permission.
- Virtual Memory: If a process requires memory larger than the physical memory, an extension of physical memory called virtual memory is used for process execution.
- Memory Management Unit (MMU): A hardware component that maps logical (virtual) addresses generated by the CPU to physical addresses in RAM.
- Fragmentation: The phenomenon where memory space gets wasted. It can be internal when the allocated memory is larger than needed, or external when free memory is split into small blocks.

What is Paging?
Paging is a memory management technique in which the address space of a process is divided into pages, blocks of a fixed length (a power of 2, typically 512 bytes to 8192 bytes). The logical memory divisions are called pages, while physical memory divisions are called frames.
Each page in logical memory is mapped to its corresponding frame in physical memory using a data structure called a Page table.
The number of pages represents the size of the process.
When paging occurs, a page table of the process stores the definition of each page. When an active process requests data, the MMU retrieves corresponding pages into frames (physical memory) for faster processing.
How Paging Works
- A process is divided into equal-sized pages (e.g., 4 KB each).
- Physical memory is divided into frames of the same size.
- Pages are loaded into available frames (not necessarily in contiguous order).
- A page table stores the mapping between pages and frames.
- The CPU generates a logical address given by:
- Page number
- Offset within the page
- The system translates the logical address into a physical address using the page table.
The paging process is shown below.

Example
Let the main memory size be 64B, and the frame size be 4B. Then, the number of frames would be 64/4 = 16. If there are 4 processes, each process is 16B, and the page size is also 4B, then the number of pages in each process is 16/4 = 4. These pages may be stored in the main memory frames in a non-contiguous form, depending on their availability. This arrangement is shown here:

Advantages of Paging
- Eliminates External Fragmentation: The paging technique allocates memory in fixed-size blocks, so there are no gaps between allocations. This prevents external fragmentation.
- Efficient Memory Utilization: As pages can be placed anywhere in memory, the memory is efficiently utilized.
- Supports Virtual Memory: Only required pages (for active processes) need to be loaded into memory.
- Simplifies Allocation: Paging does not require contiguous memory space, and hence, the pages are easy to allocate.
Disadvantages of Paging
- Internal Fragmentation: The page, especially the last page, may not be fully utilized, resulting in internal fragmentation.
- Page Table Overhead: There is a page table for each process. If a process is too large, the corresponding page table will also be huge, causing an overhead.
- Address Translation Overhead: Extra time and effort are needed to map logical addresses (pages) to physical locations (frames).
- Complex Hardware Requirements: Paging requires specialized hardware such as MMUs.
What is Segmentation?
Segmentation is a memory management technique in which memory is divided into variable-sized segments based on the logical structure of a program (each segment is for each module that contains pieces that perform related functions).
When a process is to be executed, its corresponding segments are loaded into non-contiguous memory, though every segment is loaded into a contiguous block of available memory. It is similar to paging, but in segmentation, segments are of variable length, whereas in paging, pages are of fixed size.
Each program segment represents a meaningful unit, such as:
- Code (main function)
- Data structures
- Stack
- Heap
- Utility functions
The OS maintains a segment map table for every process. It also maintains a list of free memory blocks along with segment numbers, size, and corresponding memory locations in the main memory.
The segment table stores the starting address of each segment and its length. A reference to a memory location is a value that identifies a segment and an offset.
Segmentation assigns related data into a segment table between the CPU and the physical memory, speeding up information retrieval.
How Segmentation Works
The process of segmentation is summarised below:

- A program is divided into logical segments of varying sizes.
- Each segment is stored in a different location in physical memory.
- A Segment table keeps track of:
- Base address (starting location)
- Length of the segment (Limit)
- Logical address consists of:
- Segment number
- Offset within the segment
- The system checks:
- If offset < segment length
- Then adds an offset to the base address to get the physical address
Example
- Segment 0: Base address: 500 and Limit: 800
- Segment 1: Base address: 3000 and Limit: 1200
- Segment 2: Base address: 1500 and Limit: 1000
The segmentation arrangement is shown as follows:

Each segment has a base address and limit (length) in physical memory; these values are stored in the segment table. When a program accesses a memory location, the OS uses the segment table to translate the logical address into a physical address.
For example, the base address of Segment 0 is 500, and the limit is 800. So the physical address for logical address (0, 800) will be calculated as:
Physical Address = Base Address + Offset
So for,
Segment 0, Physical Address = 500 + 800 = 1300
Segment 1, Physical Address = 3000 + 1200 = 4200
Segment 2, Physical Address = 1500 + 1000 = 2500
Hence, the logical address (500, 1300) is given to segment 0 in physical memory. Similarly, the logical addresses (3000, 4200) and (1500, 2500) are given to segment 1 and segment 2, respectively.
Advantages of Segmentation
- Reflects Logical Structure of Programs: Segmentation matches how programmers think about memory and reflects the program’s logical structure.
- Supports Modularity: As each segment represents a module or function, segmentation in a way supports modularity.
- No Internal Fragmentation: Segmentation does not cause any internal fragmentation, as the exact size is calculated for each segment.
- Efficient Memory Sharing: Segments are independent and can be shared between processes.
- No Data Structure Overhead: Segment tables consume less space compared to paging tables.
- Reduced Processing Overhead: Processing required for segmentation is less compared to paging.
Disadvantages of Segmentation
- External Fragmentation: Variable-sized segments leave gaps in memory, causing external fragmentation.
- Complex Memory Allocation: It is challenging to find suitable space for segments.
- Slower Allocation Compared to Paging: Segmentation requires searching for contiguous memory, making allocation slower.
- Compaction Overhead: Memory needs to be reorganized periodically when segmented.
Key Differences Between Paging and Segmentation
The following table presents the key differences between paging and segmentation:
| Feature | Paging | Segmentation |
|---|---|---|
| Definition | Paging is a memory management scheme in which each process is divided into fixed-size pages. | Segmentation is a memory management scheme in which a process is divided into variable-sized segments. |
| Accountability | The operating system divides the memory into pages. | The compiler is responsible for calculating the segment size, the virtual address, and the actual address. |
| View of Memory | Physical memory-oriented. | Logical program-oriented. |
| Fragmentation | Internal fragmentation. | External fragmentation. |
| Address Structure | Page number + offset. | Segment number + offset. |
| Mapping Table | Page table. | Segment table. |
| Memory Allocation | Non-contiguous. | Contiguous. |
| Page Size | Page size is fixed and determined by the system. | Segment size is variable and determined by the process. |
| Ease of Allocation | Easy. | Complex. |
| Protection & Sharing | Limited. | More flexible. |
| Programmer Visibility | Invisible to the programmer. | Visible and meaningful. |
| Performance | Faster allocation. | Slower due to fragmentation. |
| Memory Management | Paging is managed by hardware through a page table. | Segmentation is managed by software through a segment table. |
| Overhead | Paging has lower overhead due to a simpler memory management scheme. | Segmentation has higher overhead due to a more complex memory management scheme. |
Combined Approach: Segmented Paging
- Memory is divided into segments.
- Each segment is further divided into pages.
- The hybrid approach reduces external fragmentation.
- It maintains a logical structure.
- The approach improves memory utilization.
Use Case Comparison
When Paging is Preferred
- When systems require efficient memory utilization.
- In case there are virtual memory systems.
- It is ideal in high-performance environments.
When Segmentation is Preferred
- When systems need logical separation of programs.
- Applications require strong protection and sharing.
- For modular program design.
Performance Considerations
You should also consider the performance aspect of paging and segmentation.
Paging Performance
- Paging has a faster allocation of memory.
- It is efficient for large-scale systems.
- It requires caching (TLB – Translation Lookaside Buffer).
Segmentation Performance
- The segmentation process is slower due to variable sizes.
- It leads to overhead in searching memory.
- The approach may require compaction.
Conclusion
Paging and segmentation are two fundamental memory management techniques that address different challenges. While paging focuses on efficient use of physical memory by dividing the memory into fixed-sized units called pages, segmentation organizes the logical memory, dividing it based on program structure.
Paging takes care of external fragmentation and simplifies allocation. However, it introduces internal fragmentation and requires additional hardware support. Segmentation, on the other hand, aligns with program logic and offers better protection but suffers from external fragmentation and complexity.
Modern operating systems combine both techniques to utilize their strengths and minimize their weaknesses. When choosing between them, apart from their working, you should consider their advantages and trade-offs.
Paging is ideal for performance and simplicity, while segmentation is better for logical organization and protection.
Frequently Asked Questions (FAQs)
- What type of fragmentation occurs in paging?
When some memory within allocated pages remains unused, paging leads to internal fragmentation.
- What type of fragmentation occurs in segmentation?
Segmentation causes external fragmentation, where free memory is scattered in small blocks across the system.
- Which is faster: paging or segmentation?
Paging is generally faster because it uses fixed-size blocks, making memory allocation simpler compared to segmentation.
- Is segmentation still used in modern operating systems?
Yes, by combining it with paging. However, pure segmentation is rarely used today.
- What is a page table?
A page table is a data structure that maps logical pages to physical memory frames in a paging system.
- What is a segment table?
A segment table stores information about segments, including their base address and size (limit).
- Which technique is better for memory protection?
Segmentation provides better memory protection because access controls can be applied to each segment.
|
|
