-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Hi! I believe I have found a problem in BitmapPageAllocator. To reproduce the problem, use the following code snippet and compile it with default feature settings.
fn test_alloc(){
let mut allocator = BitmapPageAllocator::<4096>::new();
let size = 256 * 1024 * 1024; // 256 MB size
let start_addr = 40960; // can be any non-zero addr
allocator.init(start_addr, size); // assertion failed: end <= Self::CAP
}I believe it is a bug, because it is the normal behavior that the allocatable address index is not started from zero (zero means null, so it causes a lot of trouble).
I have investigated the reason for this bug. It turns out that the BitmapPageAllocator::inner only reserves the exact capacity of 256 MB (the maximum supported allocatable memory in default feature settings). It assumes the index of allocatable pages is started from zero. However, in BitmapPageAllocator::init, the start index of allocatable pages is calculated by start - self.base, where self.base is aligned down to 1GB. This creates an empty index before the index of the first allocatable page and causes an assertion failure.
To address the bug, I think the implementation should either add an alignment requirement for the start address or modify the way the start index is calculated.