TheHingineer

  • Operating System


  • OS Part-1

  • OS Part-2

  • OS Part-3

  • OS Part-4

  • OS Part-5

  • Segmentation in Operating System

    🔹 Introduction to Segmentation

    Segmentation ek memory management technique hai jo user ke program ko multiple logical segments me todh deti hai.
    Har segment ka apna alag address space hota hai, jo same type ke data ko store karta hai.

    ✅ Why Segmentation?

    • Paging fixed-size blocks (pages) ka use karta hai, jabki Segmentation logical division provide karta hai.

    • Programs alag-alag functional segments me divide kiye ja sakte hain, jaise code, stack, heap, data, etc.

    • Logical structure ke according memory allocate hoti hai, isse memory efficiently use hoti hai.


    🔹 How Segmentation Works?

    Segmentation me process ka logical address space multiple variable-size segments me divide hota hai.
    Har segment ka apna ek segment number aur size hota hai, jo Segment Table me store hota hai.

    🖼 Diagram (Segmentation Process)

    Logical Address Space (Segments) Physical Memory
    +----------+----------+-------+ +-----------+-------+----------+
    | Segment 1| Segment 2| Stack | | Segment 2 | Stack | Segment 1|
    +----------+----------+-------+ +-----------+-------+----------+

    👉 Segments ka size fixed nahi hota, balki program ke logic ke basis pe define hota hai.

    Steps in Segmentation:

    1️⃣ Process ke Logical Address Space ko multiple Segments me divide kiya jata hai.
    2️⃣ Segment Table mapping maintain karti hai, jo batati hai ki kaunsa Segment kaunsa Physical Address use kar raha hai.
    3️⃣ Jab CPU kisi address ko access karta hai, toh Segment Table ke through Physical Address fetch kiya jata hai.


    🔹 Address Translation in Segmentation

    Segmentation me Logical Address ko Physical Address me convert karna hota hai, jo Segment Table ke through hota hai.

    Address Calculation Formula:

    Physical Address=Base Address of Segment+Offset

    Example:

    Agar Segment 2 ka Base Address = 5000 ho aur CPU Logical Address = (Segment Number = 2, Offset = 1200 bytes) ho, toh:

    Physical Address=5000+1200=6200

    👉 Final Physical Address = 6200 bytes.


    🔹 Advantages of Segmentation

    ✅ Logical Organization: Programs different logical units me divide ho sakte hain (Code, Data, Stack, Heap).
    ✅ Efficient Memory Allocation: Process ka jitna required memory space hota hai, utna hi allocate hota hai.
    ✅ Better User View: Segmentation user ke program ke logical structure ko follow karti hai, isliye performance aur understanding better hoti hai.


    🔹 Disadvantages of Segmentation

    ❌ External Fragmentation: Kyunki segments variable-size ke hote hain, toh unused memory spaces bach sakti hain.
    ❌ Complex Address Translation: CPU ko Segment Table ko access karna padta hai, jo paging ke comparison me thoda slow hota hai.


    🔹 Comparison: Paging vs. Segmentation

    Feature Paging Segmentation
    Division Type Fixed-size blocks (Pages) Logical units (Segments)
    Fragmentation No external, but internal fragmentation External fragmentation possible
    Memory Utilization Efficient, but fixed-size allocation More flexible, but fragmentation risk
    Mapping Page Table Segment Table

    🔹 Conclusion

    ✔ Segmentation ek logical memory management technique hai, jo user programs ko meaningful logical segments me todhti hai.
    ✔ Segment Table address translation me use hoti hai, jisme Base Address aur Offset ka calculation hota hai.
    ✔ Segmentation external fragmentation se suffer karti hai, but logical program structure ko support karti hai.

    Scroll to Top