GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 5(b)

Compare allocation outcomes

Operating Systems · Memory Allocation & Segmentation · Full GATE CSE 1995 paper

GATE 1995, Q5(b) Descriptive
Report issue

Memory Allocation & Segmentation

Question 5(b), GATE 1995: 1000K of contiguous free memory receives J1=200K, J2=350K, J3=300K; J1 finishes; then J4=120K, J5=150K and J6=80K arrive, in that order. Assume allocations start at the low-address end of a selected hole, free holes coalesce, no compaction and first fit searches from the lowest address. Which policy performs better for this sequence?
Question 5(b), GATE 1995: 1000K of contiguous free memory receives J1=200K, J2=350K, J3=300K; J1 finishes; then J4=120K, J5=150K and J6=80K arrive, in that order. Assume allocations start at the low-address end of a selected hole, free holes coalesce, no compaction and first fit searches from the lowest address. Which policy performs better for this sequence?
Question 5(b), GATE 1995: 1000K of contiguous free memory receives J1=200K, J2=350K, J3=300K; J1 finishes; then J4=120K, J5=150K and J6=80K arrive, in that order. Assume allocations start at the low-address end of a selected hole, free holes coalesce, no compaction and first fit searches from the lowest address. Which policy performs better for this sequence?
Tap to enlarge
Answer & solution

Answer: First fit. (no official key was published)

First fit places the 120K job in the initial 200K hole, preserving an 80K remainder. It then puts the 150K job in the separate 150K hole and admits the final 80K job into the exact remainder. Consequently every arriving job is resident at the end, filling all 1000K.

Best fit uses the 150K hole for the 120K request, leaving 30K. The later 150K request takes 150K out of the 200K hole, leaving 50K. Although 50+30=80, the final 80K request requires one contiguous region and cannot be admitted without relocation or compaction. First fit therefore performs better on the stated admission/utilization criterion. This trace is a counterexample to the intuition that the locally smallest leftover always leads to the best future allocation. It is not a proof that first fit dominates best fit for every workload.

Original paper, page 6