Operating System

Memory Management


Memory Management is one of the most important functions of an Operating System. It is responsible for managing primary memory (RAM), allocating memory to processes, tracking memory usage, and ensuring efficient utilization of system resources.

Since multiple programs run simultaneously in modern systems, memory management helps prevent conflicts between processes while improving speed, multitasking, and overall performance.


Need for Memory Management

  • Efficient utilization of main memory
  • Proper allocation and deallocation of memory
  • Protection between processes
  • Support for multitasking
  • Faster execution of programs
Without memory management, processes may overwrite each other’s data causing system crashes.

Memory Hierarchy

Computer systems use different types of memory organized in a hierarchy based on speed, cost, and storage capacity.

Memory Hierarchy

Registers
Cache Memory
Main Memory (RAM)
Secondary Storage

Contiguous Memory Allocation

In contiguous memory allocation, each process occupies a single continuous block of memory.

  • Simple and easy to implement
  • Fast memory access
  • Can lead to fragmentation problems
Operating System
Process P1
Process P2
Free Space

Fragmentation

Fragmentation occurs when memory becomes inefficiently used.

Internal Fragmentation

Wasted memory inside allocated partition.

External Fragmentation

Free memory exists but not in contiguous form.


Paging

Paging is a memory management technique where processes are divided into fixed-size pages and memory is divided into frames.

  • Eliminates external fragmentation
  • Allows non-contiguous memory allocation
  • Uses page tables for mapping

Paging Structure

Process Pages
Page 0
Page 1
Page 2
Memory Frames
Frame 5
Frame 2
Frame 9

Segmentation

Segmentation divides programs into logical units such as functions, arrays, or modules.

  • Supports logical program structure
  • Segment sizes can vary
  • Easier sharing and protection
Code Segment
Data Segment
Stack Segment

Virtual Memory

Virtual memory allows execution of programs larger than physical memory by using disk storage as an extension of RAM.

  • Increases multiprogramming
  • Improves memory utilization
  • Uses demand paging technique
RAM
Disk Storage

Page Replacement Algorithms

When memory becomes full, Operating Systems replace existing pages to load new pages.

AlgorithmDescription
FIFOReplaces oldest page first
LRUReplaces least recently used page
OptimalReplaces page not needed for longest future time

Thrashing

Thrashing occurs when the system spends more time swapping pages between RAM and disk instead of executing processes.

  • Causes severe performance degradation
  • Happens when insufficient frames are allocated
  • High paging activity indicates thrashing
Thrashing reduces CPU utilization significantly because the CPU waits for memory operations frequently.

Paging vs Segmentation

PagingSegmentation
Fixed size memory blocksVariable size logical units
Eliminates external fragmentationMay suffer external fragmentation
Hardware orientedUser/program oriented

Summary

Memory Management is essential for efficient execution of modern operating systems. Techniques such as paging, segmentation, virtual memory, and page replacement help improve performance, multitasking, and resource utilization while ensuring smooth execution of processes.

Ready to test your Chapter VI: Memory Management knowledge?

Chapter VI: Memory Management

Test your understanding of memory hierarchy, paging, segmentation, virtual memory, page replacement algorithms, and thrashing.

5 questions·No time limit·Instant feedback