4.2.24 · D3 · HinglishOperating Systems

Worked examplesFragmentation — internal vs external, compaction

2,509 words11 min read↑ Read in English

4.2.24 · D3 · Coding › Operating Systems › Fragmentation — internal vs external, compaction

Yeh page ek drill hai. Hum parent topic ke do formulas lete hain aur unhe har tarah ke input ke against beat karte hain — clean numbers, exact fits, tiny processes, huge processes, degenerate "one hole" case, ek word problem, aur ek exam trap.

Shuru karne se pehle, teen symbols poore page ko carry karte hain. Hum inhe zero se define karte hain:

marks ceiling hain — "agale pure number tak upar round karo". Hum ko padhte hain: "2.44 blocks exist nahi karta, isliye tumhe 3 pure blocks chahiye." Upar kyun aur neeche kabhi nahi? Kyunki neeche rounding karne se process ke kuch bytes bina ghar ke reh jaate — yeh illegal hai. Har bacha hua byte ek naya block force karta hai.


The scenario matrix

Yeh har distinct case class hai jo fragmentation tumhare saamne rakh sakta hai. Neeche ke examples mein har ek apna covered cell name karta hai.

Cell Case class Isme kya special hai
A Internal, non-exact fit ka ka multiple nahi → kuch waste
B Internal, exact fit (degenerate) ka multiple hai → waste zero
C Internal, tiny process () 1 block chahiye, uska almost sab waste
D Internal, many processes (system total) kaafi tails ka sum; average each
E External, scattered holes ratio 0 aur 1 ke beech
F External, one single hole (degenerate) ratio , perfectly healthy
G External, request fails but total suffices classic "enough but useless" trap
H Compaction outcome holes merge → request ab succeed karta hai
I Word problem (real units, KB/MB) English ko formulas mein translate karo
J Exam twist paging vs. compaction confusion / limiting behaviour

Example 1 — Cell A (internal, non-exact fit)


Example 2 — Cell B (exact fit, degenerate: zero waste)


Example 3 — Cell C (tiny process, )


Example 4 — Cell D (system total, many processes)


Example 5 — Cell E & G (external: scattered holes, request fails)

Figure — Fragmentation — internal vs external, compaction
  1. Total free: K. Yeh step kyun? Ratio sabse bada usable piece ko sari free memory se compare karta hai.
  2. Largest block: K (figure mein amber bar).
  3. Ratio: . Yeh step kyun? 1 ke karib ratio matlab free memory buri tarah shattered hai; yahan aadhe se zyada 50 K se upar kisi bhi request ke liye unusable hai.
  4. 100 K request: ek contiguous hole mein land karni chahiye. Largest 50 K K hai → fail, chahe . Yeh step kyun? Process ko di jaane wali memory contiguous honi chahiye; tum ek request ke liye teen alag holes ko nahin jod sakte.

Verify: ; aur indeed . ✓ Request fail hoti hai kyunki koi single hole K nahi hai.


Example 6 — Cell F (degenerate external: one hole, ratio zero)


Example 7 — Cell H (compaction holes ko merge karta hai)

Figure — Fragmentation — internal vs external, compaction
  1. A, B, C ko front par slide karo: saare used blocks ek end ke against pack ho jaate hain (figure ka top → bottom). Yeh step kyun? Compaction physically allocated blocks ko saath copy karta hai; iske liye run-time relocatable addresses chahiye (ek base/relocation register), warna copied code galat jagahon ko point karega.
  2. Holes merge ho jaate hain: freed space ek block of K ban jaata hai. Yeh step kyun? Kuch free ya create nahi kiya gaya — wahi same 120 K ab scattered ki jagah contiguous hai.
  3. Naya ratio: .
  4. 100 K request: ek block mein → succeed karti hai. Yeh step kyun? Ab ek single hole kaafi bada hai, jo bilkul wahi hai jo request ko chahiye.

Verify: total free unchanged ( K pehle aur baad mein — compaction move karta hai, delete nahi); ratio drop hua. ✓ Aur , isliye success. Note karo A, B, C ke andar internal waste untouched hai — compaction sirf external theek karta hai.


Example 8 — Cell I (word problem, real units)


Example 9 — Cell J (exam twist: kaun sa cure, aur limit)


Recall Pure matrix ki one-line recall

Internal formula ::: ; zero sirf tab jab ka multiple ho; worst case ; system total = tails ka sum (average mein each). External ratio ::: ; ek hole ke liye 0, memory shatter hone par 1 ki taraf badhta hai; compaction ise 0 kar deta hai total free ko change kiye bina.


Parent topic par wapas jao. Related machinery: Paging, Segmentation, Dynamic Memory Allocation, Memory Allocation Strategies, Virtual Memory, Address Binding.