Skip to content

Conversation

Copy link

Copilot AI commented Dec 13, 2025

BitmapPageAllocator::init panics when initialized with a non-zero start address at maximum capacity (256MB default). The base address is always aligned down to 1GB boundaries, creating a gap that exhausts bitmap capacity before the requested region fits.

Changes

  • Added explicit capacity check: Added assertion that panics with a clear error message when the bitmap capacity is insufficient for the requested allocation range
  • Maintains 1GB alignment: Base address remains aligned to MAX_ALIGN_1GB to support maximum alignment capabilities
  • Added tests: Non-zero start address, 1GB-aligned start, and capacity exceeded panic test cases

Example

// Previously panicked with cryptic assertion from inner BitAlloc
let mut allocator = BitmapPageAllocator::<4096>::new();
allocator.init(40960, 256 * 1024 * 1024);  
// Now panics with clear message: "bitmap capacity exceeded: need X pages but CAP is Y"

// Allocations within capacity work fine
allocator.init(40960, 4 * 1024 * 1024);  // Succeeds

The fix ensures users get immediate, informative feedback when their configuration exceeds bitmap capacity, rather than encountering an obscure assertion failure from the underlying bitmap allocator.

Original prompt

This section details on the original issue you should resolve

<issue_title>BitmapPageAllocator::init assertion fails in default feature settings</issue_title>
<issue_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.</issue_description>

<agent_instructions>try to fix this issue</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 13, 2025
Copilot AI and others added 5 commits December 13, 2025 11:37
Co-authored-by: equation314 <11389231+equation314@users.noreply.github.com>
…ddresses

Co-authored-by: equation314 <11389231+equation314@users.noreply.github.com>
Co-authored-by: equation314 <11389231+equation314@users.noreply.github.com>
Co-authored-by: equation314 <11389231+equation314@users.noreply.github.com>
Co-authored-by: equation314 <11389231+equation314@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix assertion failure in BitmapPageAllocator init method Fix BitmapPageAllocator::init assertion failure with non-zero start addresses Dec 13, 2025
Copilot AI requested a review from equation314 December 13, 2025 11:53
@equation314
Copy link
Member

@copilot Panic if CAP does not meet the size or alignment requirement of start.

Per review feedback, instead of silently falling back to reduced
alignment support, now explicitly panic with a clear error message
when the bitmap capacity is insufficient for the requested allocation.

This provides better error reporting and makes the limitation explicit
rather than degrading functionality silently.

Added test to verify panic behavior when capacity is exceeded.

Co-authored-by: equation314 <11389231+equation314@users.noreply.github.com>
Copy link
Author

Copilot AI commented Dec 16, 2025

@copilot Panic if CAP does not meet the size or alignment requirement of start.

Changed to panic with a clear error message when bitmap capacity is exceeded. Added test test_init_capacity_exceeded to verify the panic behavior. See commit 25886e7.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/arceos-org/slab_allocator/commits/v0.3.1
    • Triggering command: /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/bin/cargo /home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/bin/cargo test --lib --features bitmap bitmap:: (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BitmapPageAllocator::init assertion fails in default feature settings

2 participants