Categories

Advertisement
⏱️ 37 min read

Memory Management in Operating System

N
By NotesMind
Advertisement

Memory Management in Operating System

1. What is Memory Management?

Memory Management वह प्रक्रिया है जिसके द्वारा Operating System (OS) RAM (Main Memory) को Manage करता है। OS यह तय करता है कि किस Process को कितनी Memory मिलेगी, कब मिलेगी और कब वापस ली जाएगी।

Basic View

+----------------------+

|        CPU           |

+----------+-----------+

          |

          v

+----------------------+

| Operating System     |

| Memory Management    |

+----------+-----------+

          |

          v

+----------------------+

|      RAM Memory      |

+----------------------+

Memory Management के मुख्य कार्य

1. Memory Allocation

OS प्रत्येक Process को उसकी आवश्यकता के अनुसार Memory प्रदान करता है।

2. Memory Deallocation

जब कोई Process समाप्त हो जाती है, तो OS उसकी Memory को मुक्त (Free) कर देता है ताकि अन्य Processes उसका उपयोग कर सकें।

3. Address Translation

Logical Address को Physical Address में परिवर्तित करने का कार्य Memory Management Unit (MMU) द्वारा किया जाता है।

4. Protection

एक Process दूसरी Process की Memory को Access न कर सके, इसके लिए Memory Protection प्रदान की जाती है।

5. Sharing

OS आवश्यकतानुसार कई Processes को Memory Share करने की सुविधा देता है।

Memory Management Techniques

1. Paging

  • Memory को निश्चित आकार के Pages और Frames में विभाजित किया जाता है।
  • External Fragmentation की समस्या को कम करता है।

2. Segmentation

  • Program को विभिन्न Segments (Code, Data, Stack आदि) में divide किया जाता है।
  • Logical Structure को बनाए रखता है।

3. Virtual Memory

  • Physical Memory से अधिक Memory का आभास कराती है।
  • Hard Disk के एक भाग का उपयोग Memory के रूप में किया जाता है।

 

Fragmentation

Internal Fragmentation

Allocated Memory के अंदर बची हुई unused Memory।

External Fragmentation

Free Memory छोटे-छोटे Blocks में बंट जाती है, जिससे बड़ी Memory Allocate करना कठिन हो जाता है।

Memory Management Advantage

  • Efficient Memory Utilization
  • Better System Performance
  • Multitasking Support
  • Process Protection
  • Resource Sharing

 

Memory Management in Operating System 

परिचय (Introduction)

Memory Management Operating System (OS) का वह भाग है जो Main Memory (RAM) को Control  करता है। जब किसी Computer System में multiple Processes एक साथ चल रही होती हैं, तब OS यह सुनिश्चित करता है कि प्रत्येक Process को उचित Memory मिले, Memory सुरक्षित रहे तथा उपलब्ध Memory का अधिकतम उपयोग हो।

सरल शब्दों में, Memory Management वह तकनीक है जिसके द्वारा Operating System Memory का Allocation, Deallocation, Protection, Sharing और Tracking करता है।

Memory Hierarchy

Computer System में Memory को गति (Speed), लागत (Cost) और क्षमता (Capacity) के आधार पर विभिन्न स्तरों में विभाजित किया जाता है।

CPU Registers

     ↓

Cache Memory

     ↓

Main Memory (RAM)

     ↓

Secondary Memory (SSD/HDD)

  • Registers : सबसे तेज़ Memory
  • Cache Memory : CPU और RAM के बीच
  • RAM : Primary Memory
  • SSD/HDD : Secondary Storage

 

Memory Management के उद्देश्य (Objectives)

1. Efficient Memory Utilization

Memory का अधिकतम उपयोग करना।

2. Process Isolation

एक Process दूसरी Process की Memory को Access न कर सके।

3. Multiprogramming Support

एक साथ कई Processes को चलाने की सुविधा देना।

4. Fast Execution

CPU को आवश्यक Data शीघ्र उपलब्ध कराना।

5. Virtual Memory Support

RAM कम होने पर भी बड़े Programs चलाना।

Basic Concepts

1. Logical Address

CPU द्वारा Generate किया गया Address।

उदाहरण:

Logical Address = 1500

इसे Virtual Address भी कहा जाता है।

 


2. Physical Address

RAM में वास्तविक Address।

उदाहरण:

Physical Address = 4500

3. Address Binding

Program Addresses को Memory Addresses से जोड़ने की प्रक्रिया।

Types of Address Binding

a) Compile Time Binding

Address Compilation के समय तय होते हैं।

b) Load Time Binding

Address Loading के समय तय होते हैं।

c) Execution Time Binding

Address Run Time पर तय होते हैं।

Memory Allocation

 

1. Contiguous Memory Allocation

Process को Memory के लगातार (Continuous) Block में रखा जाता है।

+------------------+

| Operating System |

+------------------+

| Process P1       |

+------------------+

| Process P2       |

+------------------+

| Process P3       |

+------------------+

Advantages

  • सरल Implementation
  • तेज़ Access

Disadvantages

  • Fragmentation की समस्या

 


Types of Contiguous Allocation

Single Partition Allocation

पूरी Memory में केवल एक User Process रहती है।

OS + One Process

 


Multiple Partition Allocation

Memory को कई Partitions में बांटा जाता है।

Fixed Partitioning

Memory पहले से निश्चित Partitions में विभाजित रहती है।

Partition 1

Partition 2

Partition 3

Partition 4

समस्या: Internal Fragmentation

 


Dynamic Partitioning

Partitions आवश्यकता अनुसार बनाए जाते हैं।

समस्या: External Fragmentation

Fragmentation

1. Internal Fragmentation

Allocated Memory के अंदर बची हुई अनुपयोगी Memory।

उदाहरण:

Required = 18 KB

Allocated = 20 KB

 

Unused = 2 KB

यह Internal Fragmentation कहलाती है।

 


2. External Fragmentation

Free Memory छोटे-छोटे Blocks में बंट जाती है।

10 KB Free

5 KB Used

8 KB Free

7 KB Used

12 KB Free

कुल Free Memory पर्याप्त होने पर भी बड़ी Process Allocate नहीं हो पाती।

Compaction

External Fragmentation को हटाने के लिए सभी Free Spaces को एक जगह इकट्ठा करना।

Before:

P1  Free  P2  Free  P3

 

After:

P1  P2  P3  Free

 


Paging

Paging सबसे महत्वपूर्ण Memory Management Technique है।

Concept

Page

Process को छोटे Fixed Size Blocks में बांटा जाता है।

Frame

RAM को समान आकार के Blocks में बांटा जाता है।

Process Pages:

P0

P1

P2

P3

 

Memory Frames:

F0

F1

F2

F3

F4

Pages किसी भी Frame में रखे जा सकते हैं।

 


Page Table

Page Number और Frame Number का Mapping Table।

Page

Frame

P0

F3

P1

F1

P2

F4

P3

F0

 


Advantages of Paging

  • External Fragmentation समाप्त
  • Efficient Memory Utilization
  • Virtual Memory Support

Segmentation

Program को Logical Units में विभाजित किया जाता है।

उदाहरण:

Code Segment

Data Segment

Stack Segment

Heap Segment

 


Segment Table

Segment

Base

Limit

Code

1000

500

Data

2000

300

Stack

3000

200

 


Advantages

  • Logical Organization
  • Protection आसान

Disadvantages

  • External Fragmentation

Disadvantages

  • Page Table Overhead
  • Internal Fragmentation संभव

 

Paging with Segmentation

आधुनिक Operating Systems दोनों Techniques का संयुक्त उपयोग करते हैं।

Program

  ↓

Segments

  ↓

Pages

  ↓

Frames

 


Virtual Memory

Virtual Memory ऐसी तकनीक है जो RAM से अधिक Memory उपलब्ध होने का आभास कराती है।

आवश्यकता

मान लीजिए:

RAM = 4 GB

 

Program Size = 8 GB

Program सीधे RAM में नहीं आ सकता।

Virtual Memory इस समस्या को हल करती है।

 


Demand Paging

Page तभी RAM में लाया जाता है जब उसकी आवश्यकता हो।

Page Needed

     ↓

Page Fault

     ↓

Disk Access

     ↓

RAM Loading

 


Page Fault

जब Required Page RAM में नहीं मिलता तो Page Fault उत्पन्न होता है।

Steps

  1. CPU Page Access करता है।
  2. Page Memory में नहीं मिलता।
  3. Page Fault Interrupt Generate होता है।
  4. OS Page को Disk से RAM में लाता है।
  5. Process पुनः Execute होती है।

 


Page Replacement Algorithms

जब RAM Full हो जाती है तब किसी Page को हटाना पड़ता है।

1. FIFO (First In First Out)

सबसे पहले आया Page पहले हटेगा।

2. LRU (Least Recently Used)

जिस Page का सबसे लंबे समय से उपयोग नहीं हुआ उसे हटाया जाएगा।

3. Optimal Algorithm

भविष्य में सबसे देर से उपयोग होने वाले Page को हटाता है।

 


Thrashing

जब System अधिक समय Page Swapping में खर्च करने लगे और कम समय Actual Execution में लगाए।

High Page Fault Rate

       ↓

Thrashing

 


Swapping

Process को अस्थायी रूप से RAM से Disk में भेजना।

RAM → Disk

Disk → RAM

 


Memory Protection

Memory Protection सुनिश्चित करती है कि:

  • Process A, Process B की Memory Access न करे।
  • User Program Kernel Memory Access न कर सके।

Protection Methods

  • Base Register
  • Limit Register
  • Access Rights
  • Paging Protection

 

Memory Management Unit (MMU)

MMU (Memory Management Unit) एक Hardware Component है जो:

  • Logical Address को Physical Address में बदलता है।
  • Memory Protection प्रदान करता है।
  • Paging और Segmentation को Support करता है।

 


आधुनिक Operating Systems में Memory Management

जैसे:

  • Windows
  • Linux
  • macOS
  • Android

इनमें मुख्यतः:

  • Virtual Memory
  • Demand Paging
  • Page Replacement
  • Swapping
  • Memory Protection
  • Shared Memory

का उपयोग किया जाता है।

 

Advertisement

💬 Leave a Comment & Rating