[NSWI004] Note on is_power_of_two

Petr Tuma petr.tuma at d3s.mff.cuni.cz
Tue Jan 5 08:58:30 CET 2021


Hello,

Miroslav already answered the first half of your question (thanks!), let me try with the second half.

> Is there a particular reason our frame allocator should only allocate
> powers of two anyway?

One allocation algorithm that is sometimes used in frame allocators is the buddy system (https://en.wikipedia.org/wiki/Buddy_memory_allocation, https://www.kernel.org/doc/gorman/html/understand/understand009.html). That particular algorithm rounds the block size up to the nearest power of two. Our assignment aims to make life (very slightly) simpler for those teams that decide to use this algorithm by guaranteeing that our tests will never call the frame allocator with an allocation request that is not a power of two. Your code can support other sizes too.

I might be missing something but off the top of my head I think there is no really significant reason to have this restriction imposed on the frame allocator. Alone, it really has very little practical benefit (it may be useful when coupled with alignment guarantees on the allocated address, but that is not included in our assignment).

Petr


More information about the NSWI004 mailing list