CS 134

Key Points: Memory Management and Segmentation

Memory Fragmentation

  1. External Fragmentation: Free space scattered in small blocks, unable to satisfy large allocation requests
  2. Internal Fragmentation: Allocated memory not fully used by a process
  3. Allocation Strategies:
    • First Fit: Allocate first free block large enough
    • Best Fit: Allocate smallest free block large enough
    • Worst Fit: Allocate largest free block available
    • Next Fit: Start searching from last allocation point

Simple Process Placement

  1. Single-Partition Memory Management:
    • Only one program runs at a time
    • Requires protection to prevent overwriting OS code/data
  2. Memory Protection:
    • Use of base and limit registers
    • Two CPU modes: user mode and kernel mode
  3. Logical Addressing:
    • Programs think they start at address zero
    • Address translation maps logical to physical addresses
  4. Fixed Partitions:
    • Memory divided into fixed-size partitions
    • Can lead to internal fragmentation and inability to run large processes
  5. Variable Partitions:
    • Dynamically sized memory allocation
    • Can lead to external fragmentation

Segmentation

  1. Purpose: Share code between processes and separate code from data
  2. Implementation:
    • Separate logical spaces (segments) for code and data
    • Each segment has its own base and limit registers
  3. Benefits:
    • Allows code sharing between processes
    • Reduces memory usage for multiple instances of the same program
  4. Historical Context:
    • Intel x86 segment registers (CS, DS, SS, ES, FS, GS)
    • Modern usage differs from original memory protection purpose

Remember

  • Memory fragmentation can occur in both fixed and variable partition schemes
  • Base and limit registers provide a simple mechanism for memory protection
  • Logical addressing allows flexibility in process placement and swapping
  • Segmentation provides a way to share code and separate code from data
  • Each memory management scheme has trade-offs in terms of efficiency, flexibility, and complexity
  • We can run experiments to explore behavior under different memory management strategies

(When logged in, completion status appears here.)