BCA / B.Tech 14 min read

Virtual Memory in Hindi

RK

लेखक Ratan Kumawat · संस्थापक, NotesMedia

प्रकाशित:

त्वरित सारांश और मुख्य बिंदु

  • • विषय फोकस: Operating System (OS) Notes in Hindi | ऑपरेटिंग सिस्टम नोट्स (BCA / B.Tech Syllabus)
  • • मुख्य विषय: Virtual Memory in Hindi - General Topics
  • • अवलोकन: Quick Answer: Operating system में Virtual Memory एक memory management technique है, जो secondary storage (जैसे hard disk या SSD) के एक हिस्से को tempo...
  • • मुख्य अवधारणाएं: Virtual Memory in Hindi, Virtual Memory क्या है, Virtual Memory की परिभाषा, Virtual Memory कैसे काम करती है, Memory management, Operating System में Virtual Memory, RAM और Virtual Memory,
Quick Answer: Operating system में Virtual Memory एक memory management technique है, जो secondary storage (जैसे hard disk या SSD) के एक हिस्से को temporary RAM की तरह इस्तेमाल करती है। इससे system को यह illusion मिलता है कि उसके पास physical RAM से कहीं ज़्यादा memory मौजूद है। इसके ज़रिए CPU ऐसे बड़े programs को भी execute कर लेता है जिनका size physical RAM से बड़ा होता है। यह मुख्य रूप से Demand Paging और Swapping पर काम करती है।

Virtual Memory in OS क्या है? (What is Virtual Memory in Hindi)

कंप्यूटर में physical RAM का size limited होता है (जैसे 4 GB, 8 GB या 16 GB)। जब आप एक साथ कई heavy software या games (जैसे video editing tool, modern IDE या high-end games) चलाते हैं, तो उन सभी programs का कुल data RAM की capacity से ज़्यादा हो सकता है।

पुरानी तकनीक में जब तक पूरा program RAM में load नहीं होता था, तब तक वो execute नहीं हो सकता था। इसे Contiguous Allocation in Hindi जैसे memory management तरीकों में साफ़ देखा जा सकता था, जहाँ memory की कमी से program crash हो जाते थे।

Virtual Memory इसी समस्या को हल करती है। यह तकनीक programmer के logical address space को system के physical address space से पूरी तरह अलग (separate) कर देती है:

  • Logical Memory (Virtual Memory): वह memory space जो CPU किसी process के लिए देखता है। यह बहुत बड़ा हो सकता है (जैसे 64-bit architecture में कई Terabytes)।
  • Physical Memory (RAM): वास्तविक physical hardware chip जो motherboard पर लगी होती है। इसका size limited होता है।
  • Secondary Storage (Swap Space / Pagefile): hard disk या SSD का वह reserved space, जहाँ RAM से बाहर निकाले गए pages अस्थायी रूप से store होते हैं। Windows में इसे pagefile.sys और Linux में swap partition कहते हैं।

Virtual Memory का सबसे बड़ा नियम यह है: किसी process को execute करने के लिए उसके पूरे code का एक साथ RAM में होना ज़रूरी नहीं है। Process का सिर्फ वही हिस्सा (page) RAM में रखा जाता है जो current instruction के लिए ज़रूरी हो, बाकी सब disk पर पड़ा रहता है।

Advertisement

Virtual Memory in OS with Diagram (Architecture)

Virtual Memory को implement करने के लिए hardware में MMU (Memory Management Unit) और OS के software algorithms मिलकर काम करते हैं। नीचे दिए गए architecture diagram से समझें कि CPU address कैसे map होता है:

+---------------+
|      CPU      |
+-------+-------+
        | Generates Logical Address (Page Number + Offset)
        v
+---------------+          Valid Bit = 1 (Page in RAM)
|   Page Table  | ------------------------------------> +-------------------+
|               |                                       |   Physical RAM    |
| [Page | Frame]|          Valid Bit = 0 (Page Fault!)  |   (Frames)        |
+-------+-------+ -------------------+                  +-------------------+
                                     |                            ^
                                     v                            | Swap In
                           +-------------------+                  | (Page fetch)
                           |   Operating       |                  |
                           |   System (Trap)   |                  |
                           +---------+---------+                  |
                                     |                            |
                                     v                            |
                           +-------------------+                  |
                           |  Secondary Disk   | -----------------+
                           |   (Swap Space)    |
                           +-------------------+

जब CPU कोई address generate करता है:

  1. CPU logical address भेजता है, जिसमें page number और offset होता है।
  2. MMU hardware Page Table में चेक करता है कि वो page RAM में मौजूद है या नहीं।
  3. हर page table entry में एक valid/invalid bit होता है। अगर bit 1 (valid) है, तो page RAM में है और execution बिना रुके जारी रहता है। इसे Page Hit कहते हैं।
  4. अगर bit 0 (invalid) है, तो इसका मतलब page अभी RAM में नहीं बल्कि disk पर है। इसे Page Fault कहते हैं।

Virtual Memory कैसे काम करती है? (Working Mechanism)

Virtual Memory मुख्य रूप से दो components पर आधारित होती है: Paging और Swapping। Modern operating systems में इसे Demand Paging के ज़रिए लागू किया जाता है।

1. Demand Paging

Demand Paging का सीधा मतलब है: "Page को RAM में केवल तभी लाओ जब CPU उसकी demand करे।" जब कोई process शुरू होता है, तो OS उसके सारे pages RAM में load नहीं करता। इसे lazy swapper (या pager) कहते हैं। जब CPU किसी instruction या data को access करता है और वो page RAM में नहीं मिलता, तब उसे disk से लाया जाता है।

2. Swapping (Page-level Swapping)

जब RAM पूरी भर जाती है और नए page के लिए जगह नहीं बचती, तो OS को RAM से किसी पुराने या कम इस्तेमाल होने वाले page को हटाकर hard disk (swap space) पर भेजना पड़ता है। इसे Swap Out कहते हैं। जब उस पुराने page की दोबारा ज़रूरत पड़ती है, तो उसे disk से वापस RAM में लाया जाता है, जिसे Swap In कहते हैं।

Page Fault क्या है और OS इसे कैसे Handle करता है?

Page Fault कोई system error या crash नहीं है, बल्कि यह एक hardware interrupt (trap) है जो CPU तब trigger करता है जब requested page physical RAM में नहीं मिलता (valid/invalid bit = 0)।

Operating System एक Page Fault को नीचे दिए गए 6 steps में resolve करता है:

  1. Trap to OS: Hardware detect करता है कि bit invalid है और OS को internal interrupt (trap) भेजता है। Process temporarily रुक जाता है।
  2. Internal Table Check: OS process के internal control block (PCB) को चेक करता है कि address valid है या invalid reference है। अगर address illegal था (memory protection violation), तो program तुरंत terminate कर दिया जाता है।
  3. Find on Disk: अगर reference valid है, तो OS disk के swap space में ढूँढता है कि वो page किस disk location पर store है।
  4. Find Free Frame in RAM: OS physical RAM में एक खाली frame (slot) खोजता है। अगर कोई frame खाली नहीं है, तो Page Replacement Algorithm चलाकर किसी victim page को swap out किया जाता है।
  5. Disk I/O (Read Page into RAM): Disk controller को command देकर required page को disk से लाकर RAM के free frame में copy किया जाता है। यह I/O operation होता है, इसलिए इसमें कुछ milliseconds का समय लगता है।
  6. Update Page Table & Restart: OS page table में उस page की entry update करता है (frame number लिखता है और bit को valid (1) सेट करता है)। फिर जिस instruction पर process रुका था, उसे ठीक उसी जगह से दोबारा restart कर दिया जाता है।

OS में frames को processes के बीच कैसे बाँटा जाता है, इसकी पूरी जानकारी यहाँ पढ़ें: Allocation of Frames in Hindi.

Solved Example: Page Replacement और Page Fault Trace

मान लें एक system में physical RAM के पास 3 free frames हैं। CPU नीचे दी गई reference string के order में pages access करता है:

Reference String: 7, 0, 1, 2, 0, 3, 0, 4

हम इसे FIFO (First-In, First-Out) algorithm से trace करते हैं। FIFO का नियम है: जो page सबसे पहले RAM में आया था, frame भर जाने पर सबसे पहले वही बाहर जाएगा।

Incoming Page Frame 1 Frame 2 Frame 3 Result (Hit / Fault) Reason
7 7 - - Page Fault Frame 1 खाली था, 7 load हुआ
0 7 0 - Page Fault Frame 2 खाली था, 0 load हुआ
1 7 0 1 Page Fault Frame 3 खाली था, 1 load हुआ
2 2 0 1 Page Fault RAM full; सबसे पुराना page 7 था, 7 की जगह 2 आया
0 2 0 1 Page Hit 0 पहले से Frame 2 में मौजूद है, कोई swap नहीं
3 2 3 1 Page Fault अगला सबसे पुराना page 0 था, 0 की जगह 3 आया
0 2 3 0 Page Fault अगला सबसे पुराना page 1 था, 1 की जगह 0 आया
4 4 3 0 Page Fault अगला सबसे पुराना page 2 था, 2 की जगह 4 आया

Performance Calculation

  • Total Page References = 8
  • Total Page Faults = 7
  • Total Page Hits = 1
  • Hit Ratio = (Hits / References) = 1 / 8 = 12.5%
  • Fault Ratio (Miss Ratio) = (Faults / References) = 7 / 8 = 87.5%

Exam में numerical solve करते समय हमेशा Hit और Miss दोनों का final count और ratio साफ़-साफ़ लिखें।

Virtual Memory vs Physical Memory (RAM)

छात्र अक्सर Virtual Memory और Physical RAM को एक ही समझ लेते हैं। नीचे दिए गए comparison table से दोनों के बीच का अंतर समझें:

Feature / Point Virtual Memory Physical Memory (RAM)
Nature एक technique / conceptual illusion है (hardware + software) वास्तविक physical semiconductor hardware chip है
Size Limit बहुत बड़ा size (secondary storage और CPU bit architecture पर निर्भर) limited size (motherboard slots और budget पर निर्भर, जैसे 8 GB/16 GB)
Speed धीमी (क्योंकि data secondary disk से आता है) बहुत तेज़ (CPU directly bus से access करता है)
Cost सस्ती (मौजूदा hard disk / SSD space का ही इस्तेमाल होता है) महंगी (per GB cost काफी ज़्यादा होती है)
Direct Access CPU इसे directly execute नहीं कर सकता; पहले RAM में लाना पड़ता है CPU physical memory को directly read/write कर सकता है
Location Hard disk / SSD के swap area / pagefile पर स्थित Motherboard के RAM DIMM slots में लगी होती है
Management Operating System और MMU से manage होती है Memory Controller hardware से manage होती है
Advertisement

Thrashing क्या है? (Thrashing in Virtual Memory)

Virtual Memory का सबसे बड़ा risk Thrashing कहलाता है।

जब system में physical RAM की तुलना में बहुत ज़्यादा processes run कर रहे हों, तो हर process को बहुत कम frames मिलते हैं। इस वजह से हर process लगातार page fault generate करने लगता है:

  1. Process P1 को page चाहिए, page fault हुआ। OS disk से page लाने में busy हो गया।
  2. उसी समय Process P2 को page चाहिए, फिर page fault हुआ।
  3. CPU instructions run करने के बजाय सिर्फ swapping (paging in and out) में अपना सारा समय बिताने लगता है।
  4. CPU utilization अचानक बहुत नीचे गिर जाता है (near 0%)।

Definition: जब कोई system execution के मुकाबले pages को swap-in और swap-out करने में ज़्यादा समय बिताने लगे, तो इस स्थिति को Thrashing कहते हैं।

Thrashing को रोकने के उपाय:

  • Degree of Multiprogramming कम करना: कुछ active processes को suspend कर देना।
  • Working Set Model: हर process को कम से कम उतने frames देना जितने उसके current working set के लिए ज़रूरी हैं।
  • Page Fault Frequency (PFF): Page fault rate की upper और lower limit तय करना। अगर fault rate high हो तो process को extra frame देना।

OS memory को internal operations के लिए कैसे सुरक्षित रखता है, इसके बारे में पढ़ें: Kernel Memory Allocation in Hindi.

Advantages और Disadvantages of Virtual Memory

Advantages (लाभ) Disadvantages (हानियाँ)
बड़े programs चलाना: RAM के physical size से बड़े software और games आसानी से run होते हैं। Performance drop: Hard disk की speed RAM से हज़ारों गुना कम होती है, जिससे swap के समय system slow हो सकता है।
Multiprogramming में वृद्धि: RAM में सिर्फ active pages रहते हैं, इसलिए एक साथ ज़्यादा programs open किए जा सकते हैं। Page Fault Overhead: बार-बार page fault होने पर context switch और disk I/O में CPU time बर्बाद होता है।
Memory Protection: हर process का virtual address space अलग होता है, जिससे कोई program दूसरे के memory data को corrupt नहीं कर सकता। Thrashing का ख़तरा: अगर memory बहुत कम पड़ जाए तो system hang या freeze हो सकता है।
Cost Saving: extra महंगी RAM खरीदे बिना ज़्यादा applications चला सकते हैं। Page Table Storage: बड़ी page tables को store करने के लिए extra memory खर्च होती है।

Virtual Memory: Students की Common Mistakes

University exams (BCA, B.Tech, MCA) में छात्र अक्सर ये गलतियाँ करते हैं, जिससे उनके marks कटते हैं:

  • Mistake 1: Virtual Memory को hardware chip समझना। कई छात्र लिख देते हैं कि "Virtual memory motherboard पर लगी एक chip होती है।" यह पूरी तरह गलत है। यह एक OS technique है जो hard disk space को borrow करती है।
  • Mistake 2: Page Fault को error या crash समझना। Page fault कोई bug या crash नहीं है। यह standard normal operation है जो OS को बताता है कि disk से page लाने की ज़रूरत है।
  • Mistake 3: Swapping और Paging में confuse होना। Classic Swapping में पूरा process बाहर और अंदर किया जाता है, जबकि Demand Paging में सिर्फ specific pages को swap-in और swap-out किया जाता है।
  • Mistake 4: FIFO anomaly (Belady's Anomaly) भूल जाना। कई बार छात्र लिखते हैं कि "RAM frames बढ़ाने से हमेशा page faults कम होते हैं।" FIFO algorithm में frames बढ़ाने पर भी page faults बढ़ सकते हैं, जिसे Belady's Anomaly कहते हैं।

Exam में कैसे लिखें (5 Marks Answer)

अगर exam में 5 marks का direct question आए: "Explain Virtual Memory in OS", तो answer sheet में सीधे इस structure में 8-10 points लिखें:

  1. Definition: Virtual memory operating system की वह memory management scheme है जो secondary memory को primary memory के extension के रूप में इस्तेमाल करती है।
  2. Core Principle: किसी process के execution के लिए उसके पूरे code का RAM में होना अनिवार्य नहीं है। केवल active pages RAM में रखे जाते हैं।
  3. Logical vs Physical Separation: यह technique logical address space को physical address space से decouple करती है, जिससे programmer को unconstrained memory मिलती है।
  4. Key Components: यह Demand Paging, Page Table, MMU और secondary storage के Swap Space पर काम करती है।
  5. Page Fault: जब CPU का request किया गया page RAM में नहीं मिलता (invalid bit), तो hardware trap generate होता है जिसे Page Fault कहते हैं।
  6. Resolution: OS disk से required page को free frame में swap-in करता है और page table update करके instruction restart करता है।
  7. Page Replacement: Frame खाली न होने पर FIFO, LRU या Optimal algorithm से victim page को swap-out किया जाता है।
  8. Major Benefits: High degree of multiprogramming, large address space, cost reduction और inter-process memory protection।
  9. Limitation: Excessive page faults से Thrashing हो सकती है, जिससे system performance drop हो जाता है।

Exam के लिए Important Questions

Short Questions (2–3 marks)

  1. Virtual Memory क्या है? (Secondary memory का RAM की तरह इस्तेमाल करने वाली OS technique)
  2. Page Fault क्या होता है? (Requested page का physical RAM में न मिलना)
  3. Demand Paging को define कीजिए। (Page को केवल demand होने पर ही RAM में लाना)
  4. Thrashing क्या है? (System का execution छोड़कर सारा समय page swapping में बर्बाद करना)
  5. Swap Space क्या होता है? (Hard disk या SSD का वह reserved हिस्सा जहाँ unmapped pages store होते हैं)

Long Questions (5–10 marks)

  1. Virtual Memory in OS क्या है? Demand Paging का working concept diagram के साथ समझाइए।
  2. Page Fault Handling के सभी steps को sequence में detail में describe कीजिए।
  3. Virtual Memory और Physical Memory में मुख्य अंतर क्या हैं? इसके advantages और disadvantages की तुलना कीजिए।
  4. Thrashing क्या है? यह क्यों उत्पन्न होती है और Operating System इसे कैसे detect और control करता है?

FAQs

Virtual memory in os in hindi का क्या मतलब है?

Operating System में virtual memory एक ऐसा mechanism है जो process को लगता है कि उसे एक बहुत बड़ी continuous memory मिली है, जबकि वास्तव में उसका data RAM और hard disk (swap space) के बीच टुकड़ों में बँटा होता है।

क्या Virtual Memory बढ़ाने से कंप्यूटर की speed बढ़ जाती है?

Virtual memory बढ़ाने से system crashes और "Out of Memory" errors रुकते हैं, लेकिन यह physical RAM की तरह computer को super-fast नहीं बनाती क्योंकि secondary storage (disk) की speed RAM से बहुत कम होती है। Speed बढ़ाने का सबसे अच्छा तरीका physical RAM बढ़ाना है।

Page Table में valid और invalid bit का क्या काम है?

Valid bit (1) बताता है कि संबंधित page physical RAM में मौजूद है। Invalid bit (0) बताता है कि page अभी RAM में नहीं है (disk पर है या illegal address है), जिससे Page Fault trigger होता है।

Virtual Memory कौन manage करता है - Hardware या Software?

यह दोनों के सहयोग से manage होती है। Address translation और trap generation का काम hardware (MMU) करता है, जबकि disk I/O, page replacement और page table updates का काम software यानी Operating System करता है।

अक्सर पूछे जाने वाले प्रश्न (FAQs)

Quick Answer: Operating system में Virtual Memory एक memory management technique है, जो secondary storage (जैसे hard disk या SSD) के एक हिस्से को temporary RAM की तरह इस्तेमाल करती है।
Operating System (OS) Notes in Hindi | ऑपरेटिंग सिस्टम नोट्स के पाठ्यक्रम में Virtual Memory in Hindi एक महत्वपूर्ण अध्याय है। यह मुख्य सिद्धांतों, परीक्षा प्रश्नों और सूत्रों को समझने के लिए अत्यधिक आवश्यक है।
हाँ, NotesMedia पर आपको Virtual Memory in Hindi के महत्वपूर्ण प्रश्नोत्तर, हल किए गए उदाहरण और नोट्स बिल्कुल मुफ्त मिलेंगे। अधिक अभ्यास के लिए आप हमारा ऐप भी डाउनलोड कर सकते हैं।
Advertisement

In this Chapter

Virtual Memory in Hindi
Distributed System in Hindi
Real Time System in Hindi
System Calls in Hindi
System Program in Hindi
Structure of Operating System in Hindi
Layers Design of Structure in Hindi
Unix in Hindi
Virtual Machine in Hindi
Kernel-Based Operating System in Hindi
Process in Hindi – OS में Process क्या है
Interacting Processes in Hindi
Threads in Hindi
Fundamental of Schedulling in Hindi
Scheduling Criteria in Hindi
Long Medium Short Term Scheduling in Hindi
Scheduling Algorithms in Hindi
Structure of Concurrent System in Hindi
Critical Region in Hindi
Critical Section in Hindi
Inter process Communication in Hindi
Monitor in Hindi
Semaphore in OS in Hindi – Counting और Binary Semaphore
Semaphores Implementation & Uses in Hindi
Logical and Physical Address in Hindi
Swapping in Hindi
Contiguous Allocation in Hindi
Segmentation in Hindi
Paging in OS in Hindi – Paging और Segmentation
Paging with Segmentation in Hindi
kernel Memory Allocation in Hindi
Page Replacement Algorithms in Hindi
Virtual Memory with demand Paging in Hindi
Deadlock & Characterization in Hindi
Methods for Handling Deadlocks in Hindi
Deadlock Thrashing in Hindi
Allocation of Frames in Hindi
Virtual Memory using Segmentation in Hindi
Interprocess Communication protocol in Hindi
Network Operating System in Hindi
Design Issues in Distributed File System in Hindi
Network Structure in Hindi
Structure Distributed System in Hindi
File System and Coordination in Hindi
Linux in Hindi
Commands of Linux in Hindi | लिनक्स के कमांड्स हिंदी में
Programmer Interface & File manipulation in Hindi
Process control in Linux in Hindi
Linux Kernel & Signals in Hindi
File System in Linux in Hindi
block & inodes in Hindi
System Editor in Hindi
Character Transliteration in Hindi
ED in Hindi
Vi Editor & There Commands in Hindi
Shell Script in Hindi
Looping & Decision Making in Hindi
Variables & File name Expansion in Hindi
Array in Hindi OS
Sub Program in Hindi
C interface with Linux in Hindi
Simpel Shell Programs in Hindi
BCA Part-1 | Operating Systems | Semester-I | MDSU Exam Paper 2023 (Held in 2024)
What is Operating System (OS) in Hindi
Operating System (OS) All Important Questions and Answers in Hindi (MDSU)
BCA || Operating System 2025 Paper || MDSU Exam Paper
BCA | OS(Operating System) 2023 Paper | MDSU Exam Paper
Type of Operating System in Hindi
Goals of Operating System in Hindi
Operation of Operating system in Hindi
Resource Allocation & Functions in Hindi
class of Operating system in Hindi
Batch Processing in Hindi
Multi Processing in Hindi
Time Sharing in Hindi