What does align_log2 in alloc_contiguous means?

Open
#6 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
25/100
Issue type
Documentation
Clarity
Needs clarification
Activity status
Stale
Tech stack
rust

Research direction

Start by reading the Rust implementation and call site for BITMAP.alloc_contiguous, including the align_log2 argument. Clarify what alloc_contiguous does and how alignment relates to allocating a 2MiB frame; done means the behavior and argument meaning are documented clearly enough for the shown allocator code.

Written by the indexing model from the issue text.

Description

I'm trying to allocate a 2MiB huge frame like this:

unsafe impl<T: PageSize> FrameAllocator<T> for GlobalFrameAllocator {
    fn allocate_frame(&mut self) -> Option<PhysFrame<T>> {
        unsafe {
            if let Some(addr) = BITMAP.alloc_contiguous(T::SIZE as usize / Size4KiB::SIZE as usize, 1) {
                let addr = PhysAddr::new(addr as u64 * Size4KiB::SIZE);
                PhysFrame::from_start_address(addr).ok()
            } else {
                None
            }
        }
    }
}

impl<T: PageSize> FrameDeallocator<T> for GlobalFrameAllocator {
    unsafe fn deallocate_frame(&mut self, frame: PhysFrame<T>) {
        let addr = frame.start_address().as_u64() as usize;
        BITMAP.dealloc(addr);
    }
}

I'm very confused on what alloc_contiguous does

Dominant language
Rust
Stars
15
Forks
12
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rcore-os/bitmap-allocator

All issues in rcore-os/bitmap-allocator

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.