fn allocate_pages(state: &HeapState, pages: usize, align: usize)
    -> Result<VirtualAddress, ()> {

    if pages == 0 { return Err(()); }

    let regions = &state.regions;

    // First, try to allocate from unused_allocated. If we can get what we need
    // from here, we don't need to map the pages - they're already mapped to
    // usable physical memory
    let from_unused_allocated = allocate_pages_from(
        &regions.unused_allocated, pages, align);

    if let Some(alloc_start) = from_unused_allocated {
        trace!("Got from unused_allocated: {:016x} x {}", alloc_start, pages);
        // Check to see if we need to restock unused_allocated
        restock_unused_allocated(&regions);
        return Ok(alloc_start);
    }

    // Otherwise, allocate virtual from the free_virtual list and acquire and
    // map physical pages.
    acquire_allocate_pages(regions, pages, align)
}
/// Allocate pages, preferring already unused mapped pages first.
Allocate pages, preferring already unused mapped pages first.
Allocate pages preferring already unused mapped pages first .
fn allocate_pages(state: &HeapState, pages: usize, align: usize)
    -> Result<VirtualAddress, ()> {
    if pages == 0 { return Err(()); }
    let regions = &state.regions;
    // First, try to allocate from unused_allocated. If we can get what we need
    // from here, we don't need to map the pages - they're already mapped to
    // usable physical memory
    let from_unused_allocated = allocate_pages_from(
        &regions.unused_allocated, pages, align);
    if let Some(alloc_start) = from_unused_allocated {
        trace!("Got from unused_allocated: {:016x} x {}", alloc_start, pages);
        // Check to see if we need to restock unused_allocated
        restock_unused_allocated(&regions);
        return Ok(alloc_start);
    }
    // Otherwise, allocate virtual from the free_virtual list and acquire and
    // map physical pages.
    acquire_allocate_pages(regions, pages, align)
}
fn allocate_pages ( state : & HeapState , pages : usize , align : usize ) -> Result < VirtualAddress , ( ) > { if pages == 0 { return Err ( ( ) ) ; } let regions = & state . regions ; // First, try to allocate from unused_allocated. If we can get what we need // from here, we don't need to map the pages - they're already mapped to // usable physical memory let from_unused_allocated = allocate_pages_from ( & regions . unused_allocated , pages , align ) ; if let Some ( alloc_start ) = from_unused_allocated { trace ! ( " " alloc_start pages ) ; // Check to see if we need to restock unused_allocated restock_unused_allocated ( & regions ) ; return Ok ( alloc_start ) ; } // Otherwise, allocate virtual from the free_virtual list and acquire and // map physical pages. acquire_allocate_pages ( regions , pages , align ) }
Allocate pages, preferring already unused mapped pages first.
Allocate pages preferring already unused mapped pages first .
state
&HeapState
pages
usize
align
usize