|
@@ -2247,12 +2247,14 @@ Get required block size to fit in the allocation as well as the alignment paddin
|
|
*/
|
|
*/
|
|
@(require_results)
|
|
@(require_results)
|
|
buddy_block_size_required :: proc(b: ^Buddy_Allocator, size: uint) -> uint {
|
|
buddy_block_size_required :: proc(b: ^Buddy_Allocator, size: uint) -> uint {
|
|
- size := size
|
|
|
|
- actual_size := b.alignment
|
|
|
|
- size += size_of(Buddy_Block)
|
|
|
|
- size = align_forward_uint(size, b.alignment)
|
|
|
|
- for size > actual_size {
|
|
|
|
- actual_size <<= 1
|
|
|
|
|
|
+ assert(size > 0)
|
|
|
|
+ // NOTE: `size_of(Buddy_Block)` will be accounted for in `b.alignment`.
|
|
|
|
+ // This calculation is also previously guarded against being given a `size`
|
|
|
|
+ // 0 by `buddy_allocator_alloc_bytes_non_zeroed` checking for that.
|
|
|
|
+ actual_size := b.alignment + size
|
|
|
|
+ if intrinsics.count_ones(actual_size) != 1 {
|
|
|
|
+ // We're not a power of two. Let's fix that.
|
|
|
|
+ actual_size = 1 << (size_of(uint) * 8 - intrinsics.count_leading_zeros(actual_size))
|
|
}
|
|
}
|
|
return actual_size
|
|
return actual_size
|
|
}
|
|
}
|