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?
- A. 3 free blocks; 512 KB
- B. 4 free blocks; 256 KB
- C. 4 free blocks; 704 KB
- 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
- A disk has cylinders 0-499. The head is at 237 and is moving towards cylinder 0. Pending requests: 312, 45, 401, 198, 260, 12, 477, 150…
- A disk spins at 12,000 RPM, has 250 sectors of 512 bytes per track, an average seek time of 4 ms and a track-to-track seek time of 0.5 ms…
- A machine has 40-bit virtual addresses, 16 KB pages and 4-byte page-table entries. Every page table at every level must fit in a single…
- A 32-bit system uses two-level paging: 10 bits for the outer index, 10 bits for the inner index and a 12-bit offset, with 4-byte entries…
- A 32-bit system uses two-level paging with a 10-bit outer index, a 10-bit inner index and a 12-bit offset. The virtual address 0xC0A8F3E7…
- A system with a TLB and a two-level page table has TLB access time 10 ns (searched before memory), memory access time 100 ns and a TLB hit…