/// Annotate all physical memory frames we got from UEFI with NUMA affinity by
/// walking through every region `memory_regions` and build subregions
/// that are constructed with the correct NUMA affinity.
///
/// We split frames in `memory_regions` in case they overlap multiple NUMA regions,
/// and let's hope it all fits in `annotated_regions`.
///
/// This really isn't the most efficient algorithm we could've built but we
/// only run this once and don't expect thousands of NUMA nodes or
/// memory regions anyways.
///
/// # Notes
/// There are some implicit assumptions here that a memory region always has
/// just one affinity -- which is also what `topology` assumes.
Annotate all physical memory frames we got from UEFI with NUMA affinity by
walking through every region `memory_regions` and build subregions
that are constructed with the correct NUMA affinity.

We split frames in `memory_regions` in case they overlap multiple NUMA regions,
and let's hope it all fits in `annotated_regions`.

This really isn't the most efficient algorithm we could've built but we
only run this once and don't expect thousands of NUMA nodes or
memory regions anyways.
Annotate all physical memory frames we got from UEFI with NUMA affinity by walking through every region ` memory_regions ` and build subregions that are constructed with the correct NUMA affinity . We split frames in ` memory_regions ` in case they overlap multiple NUMA regions and let ' s hope it all fits in ` annotated_regions ` . This really isn ' t the most efficient algorithm we could ' ve built but we only run this once and don ' t expect thousands of NUMA nodes or memory regions anyways .
fn identify_numa_affinity(
    memory_regions: &ArrayVec<Frame, MAX_PHYSICAL_REGIONS>,
    annotated_regions: &mut ArrayVec<Frame, MAX_PHYSICAL_REGIONS>,
) {
    if atopology::MACHINE_TOPOLOGY.num_nodes() > 0 {
        for orig_frame in memory_regions.iter() {
            for node in atopology::MACHINE_TOPOLOGY.nodes() {
                // trying to find a NUMA memory affinity that contains the given `orig_frame`
                for affinity_region in node.memory() {
                    if !affinity_region.is_hotplug_region() {
                        match affinity_region
                            .contains(orig_frame.base.into(), orig_frame.end().into())
                        {
                            (_, mid, _) => {
                                if mid.0 > 0 {
                                    let mid_paddr = (PAddr::from(mid.0), PAddr::from(mid.1));
                                    let annotated_frame = Frame::from_range(mid_paddr, node.id);
                                    trace!("Identified NUMA region for {:?}", annotated_frame);
                                    assert!(!annotated_regions.is_full());
                                    annotated_regions.push(annotated_frame);
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        // We are not running on a NUMA machine,
        // so we just assume everything as node#0
        // (and copy from original memory regions):
        annotated_regions
            .try_extend_from_slice(memory_regions.as_slice())
            .expect("Can't initialize annotated regions");
    }
    // Sanity check our code the sum of total bytes in `annotated_regions`
    // should be the equal to the sum of bytes in `memory_regions`:
    assert_eq!(
        annotated_regions.iter().fold(0, |sum, f| sum + f.size()),
        memory_regions.iter().fold(0, |sum, f| sum + f.size())
    );
}
fn identify_numa_affinity ( memory_regions : & ArrayVec < Frame , MAX_PHYSICAL_REGIONS > , annotated_regions : & mut ArrayVec < Frame , MAX_PHYSICAL_REGIONS > , ) { if atopology :: MACHINE_TOPOLOGY . num_nodes ( ) > 0 { for orig_frame in memory_regions . iter ( ) { for node in atopology :: MACHINE_TOPOLOGY . nodes ( ) { // trying to find a NUMA memory affinity that contains the given `orig_frame` for affinity_region in node . memory ( ) { if ! affinity_region . is_hotplug_region ( ) { match affinity_region . contains ( orig_frame . base . into ( ) , orig_frame . end ( ) . into ( ) ) { ( _ , mid , _ ) => { if mid . 0 > 0 { let mid_paddr = ( PAddr :: from ( mid . 0 ) , PAddr :: from ( mid . 1 ) ) ; let annotated_frame = Frame :: from_range ( mid_paddr , node . id ) ; trace ! ( " " annotated_frame ) ; assert ! ( annotated_regions is_full ( ) ) ; annotated_regions . push ( annotated_frame ) ; } } } } } } } } else { // We are not running on a NUMA machine, // so we just assume everything as node#0 // (and copy from original memory regions): annotated_regions . try_extend_from_slice ( memory_regions . as_slice ( ) ) . expect ( " " ) ; } // Sanity check our code the sum of total bytes in `annotated_regions` // should be the equal to the sum of bytes in `memory_regions`: assert_eq ! ( annotated_regions iter ( ) fold ( 0 sum f sum f size ( ) ) memory_regions iter ( ) fold ( 0 sum f sum f size ( ) ) ) ; }
Annotate all physical memory frames we got from UEFI with NUMA affinity by
walking through every region `memory_regions` and build subregions
that are constructed with the correct NUMA affinity.
Annotate all physical memory frames we got from UEFI with NUMA affinity by walking through every region ` memory_regions ` and build subregions that are constructed with the correct NUMA affinity .
memory_regions
&ArrayVec<Frame, MAX_PHYSICAL_REGIONS>
annotated_regions
&mut ArrayVec<Frame, MAX_PHYSICAL_REGIONS>
notes
There are some implicit assumptions here that a memory region always has
just one affinity -- which is also what `topology` assumes.
There are some implicit assumptions here that a memory region always has just one affinity -- which is also what ` topology ` assumes .