Main Memory
Main Memory
Definition:
In an Operating System (OS), main memory (or primary memory) is a crucial component
that temporarily stores data, programs, and instructions while they are actively being used
by the CPU. It enables efficient execution of processes by providing fast, direct access to
data.
Types of Memory in an OS
1. RAM (Random Access Memory):
o Stores active processes and OS data.
o Volatile (loses data when power is off).
2. Cache Memory:
o Faster than RAM; stores frequently accessed data for quick retrieval.
3. Registers:
o Small, ultra-fast storage inside the CPU for immediate data processing.
4. Virtual Memory:
o Simulated memory using disk space when RAM is full.
Memory Management Techniques in an OS
1. Contiguous Memory Allocation
Fixed Partitioning: Divides memory into fixed-sized partitions.
Variable Partitioning: Dynamically allocates memory as needed.
2. Paging
Divides memory into fixed-sized blocks called pages.
Eliminates external fragmentation.
3. Segmentation
Divides memory into logical segments based on program structure (e.g., code, data,
stack).
4. Virtual Memory Management
Uses paging and swapping to extend available memory beyond physical RAM.
Main memory is a critical resource in an operating system, enabling fast data access,
multitasking, and process execution. The OS efficiently manages memory using techniques
like paging, segmentation, and virtual memory to optimize performance.
Main Memory: Fixed and Variable Partitioning
In memory management, partitioning refers to the way the main memory is divided to
allocate space for processes. There are two primary types of partitioning:
1. Fixed Partitioning
2. Variable Partitioning
1. Fixed Partitioning
Definition
Fixed Partitioning (also called static partitioning) divides main memory into a fixed number
of partitions at system startup. Each partition has a fixed size, and a process is loaded into a
partition that is equal to or larger than its size.
Characteristics
The number of partitions is determined at system boot time and does not change.
Each partition can hold only one process at a time.
If a process is smaller than the partition size, the remaining space is wasted (internal
fragmentation).
Advantages
✅ Simple Implementation: Easy to manage since partitions do not change.
✅ Low Overhead: No need to frequently resize partitions.
Disadvantages
❌ Internal Fragmentation: If a process does not use the entire partition, the remaining
space is wasted.
❌ Limited Flexibility: If a new process needs more memory than any partition, it cannot be
loaded, even if free memory exists elsewhere.
❌ Inefficient Memory Utilization: Some partitions may remain unused if no process fits
them.
Example
Assume we have 256 MB of RAM and we divide it into four fixed partitions:
Partition 1: 64 MB
Partition 2: 64 MB
Partition 3: 64 MB
Partition 4: 64 MB
If a process requiring 40 MB is allocated to a 64 MB partition, the remaining 24 MB is
wasted due to internal fragmentation.
2. Variable Partitioning
Definition
Variable Partitioning (also called dynamic partitioning) allows memory to be allocated
dynamically based on the process's actual size. The number and size of partitions can
change as processes enter and exit memory.
Characteristics
The system creates partitions dynamically as needed.
Partitions are exactly as large as required by processes.
No internal fragmentation, but external fragmentation may occur.
Advantages
✅ Better Memory Utilization: No fixed partition sizes, so memory is used efficiently.
✅ No Internal Fragmentation: Since partitions are created dynamically, no space is wasted
inside a partition.
✅ More Flexibility: Processes of varying sizes can be allocated without being constrained by
predefined partitions.
Disadvantages
❌ External Fragmentation: Over time, free memory becomes fragmented, making it
difficult to allocate large processes.
❌ Memory Compaction Overhead: To reduce fragmentation, the system may need to
rearrange memory (compaction), which takes processing time.
Example
Assume we have 256 MB of RAM, and three processes arrive requiring 50 MB, 120 MB, and
80 MB.
The system creates three partitions dynamically:
o Process 1 → 50 MB
o Process 2 → 120 MB
o Process 3 → 80 MB
Only 6 MB remains free, and no unnecessary gaps exist.
However, if Process 2 terminates, 120 MB becomes available. If a new process needing 130
MB arrives, it cannot be allocated, even though 6 MB + 120 MB = 126 MB is free. This is
external fragmentation.
Comparison Table
Feature Fixed Partitioning Variable Partitioning
Partition Size Fixed at system startup Dynamic, changes as needed
Flexibility Low (cannot adjust partitions) High (partitions created as needed)
Internal
Yes (unused space in partitions) No (partitions match process size)
Fragmentation
External Yes (memory gets fragmented over
No (partitions are fixed)
Fragmentation time)
Poor (some partitions remain
Memory Utilization Better (adjusts to process needs)
unused)
More complex due to dynamic
Complexity Simple to implement
allocation
Compaction Needed? No Yes, to reduce fragmentation
Fixed Partitioning is simpler but suffers from internal fragmentation and inefficient
memory usage.
Variable Partitioning allows better utilization of memory but suffers from external
fragmentation, which requires compaction to fix.