Fiveable

๐Ÿ–ฒ๏ธOperating Systems Unit 3 Review

QR code for Operating Systems practice questions

3.5 Segmentation and segmented paging

๐Ÿ–ฒ๏ธOperating Systems
Unit 3 Review

3.5 Segmentation and segmented paging

Written by the Fiveable Content Team โ€ข Last updated September 2025
Written by the Fiveable Content Team โ€ข Last updated September 2025
๐Ÿ–ฒ๏ธOperating Systems
Unit & Topic Study Guides

Memory management is a crucial aspect of operating systems. Segmentation and paging are two key techniques used to organize and allocate memory efficiently. This section explores their concepts, advantages, and trade-offs, as well as the hybrid approach of segmented paging.

Segmentation divides memory into variable-sized segments, aligning with program structure and allowing flexible allocation. Paging uses fixed-size blocks, simplifying allocation but potentially causing internal fragmentation. Understanding these approaches helps in designing effective memory management systems for modern operating systems.

Segmentation vs Paging

Concept and Advantages of Segmentation

  • Segmentation divides logical address space into variable-sized segments representing logical units (functions, arrays, stacks)
  • Allows flexible memory allocation based on actual size of program components unlike fixed-size pages
  • Provides better support for sharing and protection of memory regions
  • Reduces external fragmentation compared to contiguous allocation schemes
  • Allows more efficient memory utilization by allocating only required amount potentially reducing internal fragmentation
  • Aligns more closely with programmer's conceptualization of program structure
  • Supports dynamic growth of data structures without needing to allocate maximum size upfront

Paging Overview and Comparison

  • Paging divides memory into fixed-size blocks called pages
  • Simplifies memory allocation and deallocation processes
  • Eliminates external fragmentation but may lead to internal fragmentation
  • Provides uniform access time to memory locations
  • Requires additional memory for page tables
  • Supports virtual memory implementations more easily
  • Allows for easier implementation of memory protection at the page level

Structure of Segmentation Systems

Segment Table and Address Translation

  • Uses segment table to map logical addresses to physical addresses
  • Segment table entries contain base address and limit information
  • Logical address consists of segment number and offset within segment
  • Segment Table Base Register (STBR) points to segment table location in memory
  • Segment limit register stores length of segment table preventing invalid segment access
  • Memory Management Unit (MMU) performs address translation
  • Combines base address of segment with offset to generate physical address

Protection and Fault Handling

  • Protection bits associated with each segment specify read, write, and execute permissions
  • Implements access control at segment level
  • Raises segmentation fault exceptions for illegal memory access attempts
  • Detects access beyond segment limit or violation of protection settings
  • Allows operating system to handle memory access violations gracefully
  • Supports implementation of memory isolation between processes
  • Enables fine-grained control over shared memory regions

Segmented Paging: Benefits

Hybrid Approach Advantages

  • Combines benefits of segmentation and paging techniques
  • Divides each segment into fixed-size pages for efficient memory allocation
  • Reduces fragmentation issues associated with pure segmentation
  • Logical address consists of segment number, page number within segment, and offset within page
  • Requires two-level address translation process
  • Maps segment to its page table then maps page to physical address
  • Allows for fine-grained memory protection at both segment and page levels

Enhanced Memory Management

  • Provides better support for shared memory and dynamic linking of libraries
  • Potentially reduces size of page tables compared to pure paging systems
  • Each segment has its own separate page table
  • Improves memory utilization by combining flexible segment allocation with efficient page management
  • Supports both logical organization of programs and efficient physical memory usage
  • Allows for more efficient implementation of virtual memory systems
  • Enables easier implementation of memory compression techniques

Segmentation vs Paging: Trade-offs

Flexibility and Fragmentation

  • Segmentation offers better support for variable-sized memory allocations
  • Paging provides more efficient management of fixed-size memory blocks
  • Paging typically results in less external fragmentation than segmentation
  • Segmentation may lead to external fragmentation between segments
  • Paging may cause internal fragmentation within pages
  • Segmented paging attempts to balance these trade-offs
  • Choice depends on specific system requirements and workload characteristics

Performance and Implementation Considerations

  • Address translation in segmentation generally simpler and faster than in paging
  • Paging relies more on table lookups affecting system performance
  • Segmentation requires additional hardware support for bound checking
  • Paging systems generally easier to implement and manage from OS perspective
  • Segmentation may require more complex memory allocation algorithms
  • Paging provides more flexibility in physical memory allocation
  • Trade-offs between flexibility, efficiency, and complexity influence design decisions