CS FundamentalsVery hardProduct company interview · GATE level

A buddy allocator manages 1024 KB and splits blocks in powers of two, always using the lowest-addressed free block of the needed size. Starting empty, it serves: A = 100 KB, B = 240 KB, C = 60 KB, D = 130 KB, free A, E = 50 KB, free C, free B. How many free blocks are there at the end, and how large is the biggest single request it can then satisfy?

  1. A. 3 free blocks; 512 KB
  2. B. 4 free blocks; 256 KB
  3. C. 4 free blocks; 704 KB
  4. D. 2 free blocks; 512 KB

Correct answer: B. 4 free blocks; 256 KB

A takes 128 KB at 0 (splitting 1024 into 512 + 256 + 128 + 128). B takes the 256 KB block at 256. C splits the 128 KB at 128 into two 64s and takes the one at 128. D splits 512 at 512 and takes 256 at 512, leaving 256 at 768. Freeing A gives 128 at 0, whose buddy (128 at 128) is split, so no merge. E takes the 64 at 192. Freeing C gives 64 at 128, but its buddy at 192 is E, so no merge. Freeing B gives 256 at 256, whose buddy at 0 is not whole. Free: 128 at 0, 64 at 128, 256 at 256, 256 at 768 - 704 KB in 4 blocks, but no block larger than 256 KB. Buddies merge only with their exact partner, which is why the free space is fragmented.

More Operating Systems questions

Exams that ask this topic