openhcl_boot: correctly divide ram per node to page aligned size - #4076
openhcl_boot: correctly divide ram per node to page aligned size#4076chris-oo wants to merge 2 commits into
Conversation
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
There was a problem hiding this comment.
Pull request overview
This PR updates openhcl_boot’s VTL2 RAM allocation logic to ensure the computed per-NUMA-node allocation size is page-aligned, preventing a later panic when splitting MemoryRanges at non-page-aligned offsets.
Changes:
- Page-align the computed
ram_per_nodevalue used to drive per-node allocation sizing.
| // Next, calculate the amount of memory that needs to be allocated per numa | ||
| // node. | ||
| let ram_per_node = vtl2_size / numa_node_count as u64; | ||
| // node. Make sure ram_per_node is page aligned by aligning up to the next | ||
| // page. | ||
| let ram_per_node = | ||
| ((vtl2_size / numa_node_count as u64) + (HV_PAGE_SIZE - 1)) & !(HV_PAGE_SIZE - 1); |
| // node. Make sure ram_per_node is page aligned by aligning up to the next | ||
| // page. | ||
| let ram_per_node = | ||
| ((vtl2_size / numa_node_count as u64) + (HV_PAGE_SIZE - 1)) & !(HV_PAGE_SIZE - 1); |
There was a problem hiding this comment.
| ((vtl2_size / numa_node_count as u64) + (HV_PAGE_SIZE - 1)) & !(HV_PAGE_SIZE - 1); | |
| ((vtl2_size / numa_node_count as u64).next_multiple_of(HV_PAGE_SIZE); |
There was a problem hiding this comment.
This can still replace your align_up i think
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
openhcl/openhcl_boot/src/host_params/dt/mod.rs:253
ram_per_nodeis being aligned up after dividing bynuma_node_count. This can over-allocate VTL2 RAM by up to(numa_node_count * (ALIGNMENT_GRANULARITY-1))bytes (worst case: +7 pages per node), which reduces VTL0 RAM more than necessary. Aligning the total once (max +7 pages overall) and then distributing the remainder to the last node (similar to the VTL2 pool split logic earlier in this file) keeps boundaries aligned without per-node over-allocation.
const ALIGNMENT_GRANULARITY: u64 = HV_PAGE_SIZE * 8;
let align_up = |value| (value + ALIGNMENT_GRANULARITY - 1) & !(ALIGNMENT_GRANULARITY - 1);
let ram_per_node = align_up(vtl2_size / numa_node_count as u64);
Without doing this alignment, openhcl_boot will later panic when we try to split allocations based on free ranges for a MemoryRange, because the split point will not be page aligned.