wisemonkeys logo
FeedNotificationProfileManage Forms
FeedNotificationSearchSign in
wisemonkeys logo

Blogs

Different memory allocation strategies

profile
Srushti Chauhan
Jul 27, 2024
2 Likes
0 Discussions
606 Reads

Introduction

In operating systems, memory allocation refers to the process of assigning memory to different processes or programs running on a computer system. Memory allocation is a crucial function in operating systems, managing how memory resources are distributed among various processes. Different strategies have been developed to optimize memory usage and ensure system efficiency. Here are some common memory allocation strategies:

1. Contiguous Memory Allocation

  • Definition: This strategy allocates a single contiguous block of memory to each process.

Contiguous memory allocation is a technique where the operating system allocates a contiguous block of memory to a process. This memory is allocated in a single, continuous chunk, making it easy for the operating system to manage and for the process to access the memory. Contiguous memory allocation is suitable for systems with limited memory sizes and where fast access to memory is important.

Contiguous memory allocation can be done in two ways:-

  • Fixed Partitioning − In fixed partitioning, the memory is divided into fixed-size partitions, and each partition is assigned to a process. This technique is easy to implement but can result in wasted memory if a process does not fit perfectly into a partition.

  • Dynamic Partitioning − In dynamic partitioning, the memory is divided into variablesize partitions, and each partition is assigned to a process. This technique is more efficient as it allows the allocation of only the required memory to the process, but it requires more overhead to keep track of the available memory.

    Advantages of Contiguous Memory Allocation

    • Simplicity − Contiguous memory allocation is a relatively simple and straightforward technique for memory management. It requires less overhead and is easy to implement.

    • Efficiency − Contiguous memory allocation is an efficient technique for memory management. Once a process is allocated contiguous memory, it can access the entire memory block without any interruption.

  • Low fragmentation − Since the memory is allocated in contiguous blocks, there is a lower risk of memory fragmentation. This can result in better memory utilization, as there is less memory wastage.

Disadvantages of Contiguous Memory Allocation

  • Limited flexibility − Contiguous memory allocation is not very flexible as it requires memory to be allocated in a contiguous block. This can limit the amount of memory that can be allocated to a process.

  • Memory wastage − If a process requires a memory size that is smaller than the contiguous block allocated to it, there may be unused memory, resulting in memory wastage.

  • Difficulty in managing larger memory sizes − As the size of memory increases, managing contiguous memory allocation becomes more difficult. This is because finding a contiguous block of memory that is large enough to allocate to a process becomes challenging.

  • External Fragmentation − Over time, external fragmentation may occur as a result of memory allocation and deallocation, which may result in non − contiguous blocks of free memory scattered throughout the system.

2.Non-contiguous Memory Allocation

Non-contiguous memory allocation, on the other hand, is a technique where the operating system allocates memory to a process in non-contiguous blocks. The blocks of memory allocated to the process need not be contiguous, and the operating system keeps track of the various blocks allocated to the process. Non-contiguous memory allocation is suitable for larger memory sizes and where efficient use of memory is important.

Non-Contiguous memory allocation can be done in two ways:-

 1) Paging

  • Definition: Memory is divided into fixed-size blocks called pages, and physical memory is divided into page frames of the same size.
  • How it Works: A process’s memory is divided into pages that can be mapped to any page frame in physical memory. This approach helps avoid external fragmentation and simplifies memory management.

In paging, the memory is divided into fixed-size pages, and each page is assigned to a process. This technique is more efficient as it allows the allocation of only the required memory to the process.

  • Advantages:
    • Eliminates external fragmentation.
    • Simplifies allocation and deallocation.
  • Disadvantages:
    • Can cause internal fragmentation if a process doesn’t use the entire page.

   2)Segmentation

  • Definition: Memory is divided into segments based on the logical organization of the program (e.g., code, data, stack).
  • How it Works: Each segment is of variable length and is managed independently. Segments are referenced by segment number and offset.

In segmentation, the memory is divided into variable-sized segments, and each segment is assigned to a process. This technique is more flexible than paging but requires more overhead to keep track of the allocated segments.

  • Advantages:
    • Supports the logical division of a program.
    • Segments can grow or shrink independently.
  • Disadvantages:
    • Can lead to external fragmentation.
    • Managing variable-sized segments can be complex.

4. Virtual Memory

  • Definition: Provides an abstraction of memory that gives each process the illusion of having a large, contiguous block of memory, even though physical memory may be fragmented.
  • How it Works: Virtual memory systems use paging or segmentation to map virtual addresses to physical addresses. This allows processes to use more memory than physically available by swapping pages in and out of disk storage.
  • Advantages:
    • Supports multitasking by allowing multiple processes to run concurrently.
    • Provides the illusion of a large address space.
  • Disadvantages:
    • Can incur performance overhead due to paging and swapping.
    • Requires efficient management of page tables and disk space.

5. Buddy System

  • Definition: Memory is allocated in blocks that are powers of two, and the system maintains a list of free blocks of each size.
  • How it Works: When a process requests memory, the system finds a suitable block, which may involve splitting larger blocks. If memory is freed, the system attempts to merge adjacent free blocks into larger blocks.
  • Advantages:
    • Reduces fragmentation compared to fixed partitioning.
    • Relatively simple to implement.
  • Disadvantages:
    • Can still suffer from internal fragmentation.
    • May require additional bookkeeping.

6. Slab Allocation

  • Definition: Memory is divided into slabs, where each slab contains objects of a specific size.
  • How it Works: Objects of the same size are allocated from the same slab. This is often used in kernel memory management.
  • Advantages:
    • Reduces fragmentation for objects of fixed size.
    • Efficient for managing small, frequent allocations.
  • Disadvantages:
    • May be less efficient for objects of varying sizes.

7. Allocation with Garbage Collection

  • Definition: This strategy is often used in languages with automatic memory management. The system automatically reclaims memory that is no longer in use.
  • How it Works: Memory is allocated for objects as needed, and a garbage collector periodically scans for and frees unused objects.
  • Advantages:
    • Reduces the programmer’s burden of manual memory management.
    • Can help avoid memory leaks.
  • Disadvantages:
    • Garbage collection can introduce performance overhead.
    • The timing of garbage collection can be unpredictable.

Each strategy has its strengths and trade-offs, and the choice of strategy often depends on the specific requirements and constraints of the system being designed.


Comments ()


Sign in

Read Next

Firewall / IDS Evasion Techniques

Blog banner

Corporate Discipline.

Blog banner

Life of an army person

Blog banner

Paddle Through Paradise: The Best Kayak Launch Points Near Arcadia

Blog banner

VPN

Blog banner

Multiprocessor

Blog banner

IT Service as as Value Creation

Blog banner

Benefits of Yoga

Blog banner

Note Taker App

Blog banner

MODERN OPERATING SYSTEM

Blog banner

Retiring ISS

Blog banner

NETSUITE

Blog banner

Regression Analysis

Blog banner

internet email and it's applications

Blog banner

Fault Tolerance

Blog banner

Deadlock

Blog banner

Artificial Intelligence and I

Blog banner

GraphQL

Blog banner

Access management

Blog banner

Smartphone Security: Vulnerabilities and Attacks

Blog banner

Dr. Venkadavarahan

Blog banner

THE DESIRE OF MANY

Blog banner

MAJOR ACHIEVEMENTS OF OS

Blog banner

Deming’s Process

Blog banner

“CONSISTENCY” in Social Media Marketing

Blog banner

MENDELEY

Blog banner

Mobile Security

Blog banner

security controls

Blog banner

Teamwork

Blog banner

Embedded Operating System

Blog banner

USES OF WHATSAPP

Blog banner

The Power of Forensic Watermarking in the Fight Against Content Piracy

Blog banner

Drawing tips for a beginner

Blog banner

virtual memory

Blog banner

Deadlocks in Operating System

Blog banner

Operating System Objectives and Functions

Blog banner

Jamming Attacks in Network Security: Disrupting Communication Signals

Blog banner

A Review on Data Acquisition in Cyber Forensics

Blog banner

An Overivew Of Cache Memory

Blog banner

Memory management

Blog banner

Deadlocks in Operating Systems

Blog banner

How to Find the Right Therapist For Me?

Blog banner