vmm: memory_manager: use available_parallelism for prefault threads

Use std::thread::available_parallelism() when sizing the prefault
worker threads so the number of threads scales with the host CPU
count instead of relying on unsafe sysconf.

Fixes: #8495

Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>
This commit is contained in:
Pulak Kanti Bhowmick
2026-07-07 21:53:34 +07:00
committed by Rob Bradford
parent 818fc07266
commit 03e229786d

View File

@@ -26,7 +26,6 @@ use arch::{RegionType, layout};
use devices::ioapic; use devices::ioapic;
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
use hypervisor::HypervisorVmError; use hypervisor::HypervisorVmError;
use libc::_SC_NPROCESSORS_ONLN;
use log::{debug, error, info, warn}; use log::{debug, error, info, warn};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use thiserror::Error; use thiserror::Error;
@@ -2237,14 +2236,10 @@ impl MemoryManager {
} }
fn get_prefault_num_threads(page_size: usize, num_pages: usize) -> usize { fn get_prefault_num_threads(page_size: usize, num_pages: usize) -> usize {
let mut n: usize = 1;
// Do not create more threads than processors available. // Do not create more threads than processors available.
// SAFETY: FFI call. Trivially safe. let mut n = thread::available_parallelism()
let procs = unsafe { libc::sysconf(_SC_NPROCESSORS_ONLN) }; .map_or(1, |val| val.get())
if procs > 0 { .min(MAX_PREFAULT_THREAD_COUNT);
n = cmp::min(procs as usize, MAX_PREFAULT_THREAD_COUNT);
}
// Do not create more threads than pages being allocated. // Do not create more threads than pages being allocated.
n = cmp::min(n, num_pages); n = cmp::min(n, num_pages);