4.2.27 · HinglishOperating Systems

Segmentation — segment table, protection

1,687 words8 min readRead in English

4.2.27 · Coding › Operating Systems


WHAT is a segment?

Key contrast yeh hai: paging mein saare blocks ek hi fixed size ke hote hain aur yeh split programmer ko dikhai nahi deta. Segmentation mein blocks alag-alag sizes ke hote hain aur programmer ko visible/meaningful hote hain.


HOW the segment table works (derive the translation)

Hume logical pair ko ek real physical address mein convert karna hai. Chaliye machinery scratch se banate hain.

Step 1 — Segment physical memory mein kahan rehta hai? Har segment contiguous hota hai, toh hume sirf uska starting physical address chahiye. Ise base kehte hain.

Step 2 — Segment kitna bada hai? Kyunki segments ki length alag-alag hoti hai, hume har segment ka limit (length) store karna padta hai taaki program apne end ke baad read na kar sake.

Toh har segment ke liye hum do numbers store karte hain: . Inhi pairs ki table ko segment table kehte hain. Register STBR (Segment Table Base Register) table ko point karta hai; STLR (Segment Table Length Register) batata hai ki kitni entries valid hain.

Step 3 — Translation formula

Figure — Segmentation — segment table, protection

Protection — the real payoff

Har segment-table entry ko extend kiya jaata hai:

Field Meaning
base physical start address
limit length (bounds check)
R/W/X bits read / write / execute permissions
valid bit kya yeh segment present/legal hai?

Worked Examples


Common Mistakes (Steel-manned)


Flashcards

Segmentation logical address ke do parts kya hote hain?
Segment number aur offset/displacement .
Segment-table entry mein minimum kaun se do fields hote hain?
Base (physical start) aur limit (length).
ke liye address-translation rule likhiye.
Agar toh physical ; warna trap (segmentation fault).
Bounds check strict kyun hota hai (, nahi)?
Valid offsets hote hain; allow karne se next segment mein read ho jaata hai.
Segment table ko kaunsa register point karta hai, aur uski length kaun deta hai?
STBR (base) aur STLR (length).
Segmentation safe code sharing kaise enable karta hai?
Do processes ki table entries same base/limit ko R/X permission ke saath point karti hain → ek shared copy.
Ek segment entry mein kaunse protection bits hote hain?
Read, Write, Execute (aur ek valid bit).
R/X code segment par write kyun trap karta hai jab offset in-bounds ho?
Bounds OK ≠ permission OK; write permission bit 0 hai → protection fault.
Pure segmentation mein kaun si fragmentation hoti hai?
External fragmentation (variable-size holes); koi internal fragmentation nahi.
Segmentation vs paging — block size kaun decide karta hai?
Segmentation: programmer/logical (variable). Paging: system (fixed).

Recall Feynman: ek 12-saal ke bachche ko samjhao

Socho tumhara school ka saman labelled boxes mein hai: ek "Homework" box, ek "Lunch" box, ek "Games" box. Kuch dhundhne ke liye tum kehte ho "Box: Games, item 3" instead of ek giant number yaad karne ke. Teacher (OS) ek list rakhti hai jo batati hai har box shelf par kahan hai (base) aur kitni badi hai (limit). Agar tum ek aise box se item 50 maango jisme sirf 10 cheezein hain, toh teacher tumhe rokegi — yahi segmentation fault hai. Aur "Games" box sirf dekhne ke liye ho sakta hai (likhna allowed nahi) — isme likhne ki koshish karo aur tum block ho jaoge. Har box ka yeh label idea segmentation hai, aur box ke rules protection hain.

Connections

  • Paging — page table, TLB — fixed-size counterpart; combine into Segmented Paging.
  • Memory Management — base & limit registers — segmentation = bahut saare base/limit pairs.
  • External vs Internal Fragmentation — segmentation → external; paging → internal.
  • Address Translation & MMU — hardware jo perform karta hai.
  • Shared Libraries & Dynamic Linking — shared read-only segments par built.
  • Protection & Memory Safety — R/W/X bits, segmentation fault traps.

Concept Map

split into

addressed by

s indexes

points to

bounds valid entries

stores base b_s

stores limit L_s

check d < L_s

no, trap

yes

physical = b_s + d

holds permission bits

per-unit R/W/X

Program logical units

Segments

Logical address (s, d)

Segment table

STBR register

STLR register

Base

Limit

Valid?

Segmentation fault

Physical address

Protection