1. Memory allocation

Memory Management

Memory Management वह process है जिसमें Operating System (OS) computer की memory को control और organize करता है। इसमें memory को छोटे-छोटे blocks में divide करके अलग-अलग running programs को allocate किया जाता है, जिससे system performance improve होती है।


मुख्य बिंदु (Key Points):

  • Operating System का सबसे important function है primary memory को manage करना
  • यह एक साथ multiple processes को memory में support करता है
  • Processes को unauthorized access से protect करता है
  • Efficient तरीके से swapping और virtual memory को handle करता है

memory-tree

Techniques in Memory Allocation (मेमोरी एलोकेशन की तकनीकें)
ये techniques Operating System (OS) द्वारा use की जाती हैं ताकि memory को efficiently allocate, utilize और manage किया जा सके।

👉 विभिन्न techniques को broadly दो categories में divide किया जाता है:

ggg

Swapping (स्वैपिंग)

Swapping एक memory management technique है जिसमें processes को temporarily main memory (RAM) से secondary storage (disk) में भेजा जाता है ताकि दूसरी processes के लिए memory free हो सके।

  • Multiple processes efficiently run कर सकते हैं
  • Low-priority processes को swap out किया जा सकता है
  • Swap होने के बाद process वापस load होकर resume करता है
  • Transfer time data के size पर depend करता है

Contiguous Memory Allocation (सतत मेमोरी एलोकेशन)

इसमें हर process को एक continuous memory block दिया जाता है, जहाँ उसका पूरा data और instructions stored होते हैं।


Single Contiguous Memory Allocation

यह सबसे simple technique है।

👉 Memory को 2 parts में divide किया जाता है:

  • एक हिस्सा Operating System के लिए
  • दूसरा हिस्सा single user process के लिए

Characteristics (विशेषताएँ):

  • एक समय में केवल एक process
  • OS fixed memory use करता है
  • कोई multiprogramming नहीं
  • Simple management

Advantages (फायदे):

  • Simple memory management
  • Fragmentation नहीं होता

Disadvantages (नुकसान):

  • Poor memory utilization
  • Multitasking support नहीं

Partitioned Memory Allocation (विभाजित मेमोरी एलोकेशन)

Memory को multiple partitions में divide किया जाता है, और हर partition में एक process चलता है।


1. Fixed Partition Allocation

  • Memory fixed partitions में divide होती है
  • हर partition का size fixed होता है
  • एक partition = एक process
  • Internal Fragmentation होता है
  • OS partition table से track करता है

2. Variable (Dynamic) Partition Allocation

  • Memory process size के अनुसार dynamically allocate होती है
  • Internal fragmentation कम होता है
  • लेकिन External Fragmentation होता है

Advantages:

  • Multiprogramming possible
  • Better utilization

Disadvantages:

  • Fragmentation issues
  • Complex management

Non-Contiguous Memory Allocation (असतत मेमोरी एलोकेशन)

इसमें process को छोटे-छोटे parts में divide करके अलग-अलग memory locations में store किया जाता है।

Features (विशेषताएँ):

  • Process कई जगह store हो सकता है
  • Memory utilization improve होता है
  • External fragmentation कम होता है
  • MMU (Memory Management Unit) required होता है

Advantages:

  • Better utilization
  • Large programs support
  • Continuous memory की जरूरत नहीं

Disadvantages:

  • Complex system
  • Address translation overhead
  • Extra tables (page table / segment table) की जरूरत

Techniques (तकनीकें):

  • Paging → fixed-size pages
  • Segmentation → logical segments (code, data, stack)
  • Segmentation + Paging → दोनों का combination

Memory Management Mechanisms

Virtual Memory

  • Program RAM से बड़ा हो सकता है
  • Disk को extra memory की तरह use करता है

Page Replacement Algorithms (PRA)

जब memory full हो जाती है तो कौन सा page हटाना है:

  • FIFO → सबसे पहले आया page हटाओ
  • LRU → least recently used हटाओ
  • Optimal → future में सबसे कम use होगा उसे हटाओ
  • LFU → least frequently used हटाओ

Demand Paging

  • केवल required pages load होते हैं
  • Memory और I/O बचता है

Memory Problems (समस्याएँ)

Fragmentation (फ्रैगमेंटेशन)

  • Internal Fragmentation → extra allocated space waste
  • External Fragmentation → scattered free memory

Thrashing (थ्रैशिंग)

  • System बार-बार swapping करता है
  • CPU utilization बहुत कम हो जाता है

Memory Allocation Strategies (रणनीतियाँ)

Fixed Partition Allocation

  • Fixed size partitions
  • Partition table से track

Dynamic Partition Allocation

  • Process size के अनुसार memory

Placement Algorithms (एल्गोरिदम):

  • First Fit → पहला suitable block
  • Best Fit → smallest suitable block
  • Worst Fit → largest block
  • Next Fit → last position से search