Unit III: Memory Management – Notes
1. What is Memory Management?
A technique for managing RAM in an OS.
Helps in:
- Allocating/deallocating memory for processes.
- Tracking used and free memory.
- Improving concurrency and system performance.
- Reducing fragmentation and ensuring data integrity.
2. Swapping
Moves inactive processes from main memory to secondary storage (and back).
Backing Store: Fast disk to hold memory images.
Roll In/Roll Out: Used for priority-based scheduling.
Pros: Better utilization, flexibility, and performance.
Cons: Overhead, disk I/O, possible data issues.
3. Contiguous Memory Allocation
Divides memory into fixed or variable-size blocks.
Fixed-size partitioning: Static, causes internal fragmentation.
Variable-size partitioning: Dynamic, reduces internal fragmentation.
Uses relocation registers (base & limit) to protect memory.
Pros: Easy access, high performance.
Cons: Fragmentation, growing files are harder to manage.
4. Partition Allocation Methods
First Fit: First block large enough is chosen.
Best Fit: Smallest suitable block.
Worst Fit: Largest available block.
Next Fit: Similar to First Fit but starts from last allocated block.
5. Paging
Non-contiguous memory allocation.
Pages: Logical memory blocks.
Frames: Physical memory blocks.
Uses a page table for address translation.
Causes internal fragmentation.
6. Segmentation
Divides memory into logical segments (functions, arrays, etc.).
Each segment has:
- Base address
- Limit (length)
Provides better memory protection and isolation.
7. Paging vs. Segmentation
Paging: Fixed-size blocks, internal fragmentation, limited protection.
Segmentation: Variable-size logical units, external fragmentation, better protection.
8. Virtual Memory
Uses hard disk as extension of RAM.
Enables running large or many apps simultaneously.
Advantages:
- Increased address space.
- Efficient memory use.
- Automatic data movement.
Disadvantages:
- Overhead (page faults, slowdowns).
- Complex implementation.
9. Page Replacement Algorithms
Used when a page must be swapped in, but no free frame exists.
FIFO: Replaces the oldest page, suffers from Belady’s Anomaly.
LRU: Replaces the least recently used page, efficient but needs hardware support.
Optimal (OPT): Replaces page not used for longest future time, ideal but impractical.
10. Frame Allocation Techniques
Equal: All processes get equal frames.
Proportional: Based on process size.
Priority: Higher priority = more frames.
Global Replacement: Any process can take frames.
Local Replacement: Each process uses only its own frames.
11. Fragmentation
Internal Fragmentation: Wasted space within allocated memory.
External Fragmentation: Wasted space between allocated memory blocks.
Solved by compaction (external) and best-fit allocation (internal).
12. Thrashing
Too many page faults lead to low CPU performance.
Caused by excessive paging and low available frames.
Solutions:
- Reduce degree of multiprogramming.
- Use better page replacement policies.
- Monitor and control memory usage.