Course Content
Bonus Section (for Interviews and GATE/Placement prep)
0/1
Operating Systems (OS)
Memory Allocation Techniques: Contiguous, Paging, Segmentation, Fragmentation`

Efficient memory allocation is crucial in any operating system to ensure optimal performance, process isolation, and minimal wastage. Various techniques are used to manage how memory is allocated to processes. In this section, we’ll explore three core allocation techniques—Contiguous Allocation, Paging, and Segmentation—as well as how fragmentation affects them.


1. Contiguous Memory Allocation

What It Is:In contiguous memory allocation, each process is allocated a single, continuous block of memory in the main RAM. All the memory a process needs must be available in one sequence.

 

How It Works:

 

  • The operating system keeps a list of free memory blocks.
  • When a process arrives, the OS looks for a block large enough to fit it.
  • Once allocated, the block cannot be resized or broken.

 

 

Advantages:

 

  • Simple to implement.
  • Fast access due to sequential storage.

 

Limitations:

 

  • Leads to external fragmentation—unused spaces between allocated blocks.
  • Difficult to find large enough contiguous blocks for large processes.

2. Paging

What It Is:
Paging is a memory management technique that divides both the process and memory into fixed-size blocks—called pages (process) and frames (memory). Pages are loaded into any available frame in memory, not necessarily contiguous.

 

How It Works:

 

  • The logical address is divided into page number and offset.
  • The MMU uses a page table to map each page to a frame in physical memory.
  • This removes the need for contiguous allocation.

 

 

Advantages:

 

  • Eliminates external fragmentation.
  • More flexible memory usage.

 

Limitations:

 

  • Can lead to internal fragmentation if the last page is not fully used.
  • Adds overhead due to page table management.

3. Segmentation

What It Is:
Segmentation divides the program into logical segments such as code, data, stack, etc., each with different sizes. Each segment is loaded into memory separately and can be placed in non-contiguous locations.

 

How It Works:

 

  • Each logical address includes a segment number and an offset.
  • The segment table holds the base address and size of each segment.
  • The MMU translates this logical address into a physical one.

]

Advantages:

 

  • Supports logical program structure.
  • Easier memory protection and sharing between segments.

 

Limitations:

 

  • Can still suffer from external fragmentation.
  • Segment tables require management and protection.

4. Fragmentation: Internal vs External

Fragmentation refers to wasted memory space that arises from allocation inefficiencies.

 

Internal Fragmentation:

  • Occurs when fixed-size memory blocks are allocated, but the process does not use the entire block.
  • The unused space inside allocated blocks is wasted.
  • Common in paging systems.

External Fragmentation:

  • Happens when free memory is scattered in small blocks between allocated ones.
  • Even if enough total memory exists, no single large enough block may be available.
  • Common in contiguous and segmentation systems.

0% Complete
WhatsApp Icon

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.