Memory Management Techniques -
Detailed Explanation
Group Members:
1. Nabaya Nestroy - 24/2/306/D/053
2. Nsimenta Shawn - 24/2/306/D/714
3. Muwonge Henry - 24/2/306/D/712
4. Muyanja Muhammad - 24/2/306/D/498
5. Magezi Conrad - 23/2/306/D/719
Introduction to Memory Management
Memory management is a crucial function of operating systems that handles how computer
memory is allocated to programs and reclaimed when no longer needed. As Silberschatz
explains in "Operating System Concepts (10th edition)", it involves tracking every byte in
memory, deciding which processes get memory, and managing data movement between main
memory (RAM) and secondary storage (like hard disks).
Modern computers use various techniques to manage memory efficiently. Let's examine each
technique in detail with simplified explanations.
1. Contiguous Memory Allocation
This is one of the simplest memory management techniques where each process gets a single,
continuous block of memory.
Types:
a) Fixed Partitioning:
Memory is divided into fixed-size partitions during system startup
Each partition can hold exactly one process
If a process is smaller than its partition, the unused space is wasted (internal
fragmentation)
Example: Imagine a bookshelf with fixed-size shelves - small books leave empty
space
b) Variable Partitioning:
Memory is divided dynamically based on process sizes
Reduces internal fragmentation but can cause external fragmentation
External fragmentation occurs when free memory exists but isn't contiguous
Example: Like parking cars of different sizes - small gaps between cars may be too
small for new cars
Advantages:
1. Fast memory access - Continuous blocks allow quick data retrieval
2. Low overhead - No complex data structures needed
3. Simple implementation - Easy to allocate and deallocate memory
Disadvantages:
1. Fragmentation issues - Both internal and external fragmentation
2. Limited multiprogramming - Fixed number of partitions limits concurrent processes
3. Memory waste - Unused spaces can't be utilized efficiently
2. Paging
Paging solves fragmentation problems by dividing memory into small, fixed-size units.
How it works:
Physical memory is divided into frames (typically 4KB each)
Logical memory (process memory) is divided into same-sized pages
A page table maps logical page numbers to physical frame numbers
The OS handles all address translations transparently
Example:
Imagine a library where books (processes) are broken into standard-sized pages. These pages
can be stored anywhere on the shelves (memory), and the librarian (page table) knows where
each page is located.
Advantages:
1. Eliminates external fragmentation - Any page can go in any available frame
2. Efficient memory use - Small fixed sizes minimize wasted space
3. Virtual memory support - Enables processes to use more memory than physically
available
4. Fast access - Hardware support makes address translation quick
Disadvantages:
1. Memory overhead - Page tables consume memory space
2. Internal fragmentation - Last page of a process may not fill a frame completely
3. Complex implementation - Requires hardware support for address translation
3. Segmentation
Segmentation organizes memory according to logical divisions within a program.
How it works:
Memory is divided into variable-sized segments (code, stack, heap, etc.)
Each segment has a base address and length (stored in a segment table)
Addresses consist of a segment number and offset within that segment
Example:
Think of a segmented memory like a filing cabinet where each drawer (segment) holds
different types of documents - one for financial records, another for personnel files, etc. Each
drawer can grow or shrink as needed.
Advantages:
1. Logical organization - Matches how programmers think about memory
2. Sharing capability - Segments can be shared between processes
3. Protection - Different access rights can be set for each segment
4. Reduced internal fragmentation - Segments match actual needs
Disadvantages:
1. External fragmentation - Variable sizes leave unusable gaps
2. Complex management - More difficult to implement than paging
3. Slower allocation - Finding space for variable-sized segments takes time
4. Virtual Memory
Virtual memory creates the illusion of more memory than physically exists by using disk
space.
Key Mechanism (Demand Paging):
Only currently needed pages reside in RAM
Unused pages stay on disk in a special swap space
When a program accesses a page not in RAM (page fault), the OS loads it from disk
Example:
Like a librarian who keeps only frequently used books on display shelves, storing others in a
back room. When someone requests a stored book, the librarian fetches it.
Advantages:
1. Large address space - Programs can use more memory than physically available
2. Efficient memory use - Only active pages consume RAM
3. More concurrent processes - System can handle more programs simultaneously
4. Simplified programming - Developers don't need to manage memory limits
5. Swapping
Swapping moves entire processes between RAM and disk.
How it works:
1. When RAM fills up, the OS selects an idle process
2. The entire process is copied to disk (swap space)
3. When needed again, it's copied back to RAM
4. Execution continues from where it paused
Advantages:
1. More processes - System can run programs that don't all fit in RAM
2. CPU utilization - Ensures CPU always has work to do
3. Large program support - Enables execution of big programs
Disadvantages:
1. Performance penalty - Disk I/O is much slower than RAM access
2. Thrashing risk - Excessive swapping can dominate system resources
3. Response time issues - Swapped-out processes respond slowly when activated
6. Compaction
Compaction reorganizes memory to reduce fragmentation.
How it works:
The OS moves allocated memory blocks together
This consolidates free space into one large block
Requires updating all address references
Example:
Like defragmenting a hard drive - rearranging files to eliminate gaps between them.
Challenges:
1. CPU overhead - Moving memory blocks consumes processor time
2. Complexity - Must update all memory references accurately
3. Temporary performance hit - System may slow down during compaction
Conclusion
Modern operating systems often combine these techniques (like paging with segmentation) to
get the benefits of each. Understanding these memory management methods helps us
appreciate how computers efficiently handle multiple programs with limited physical
memory.