BCA / B.Tech 13 min read

Swapping in Hindi

RK

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

प्रकाशित:

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

  • • विषय फोकस: Operating System (OS) Notes in Hindi | ऑपरेटिंग सिस्टम नोट्स (BCA / B.Tech Syllabus)
  • • मुख्य विषय: Swapping in Hindi - General Topics
  • • अवलोकन: Quick Answer: Operating system में Swapping एक memory management technique है, जिसमें जब RAM (main memory) भर जाती है, तो किसी inactive या low-priority...
  • • मुख्य अवधारणाएं: Swapping, Memory management context switch Hindi, Swap space swapping,Swapping, Memory management context switch, Swap space swapping
Quick Answer: Operating system में Swapping एक memory management technique है, जिसमें जब RAM (main memory) भर जाती है, तो किसी inactive या low-priority process को temporarily RAM से निकालकर secondary storage (hard disk या SSD के swap space) पर save कर दिया जाता है (Swap Out)। बाद में जब RAM में space खाली होता है या उस process का turn आता है, तो उसे disk से वापस RAM में load कर लिया जाता है (Swap In)। इससे limited RAM में भी एक साथ कई processes execute हो पाते हैं और system का degree of multiprogramming बढ़ जाता है।

Swapping in OS क्या है? (Swapping Meaning in Computer)

कंप्यूटर में "Swap" शब्द का सीधा मतलब है अदला-बदली (exchange)। जब आप computer पर एक साथ कई heavy software (जैसे Chrome browser, IDE, video player) चलाते हैं, तो उन सभी programs को एक साथ RAM (main memory) में रखने के लिए space कम पड़ जाता है।

CPU सिर्फ उन्हीं instructions को execute कर सकता है जो RAM में मौजूद हों। अगर RAM का size 4 GB है और चल रहे processes को 6 GB space चाहिए, तो normal तरीके से system नए process को start ही नहीं करने देगा। इसी problem को solve करने के लिए OS Swapping का use करता है।

Swapping में operating system memory manager की मदद से उन processes को चुनता है जो currently CPU का use नहीं कर रहे (जैसे जो user input का wait कर रहे हैं या जिनकी priority कम है)। OS इन processes को RAM से copy करके hard disk या secondary storage के एक खास हिस्से (backing store / swap space) पर move कर देता है। जैसे ही RAM में जगह बनती है, रुका हुआ process वापस RAM में आ जाता है और execution continue करता है।

Memory allocation के basic तरीके समझने के लिए देखें: Contiguous Allocation in Hindi.

Swapping in Hindi

Operating system में Swapping का diagram: RAM और disk के बीच process का Swap Out और Swap In।

Advertisement

Swapping Diagram in OS (Architecture)

Swapping का standard architecture नीचे दिए गए diagram से समझा जा सकता है:

+-------------------------------------------------------+
|                    MAIN MEMORY (RAM)                  |
|  +--------------------+                               |
|  |  Operating System  |                               |
|  +--------------------+                               |
|  |  Process P1        | ====== Swap Out ======> +---+ |
|  |  (Blocked / Idle)  |                         |   | |
|  +--------------------+                         | D | |
|  |  Process P2        | <====== Swap In ======= | I | |
|  |  (Ready to Run)    |                         | S | |
|  +--------------------+                         | K | |
|  |  Free Memory Space |                         |   | |
|  +--------------------+                         +---+ |
+-------------------------------------------------------+
                      BACKING STORE (Swap Space)

यहाँ Backing Store आम तौर पर एक fast secondary storage (hard disk partition या SSD block) होता है, जो इतना बड़ा होता है कि user के सभी processes की memory copies को store कर सके।

Swap In और Swap Out क्या है? (Swapping Operations)

Swapping में मुख्य रूप से दो operations लगातार काम करते हैं:

1. Swap Out Operation

जब main memory में नए process के लिए जगह नहीं बचती, या कोई high priority process ready queue में आता है, तो medium-term scheduler किसी current process को RAM से हटाकर backing store (disk) पर write कर देता है। इस action को Swap Out कहते हैं। Swap out होने के बाद process की state Waiting/Suspended state बन जाती है और RAM का space free हो जाता है।

2. Swap In Operation

जब RAM में पर्याप्त memory free हो जाती है, या swap out किए गए process का execution time आता है, तो OS disk से उस process के image/data को वापस पढ़ता है और RAM के free space में load कर देता है। इसे Swap In कहते हैं। Swap in होते ही process दोबारा Ready state में आ जाता है और CPU scheduler उसे execute कर सकता है।

Swap Out vs Swap In (तुलना)

Point Swap Out Swap In
Data Movement RAM (Main Memory) से Disk (Secondary Storage) Disk (Secondary Storage) से RAM (Main Memory)
कब होता है? जब RAM full हो या high-priority process आए जब RAM खाली हो और suspended process को चलना हो
Memory पर असर RAM में free space create करता है RAM के free space को occupy करता है
Process State Ready/Running से Suspended Blocked बनती है Suspended से Ready queue में वापस आता है
Disk Operation Disk पर Write operation होता है Disk से Read operation होता है

Address Binding और Swapping का Relation

BCA और B.Tech exams में एक conceptual question बार-बार पूछा जाता है: "क्या swap in होने के बाद process उसी purani memory location पर वापस आएगा?" इसका answer process के Address Binding method पर निर्भर करता है:

  • Compile Time / Load Time Binding: अगर process के memory addresses compile time या load time पर fix हो चुके हैं, तो swap in होने पर process को RAM के उसी exact physical address पर वापस load होना पड़ेगा जहाँ वह पहले था। अगर वह slot busy है, तो process wait करेगा।
  • Execution Time (Dynamic) Binding: Modern operating systems execution time address binding use करते हैं। इसमें CPU run time पर base register और relocation register की मदद से logical address को physical address में बदलता है। इसका सबसे बड़ा फायदा यह है कि swap in होने पर process RAM के किसी भी available free frame या block में load हो सकता है।

Swap Space Management in OS in Hindi

Operating system hard disk के एक हिस्से को regular file system से अलग रखता है ताकि swapping fast speed से हो सके। इसे Swap Space कहते हैं।

Swap space को manage करने के लिए OS दो strategies use करता है:

  1. Separate Disk Partition (Raw Partition): Disk पर एक dedicated partition बना दिया जाता है (जैसे Linux का swap partition)। इसमें कोई standard file system (जैसे ext4 या NTFS) नहीं होता। OS सीधा raw disk blocks पर data write करता है, जिससे file lookup का overhead खत्म हो जाता है और speed maximum मिलती है।
  2. Swap File: Regular file system के अंदर एक बड़ी fixed-size file बनाई जाती है (जैसे Windows में pagefile.sys)। इसे resize करना आसान होता है, लेकिन regular directory structure से होकर गुजरने के कारण यह dedicated partition से थोड़ी धीमी होती है।

Linux operating system में swap space कैसे manage होता है, इसके commands और structure के लिए पढ़ें: Linux in Hindi.

Solved Example: Swapping का Trace और Transfer Time Calculation

Swapping का exact working समझने के लिए नीचे दिए गए दोनों real scenarios को ध्यान से देखिए:

Scenario 1: Memory Allocation और Swap Trace

मान लीजिए एक computer system में usable RAM = 4 GB है। System में तीन processes run होना चाहते हैं: Process P1 (2 GB), Process P2 (2 GB), और Process P3 (2 GB)। Timeline पर swapping का step-by-step trace इस प्रकार होगा:

Time Step Action RAM की स्थिति (Total 4 GB) Disk (Swap Space) की स्थिति
T0 (Start) P1 और P2 memory में load हुए P1 (2 GB) + P2 (2 GB) = Full खाली
T1 New Process P3 (2 GB) arrive हुआ P1 और P2 चल रहे हैं, P3 को जगह नहीं P3 queue में wait कर रहा है
T2 P1 I/O wait में गया; OS ने P1 को Swap Out किया P2 (2 GB) + 2 GB Free P1 (2 GB) disk पर save हुआ
T3 OS ने P3 को RAM में Swap In किया P2 (2 GB) + P3 (2 GB) = Full P1 disk पर मौजूद है
T4 P2 complete होकर exit हुआ P3 (2 GB) + 2 GB Free P1 disk पर मौजूद है
T5 OS ने P1 को वापस Swap In किया P3 (2 GB) + P1 (2 GB) = Full Swap space खाली

Scenario 2: Swap Transfer Time की Numerical Calculation

Exam में numerical question आता है: "Swapping में context switch time कितना लगता है?"

मान लीजिए:

  • User process का size = 100 MB
  • Hard disk का transfer rate = 50 MB/sec
  • Average disk latency / seek time = 8 ms (0.008 seconds)

Calculation:

1. Process को disk पर Swap Out करने का time:

Transfer Time = Process Size / Transfer Rate
              = 100 MB / 50 MB/sec = 2.0 seconds
Total Swap Out Time = 2.0 seconds + 0.008 seconds = 2.008 seconds

2. नए process को RAM में Swap In करने का time:

Total Swap In Time = 2.0 seconds + 0.008 seconds = 2.008 seconds

3. Total Context Switch Overhead:

Total Time = Swap Out Time + Swap In Time
           = 2.008 + 2.008 = 4.016 seconds (~4016 ms)

Result: CPU का normal context switch micro-seconds में होता है, लेकिन swapping के साथ यह बढ़कर 4 seconds से ज़्यादा हो गया। इसीलिए modern OS पूरे 100 MB process को एक साथ swap करने के बजाय सिर्फ required pages को swap करते हैं (Paging)।

Swapping vs Paging (तुलना)

Students अक्सर swapping और paging को एक ही समझ लेते हैं। नीचे दी गई table से इनका basic difference समझिए:

Feature Traditional Swapping Paging (Demand Paging)
Unit of Transfer पूरा का पूरा Process एक साथ transfer होता है सिर्फ fixed-size Page (जैसे 4 KB) transfer होता है
Memory Requirement Process को RAM में लगातार (contiguous) space चाहिए Non-contiguous frames में भी page रखा जा सकता है
Disk I/O Overhead बहुत ज़्यादा (पूरा 100 MB–1 GB process read/write) बहुत कम (सिर्फ 4 KB का single page read/write)
Fragmentation External fragmentation की problem हो सकती है External fragmentation नहीं होता, internal fragmentation बहुत कम
Modern OS Use Pure रूप में use नहीं होता Modern OS (Windows, Linux) paging-based swapping use करते हैं

Kernel level पर memory chunks कैसे allocate होते हैं, इसके लिए देखें: Kernel Memory Allocation in Hindi.

Advertisement

Advantages और Disadvantages of Swapping

Advantages (फायदे)

  • Higher Degree of Multiprogramming: RAM का physical size limited होने पर भी system कई सारे programs को active रख सकता है।
  • Priority-based Scheduling: अगर कोई high-priority task आ जाए, तो कम जरूरी process को तुरंत disk पर भेजकर resources critical task को दिए जा सकते हैं।
  • Better CPU Utilization: CPU कभी idle नहीं बैठता; अगर RAM का process I/O block हो, तो दूसरे process को तुरंत swap in करके CPU busy रखा जाता है।
  • Cost Effective: Expensive RAM बढ़ाए बिना user को बड़े applications run करने की facility मिल जाती है क्योंकि disk storage बहुत cheap होता है।

Disadvantages (नुकसान)

  • Performance Penalty (High Latency): Hard disk या SSD की speed RAM से सैकड़ों गुना धीमी होती है। बार-बार swapping होने से system freeze या slow महसूस होता है।
  • Thrashing की Problem: जब RAM बहुत छोटी हो और active processes बहुत ज़्यादा हों, तो system execution करने के बजाय अपना सारा time सिर्फ swap in और swap out करने में बर्बाद कर देता है। इसे Thrashing कहते हैं।
  • Pending I/O Hazard: अगर किसी process का data disk से read होकर RAM में आ रहा हो और OS उसी समय उस process को swap out कर दे, तो new incoming data किसी गलत process की memory को corrupt कर सकता है। इससे बचने के लिए OS को memory buffer lock करना पड़ता है।

Processes आपस में communication और shared data कैसे manage करते हैं, इसके लिए पढ़ें: Inter Process Communication in Hindi.

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

अगर university exam (BCA/MCA/B.Tech) में 5 marks का question आए "Swapping क्या है? इसके फायदे और नुकसान लिखिए", तो answer sheet में सीधे इस structure में 8–10 points लिखें:

  1. Definition: Swapping एक memory management method है जिसमें processes को RAM और backing store (secondary storage) के बीच temporarily transfer किया जाता है।
  2. Core Operations: इसमें दो operations होते हैं: (a) Swap Out (RAM से Disk पर भेजना) और (b) Swap In (Disk से RAM में वापस लाना)।
  3. Scheduler: इस कार्य को Medium-Term Scheduler manage करता है।
  4. Objective: इसका मुख्य उद्देश्य Degree of Multiprogramming और CPU utilization को बढ़ाना है।
  5. Diagram: RAM, CPU, और Backing Store के बीच Swap In/Out का एक साफ block diagram बनाएँ।
  6. Address Binding: Execution-time dynamic binding होने पर process RAM में किसी भी available free location पर वापस आ सकता है।
  7. Two Advantages: Limited RAM में larger applications run हो पाते हैं; priority-based processes को तुरंत RAM मिल जाती है।
  8. Two Disadvantages: Disk I/O slow होने से high context switch overhead आता है; over-swapping से Thrashing हो सकती है।

Students की 4 आम गलतियाँ (Common Mistakes)

  • गलती 1: Paging और Swapping को identical समझना। Traditional swapping में पूरा process move होता है, जबकि paging में केवल 4 KB के छोटे pages move होते हैं। Modern OS pure swapping use नहीं करते, बल्कि page swapping (demand paging) use करते हैं।
  • गलती 2: CPU Scheduler को swapping का जिम्मेदार मानना। CPU scheduler (short-term scheduler) ready processes को CPU assign करता है। Swapping का फैसला Medium-Term Scheduler करता है।
  • गलती 3: Swap Time calculation में disk transfer time छोड़ देना। कई students सिर्फ RAM access time जोड़ते हैं। Swapping में 99% time disk seek time और data transfer rate में खर्च होता है।
  • गलती 4: Pending I/O risk को ignore करना। I/O operation complete होने से पहले process को swap out करने से data memory corruption हो सकती है। इसे रोकने के लिए I/O transfer हमेशा kernel buffer के through होना चाहिए।

Exam के लिए Important Questions

Short Questions (2–3 marks)

  1. Swapping in OS क्या है? (RAM और secondary storage के बीच processes की temporary shifting)
  2. Swap Out और Swap In में मुख्य अंतर क्या है? (Swap Out memory free करता है, Swap In disk से data memory में लाता है)
  3. Swap Space क्या होता है? (Hard disk का reserved partition या file जहाँ swapped-out data रखा जाता है)
  4. Thrashing क्या है? (जब system execution से ज़्यादा time swapping में spend करने लगे)
  5. Medium-term scheduler का क्या role है? (यह processes को swap out और swap in करने का decision लेता है)

Long Questions (5–10 marks)

  1. Operating system में Swapping concept को diagram, operations (Swap In/Out), और address binding के साथ detail में समझाइए।
  2. Swapping और Paging में अंतर स्पष्ट कीजिए। Swapping में transfer time overhead कैसे calculate किया जाता है? Example देकर समझाइए।
  3. Swap space management क्या है? Dedicated swap partition और swap file system के merits और demerits की तुलना कीजिए।

FAQs

Swapping in OS in Hindi क्या है?

Operating system में swapping एक ऐसी technique है जिससे कम RAM होने पर भी बड़े और अधिक processes run किए जा सकते हैं। इसमें idle processes को hard disk के swap area में shift किया जाता है और जरूरत पड़ने पर वापस RAM में लाया जाता है।

क्या swapping से computer slow हो जाता है?

हाँ, क्योंकि hard disk और SSD की data read/write speed RAM की तुलना में काफी कम होती है। जब system बार-बार data swap out और swap in करता है, तो CPU को disk I/O का wait करना पड़ता है, जिससे system lag करने लगता है।

Swapping और Thrashing में क्या relation है?

जब main memory में processes की संख्या बहुत ज़्यादा हो जाती है और RAM बहुत कम, तो system continuously pages या processes को swap in और swap out करने लगता है। इस स्थिति को Thrashing कहते हैं, जिससे CPU utilization गिरकर लगभग 0% हो जाता है।

क्या modern operating systems में pure swapping use होती है?

नहीं, modern operating systems (जैसे Windows 11 या Linux) traditional pure swapping (पूरे process को एक साथ move करना) use नहीं करते। वे Paging with Page Swapping (Demand Paging) use करते हैं, जिसमें सिर्फ वही pages swap out होते हैं जिनकी तुरंत जरूरत नहीं होती।

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

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

In this Chapter

Swapping 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
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 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