TheHingineer

  • Operating System


  • OS Part-1

  • OS Part-2

  • OS Part-3

  • OS Part-4

  • OS Part-5

  • Allocation of Frames & Thrashing in Operating System

    🔹 Introduction

    Memory management ka ek important aspect frame allocation aur thrashing hai.

    • -> Frame Allocation: Ye decide karta hai ki process ko kitni memory (frames) assign ki jayegi.

    • -> Thrashing: Jab CPU ka zyada time page swapping me chala jata hai aur actual execution slow ho jati hai.

    🚀 Agar memory properly allocate nahi ki jaye, to system thrashing ka shikar ho sakta hai!


    🔹 Allocation of Frames

    Paging system me memory ko small fixed-size blocks (frames) me divide kiya jata hai. Jab koi process execute hota hai, tab uske pages ko available frames me load kiya jata hai.

    ✅ Frame Allocation ka goal:

    1. -> Efficient memory utilization

    2. -> Minimum page faults

    3. -> Process execution ko optimize karna

    📌 Types of Frame Allocation Policies

    1️⃣ Equal Allocation

    • Har process ko equal number of frames diye jate hain.

    • Agar total frames = 10 aur 2 processes hain, to har process ko 5 frames milenge.

    ✔ Advantage: Simple aur easy to implement
    ❌ Disadvantage: Agar ek process zyada memory demand kare aur doosra kam, tab bhi dono ko equal frames milenge → memory wastage ho sakti hai.


    2️⃣ Proportional Allocation

    • Har process ko uski size ke basis par frames allocate kiye jate hain.

    ✔ Advantage: Large processes ko zyada memory milti hai → better performance
    ❌ Disadvantage: Small processes ke liye zyada memory allocate nahi hoti.

    📝 Example:
    Maan lo total 100 frames available hain, aur

    • Process P1 = 200 KB

    • Process P2 = 300 KB

    Total size = 200 + 300 = 500 KB

    Frame allocation:

    • P1 ke liye: (200/500) × 100 = 40 frames

    • P2 ke liye: (300/500) × 100 = 60 frames


    3️⃣ Priority-Based Allocation

    • Process ke priority ke basis par frames allocate hote hain.

    • Higher priority wale process ko zyada frames milte hain.

    ✔ Advantage: Important processes ko better performance milti hai.
    ❌ Disadvantage: Low priority wale processes starvation face kar sakte hain.


    4️⃣ Global vs Local Allocation

    🔹 Global Allocation: Process kisi bhi available free frame ko use kar sakta hai.
    🔹 Local Allocation: Process sirf apne allocated frames ke andar page replace kar sakta hai.


    🔹 Thrashing in Operating System

    **Thrashing ek situation hai jisme CPU zyada time page swapping me spend karta hai aur actual execution slow ho jati hai.

    📌 Why Thrashing Occurs?

    ✅ Jab process ko sufficient frames nahi milte, to continuous page faults hone lagte hain.
    ✅ CPU baar-baar naye pages ko memory me swap karta hai, aur process execution slow ho jata hai.


    🔹 Working of Thrashing

    🔹 Jab CPU kisi page ko access karna chahta hai jo memory me available nahi hai, to page fault hota hai.
    🔹 Agar page faults zyada hone lagte hain, to OS naye pages ko load karta hai aur purane pages ko replace karta hai.
    🔹 Agar naye pages bhi jaldi replace ho jate hain, to process continuously page faults generate karta hai!
    🔹 Ye cycle repeat hoti hai aur system slow ho jata hai.

    📝 Example:

    • Maan lo ek process ko 10 pages ki zaroorat hai, lekin sirf 4 frames available hain

    • Process baar-baar naye pages ko laata hai aur purane pages ko replace karta hai

    • CPU ka zyada time swapping me chala jata hai, aur execution slow ho jati hai

    📉 Result: CPU 100% busy hota hai, lekin effective work 0% hota hai!


    🔹 How to Prevent Thrashing?

    ✅ Working Set Model:

    • Process ka currently required pages ka set (Working Set) memory me rakha jaye.

    • Agar working set ke pages memory me hain, to page faults kam honge.

    ✅ Page Fault Frequency (PFF) Algorithm:

    • Agar page faults high hain, to process ko zyada frames diye jaye.

    • Agar page faults kam hain, to extra frames kisi aur process ko de diye jaye.

    ✅ Local Replacement Policy:

    • Process apne allocated frames ke andar hi page replace kare taaki doosre processes affect na ho.

    ✅ Increase RAM:

    • Agar RAM zyada hogi, to page faults automatically reduce honge aur thrashing avoid hogi.


    🔹 Conclusion

    ✔ Frame allocation ka sahi selection system ki performance ko optimize karta hai.
    ✔ Thrashing ek serious issue hai jo system performance ko drastically reduce kar sakta hai.
    ✔ Working Set Model aur Page Fault Frequency ka use karke thrashing avoid ki ja sakti hai.

    Scroll to Top