TheHingineer

  • Operating System


  • OS Part-1

  • OS Part-2

  • OS Part-3

  • OS Part-4

  • OS Part-5

  • Virtual Memory in Operating System

    🔹 Introduction

    Virtual Memory ek memory management technique hai jo processes ko required se zyada memory allocate karne ka illusion deti hai, even if physical RAM utni available na ho. Iska kaam secondary storage (HDD/SSD) ko RAM ke extension ke tarah use karna hota hai.

    ✅ Why Virtual Memory?

    • Jab processes ka size available RAM se zyada hota hai tab Virtual Memory ka use hota hai.

    • Ye OS ko multiple processes efficiently manage karne me madad karti hai.

    • Disk space ko temporarily RAM ke tarah use karke execution allow karti hai.


    🔹 How Virtual Memory Works?

    Virtual Memory logical address space aur physical address space ko alag kar deti hai. Jab kisi process ko extra memory chahiye hoti hai, to OS uske kuch parts ko secondary storage me swap kar deta hai aur zaroorat padne par wapas RAM me load karta hai.

    Main Steps:

    1. 1. CPU ek logical address generate karta hai.

    2. 2. Page Table mapping ke through ye address physical memory me translate hota hai.

    3. 3. Agar required page memory me hai to process continue hota hai (Page Hit).

    4. 4. Agar page memory me nahi hai to page fault aata hai aur OS us page ko secondary storage se RAM me load karta hai.

    👉 Diagram: Virtual Memory Working

    CPU → Logical Address → Page Table → Physical Memory / Disk


    🔹 Components of Virtual Memory

    Virtual Memory ke kuch important components hote hain:

    Component Description
    Paging Process ko pages me divide karta hai aur physical memory me frames assign karta hai
    Page Table Logical aur Physical address mapping store karta hai
    Swap Space HDD/SSD ka part jo temporarily pages store karta hai
    Page Fault Handler Jab required page memory me nahi hota, to usko RAM me load karta hai
    TLB (Translation Lookaside Buffer) Fast memory jo frequently accessed pages ka translation store karti hai

    🔹 Demand Paging

    ✅ Demand Paging ek aisi technique hai jo tabhi pages ko memory me load karti hai jab unki zaroorat ho.
    ✅ Isse memory efficient hoti hai kyunki unused pages memory me load nahi hote.
    ✅ Agar page memory me nahi hota to “Page Fault” hota hai aur OS us page ko disk se laake memory me load karta hai.

    👉 Diagram: Demand Paging Working

    Process Requests PageIf Page in MemoryExecute
                          → If Page NOT in MemoryPage FaultLoad Page from Disk


    🔹 Page Replacement Algorithms

    Jab memory full hoti hai aur naye page ko load karna padta hai, tab OS kisi existing page ko remove karta hai. Ye page replacement algorithms use hote hain:

    Algorithm Working Pros & Cons
    FIFO (First In First Out) Sabse purana page replace hota hai Simple but inefficient
    LRU (Least Recently Used) Jo sabse kam use hua hai, usko replace karta hai Better performance
    Optimal Page Replacement Jo future me sabse late use hoga, usko replace karta hai Best but practically impossible

    🔹 Advantages of Virtual Memory

    ✅ Badi processes ko execute kar sakti hai even if RAM kam ho
    ✅ Multiple programs ek saath efficiently execute hote hain
    ✅ Less frequent program crashes due to memory limitations
    ✅ Memory protection provide karta hai


    🔹 Disadvantages of Virtual Memory

    ❌ Agar zyada pages swap hone lage to system slow ho jata hai (Thrashing)
    ❌ Disk pe frequent read/write hone se performance degrade ho sakti hai
    ❌ Hardware aur software support chahiye hota hai (MMU – Memory Management Unit)


    🔹 Conclusion

    ✔ Virtual Memory ek powerful technique hai jo processes ko required se zyada memory allocate karne ka illusion deti hai.
    ✔ Demand Paging aur Page Replacement Algorithms ka use karke OS efficiently memory manage karta hai.
    ✔ Virtual Memory ka correct implementation system performance aur efficiency improve karta hai.

    Scroll to Top