Memory Management in Operating System: Paging, Segmentation, Virtual Memory
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 Management क्या है? (What is Memory Management)
Memory Management वह प्रक्रिया है जिसके द्वारा Operating System RAM (Main Memory) को Manage करता है। OS यह तय करता है कि किस Process को कितनी Memory मिलेगी, कब मिलेगी और कब वापस ली जाएगी।
Basic Working Flow:
CPU
↓
Operating System (Memory Management)
↓
RAM (Main Memory)
Memory Hierarchy
Computer System में Memory को गति (Speed), लागत (Cost) और क्षमता (Capacity) के आधार पर विभिन्न स्तरों में विभाजित किया जाता है।
CPU Registers → सबसे तेज़ Memory Cache Memory → CPU और RAM के बीच RAM → Primary Memory SSD/HDD → Secondary Storage
Memory Management के उद्देश्य (Objectives)
- Efficient Memory Utilization – Memory का अधिकतम उपयोग करना
- Process Isolation – एक Process दूसरी Process की Memory को Access न कर सके
- Multiprogramming Support – एक साथ कई Processes को चलाने की सुविधा देना
- Fast Execution – CPU को आवश्यक Data शीघ्र उपलब्ध कराना
- Virtual Memory Support – RAM कम होने पर भी बड़े Programs चलाना
Memory Management के मुख्य कार्य (Key Functions)
| कार्य | विवरण |
|---|---|
| Memory Allocation | OS प्रत्येक Process को आवश्यकता अनुसार Memory प्रदान करता है |
| Memory Deallocation | Process समाप्त होने पर OS उसकी Memory मुक्त (Free) कर देता है |
| Address Translation | Logical Address को Physical Address में बदलने का कार्य MMU करता है |
| Protection | एक Process दूसरी Process की Memory Access न करे, इसके लिए Protection दी जाती है |
| Sharing | OS आवश्यकता अनुसार कई Processes को Memory Share करने की सुविधा देता है |
Basic Concepts: Logical vs Physical Address
1. Logical Address
CPU द्वारा Generate किया गया Address। इसे Virtual Address भी कहा जाता है।
उदाहरण: Logical Address = 1500
2. Physical Address
RAM में वास्तविक Address।
उदाहरण: Physical Address = 4500
3. Address Binding
Program Addresses को Memory Addresses से जोड़ने की प्रक्रिया को Address Binding कहते हैं।
Types of Address Binding:
| Type | विवरण |
|---|---|
| Compile Time Binding | Address Compilation के समय तय होते हैं |
| Load Time Binding | Address Loading के समय तय होते हैं |
| Execution Time Binding | Address Run Time पर तय होते हैं |
Memory Allocation Techniques
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
a) Single Partition Allocation
पूरी Memory में केवल एक User Process रहती है (OS + One Process)
b) Multiple Partition Allocation
Memory को कई Partitions में बांटा जाता है:
- Fixed Partitioning: Memory पहले से निश्चित Partitions में विभाजित रहती है — समस्या: 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 में बंट जाती है, जिससे बड़ी Memory Allocate करना कठिन हो जाता है — भले ही कुल Free Memory पर्याप्त हो।
Compaction
External Fragmentation को हटाने के लिए सभी Free Spaces को एक जगह इकट्ठा किया जाता है।
Before: P1 Free P2 Free P3
After: P1 P2 P3 Free
Paging in Operating System
Paging सबसे महत्वपूर्ण Memory Management Technique है।
Concept:
- Page: Process को छोटे Fixed Size Blocks में बांटा जाता है
- Frame: RAM को समान आकार के Blocks में बांटा जाता है
Pages किसी भी Frame में रखे जा सकते हैं।
Page Table (Mapping Example)
| Page | Frame |
|---|---|
| P0 | F3 |
| P1 | F1 |
| P2 | F4 |
| P3 | F0 |
Advantages of Paging:
- External Fragmentation समाप्त हो जाता है
- Efficient Memory Utilization
- Virtual Memory Support
Disadvantages of Paging:
- Page Table Overhead
- Internal Fragmentation संभव
Segmentation in Operating System
Segmentation में Program को Logical Units में विभाजित किया जाता है — जैसे Code, Data, Stack, Heap।
Segment Table (Example)
| Segment | Base | Limit |
|---|---|---|
| Code | 1000 | 500 |
| Data | 2000 | 300 |
| Stack | 3000 | 200 |
Advantages:
- Logical Organization
- Protection आसान
Disadvantages:
- External Fragmentation
Paging with Segmentation
आधुनिक Operating Systems दोनों Techniques का संयुक्त उपयोग करते हैं:
Program → Segments → Pages → Frames
Virtual Memory in Operating System
Virtual Memory ऐसी तकनीक है जो RAM से अधिक Memory उपलब्ध होने का आभास कराती है। Hard Disk के एक भाग का उपयोग 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:
- CPU Page Access करता है
- Page Memory में नहीं मिलता
- Page Fault Interrupt Generate होता है
- OS Page को Disk से RAM में लाता है
- Process पुनः Execute होती है
Page Replacement Algorithms
जब RAM Full हो जाती है, तब किसी Page को हटाना पड़ता है।
| Algorithm | विवरण |
|---|---|
| FIFO (First In First Out) | सबसे पहले आया Page पहले हटेगा |
| LRU (Least Recently Used) | जिस Page का सबसे लंबे समय से उपयोग नहीं हुआ उसे हटाया जाएगा |
| Optimal Algorithm | भविष्य में सबसे देर से उपयोग होने वाले Page को हटाता है |
Thrashing
जब System अधिक समय Page Swapping में खर्च करने लगे और कम समय Actual Execution में लगाए, तो उसे Thrashing कहते हैं।
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 एक Hardware Component है जो:
- Logical Address को Physical Address में बदलता है
- Memory Protection प्रदान करता है
- Paging और Segmentation को Support करता है
आधुनिक Operating Systems में Memory Management
Windows, Linux, macOS aur Android जैसे आधुनिक Operating Systems में मुख्यतः निम्नलिखित Techniques का उपयोग किया जाता है:
- Virtual Memory
- Demand Paging
- Page Replacement
- Swapping
- Memory Protection
- Shared Memory
Memory Management के लाभ (Advantages)
- Efficient Memory Utilization
- Better System Performance
- Multitasking Support
- Process Protection
- Resource Sharing
ये टॉपिक भी आप देख सकते है - Batch Processing OS, Multiprogramming Os, Multitasking Os, Multiuser Os, Multithreading
Os
परीक्षा के महत्वपूर्ण बिंदु (Important Exam Points)
- ⭐ Memory Management OS का वह भाग है जो RAM को Control करता है
- ⭐ Logical Address ko Physical Address me MMU convert karta hai
- ⭐ Paging External Fragmentation ko khatam karti hai
- ⭐ Segmentation Logical Units (Code, Data, Stack) me divide karta hai
- ⭐ Virtual Memory RAM se zyada memory ka illusion deti hai
- ⭐ LRU aur FIFO Page Replacement ke common algorithms hain
- ⭐ Thrashing High Page Fault Rate ki wajah se hoti hai
FAQs
Q1. Memory Management Operating System में क्यों महत्वपूर्ण है?
यह सुनिश्चित करता है कि सभी Processes को आवश्यक Memory मिले, बिना किसी Conflict के, और System Performance बेहतर रहे।
Q2. Paging और Segmentation में क्या अंतर है?
Paging Memory को Fixed Size Blocks में बांटती है, जबकि Segmentation Program को Logical Units (Code, Data, Stack) में बांटती है।
Q3. Virtual Memory की आवश्यकता क्यों पड़ती है?
जब Program Size RAM से बड़ा हो, तब Virtual Memory Hard Disk के हिस्से का उपयोग करके Program को चलाने में मदद करती है।
Q4. Thrashing क्या है?
जब System अधिक समय Page Swapping में खर्च करता है और Actual Execution कम होता है, उसे Thrashing कहते हैं।
💬 Leave a Comment & Rating