GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 5(a)

Trace first fit and best fit

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

GATE 1995, Q5(a) Descriptive
Report issue

Memory Allocation & Segmentation

Question 5(a), 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. Draw both memory allocation sequences.
Question 5(a), 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. Draw both memory allocation sequences.
Tap to enlarge
Answer & solution

Answer: First fit admits all jobs; best fit cannot admit J6. (no official key was published)

Use half-open address intervals in K so that [0,200) has size 200. Both algorithms initially allocate J1=[0,200), J2=[200,550), J3=[550,850), leaving [850,1000) free. When J1 finishes, the holes are [0,200) and [850,1000).

First fit: J4 takes [0,120), leaving holes [120,200) of size 80 and [850,1000) of size 150. J5 cannot fit in 80, so it occupies [850,1000). J6 then exactly fills [120,200). Final low-to-high layout is J4:120 | J6:80 | J2:350 | J3:300 | J5:150.

Best fit: J4 takes the smaller adequate hole [850,1000), occupying [850,970) and leaving 30K. J5 takes [0,150), leaving [150,200) of size 50. J6 needs 80K but neither the 50K nor 30K hole suffices. Final layout is J5:150 | free:50 | J2:350 | J3:300 | J4:120 | free:30, with J6 waiting.

The total free space is 80K, equal to J6’s request, but it is split into nonadjacent holes. This is external fragmentation, not a shortage of aggregate space.

Original paper, page 6