Memory Management in Operating Systems: Techniques and Strategies
Memory Management in Operating Systems
Introduction
Memory management is crucial for efficient OS operation. It involves tracking memory usage and allocating space to processes. This document explores various memory management techniques and strategies.
Memory Types and Fragmentation
Two types of fragmentation can occur:
- Internal Fragmentation: Due to the size difference between a memory partition and the resident object (static partitions).
- External Fragmentation: Unused memory between partitions (dynamic partitions).
Memory Allocation Algorithms
Several algorithms manage memory allocation:
- Queue per Partition: Processes are queued based on assigned partition size.
- Single Queue: All waiting processes reside in a single queue, managed by a module.
Static Partitions
Advantages
- Simple administration, requiring only a record of each zone’s status (free or busy).
- Inter-process protection via memory keys or base/limit registers.
Disadvantages
- Poor memory utilization due to inflexibility.
- Difficulty running programs larger than partitions, leading to the use of overlays.
- Memory wastage from inefficient partitioning (fragmentation).
Dynamic Partitions
Memory is divided into variable-sized blocks based on process needs.
Advantages
- Flexibility in defining block sizes, eliminating internal fragmentation.
Disadvantages
- External fragmentation: Unused memory gaps between partitions.
Memory Compaction
Compaction unites free memory blocks into a single partition. This requires dynamic program relocation, adjusting base/limit registers.
Placement Strategies
- First Fit: Allocates the first space large enough.
- Best Fit: Allocates the smallest space large enough.
- Worst Fit: Allocates the largest available space.
- Next Fit: Similar to First Fit, but starts the search from the last allocated space.
- Quick Fit: Maintains separate linked lists for different hole sizes.
Overlays
Overlays keep only necessary instructions and data in memory at any given time.
Swapping
Swapping moves processes between main memory and a designated disk area (swap space or backing store).
- Swap-out: Moving a process from memory to disk.
- Swap-in: Moving a process from disk to memory.
Binding
Binding translates logical addresses to physical addresses.
- Logical Address: A memory location reference independent of current data assignment.
- Relative Address: Position relative to a known memory point.
- Physical Address: The actual memory location.
Memory Hierarchy
Memory is organized hierarchically based on speed and cost:
- Cache: Fastest and most expensive.
- Main Memory: Slower and less expensive than cache.
- Secondary Storage: Slowest and cheapest.
Memory Manager
The Memory Manager is the OS component responsible for tracking memory usage and allocating space.
Memory Management Goals
- Efficient memory utilization.
- Protection between processes.
- Supporting multiprogramming.
Memory Protection
In monoprogramming systems, memory protection is achieved using base and limit registers. Multiprogramming systems require more robust protection mechanisms.
Multiprogramming with Fixed Partitions
Memory is divided into fixed-size partitions, each holding one process.
Multiprogramming with Variable Partitions
Partitions are variable in size and number, adapting to process needs.