runtime-rs: static resources: always set maxvcpus equal to vcpus

based on current runtime-go behaviour introduced in https://github.com/kata-containers/kata-containers/pull/9195

When using static resources, always set maxvcpus value equal to the vcpus value.
This is because the static resources case does not support dynamic CPU hotplugging,
and therefore the maximum number of vCPUs should be limited to the number of vCPUs.
Booting with a high number of max vCPUs is a bit slower compared to a lower number.

Signed-off-by: Saul Paredes <saulparedes@microsoft.com>
This commit is contained in:
Saul Paredes
2026-05-12 15:11:49 -07:00
parent 3799473041
commit d930fc42b8

View File

@@ -144,12 +144,14 @@ impl InitialSizeManager {
info!(sl!(), "resource with vcpu {}", self.resource.vcpu);
if config.runtime.static_sandbox_resource_mgmt {
hv.cpu_info.default_vcpus += self.resource.vcpu;
let new_vcpus_ceil = hv.cpu_info.default_vcpus.ceil() as u32;
if hv.cpu_info.default_maxvcpus < new_vcpus_ceil {
hv.cpu_info.default_maxvcpus = new_vcpus_ceil;
}
}
}
if config.runtime.static_sandbox_resource_mgmt {
let new_vcpus_ceil = hv.cpu_info.default_vcpus.ceil() as u32;
hv.cpu_info.default_maxvcpus = new_vcpus_ceil;
}
self.resource.orig_toml_default_mem = hv.memory_info.default_memory;
if self.resource.mem_mb > 0 {
info!(sl!(), "resource with memory {}", self.resource.mem_mb);
@@ -450,6 +452,23 @@ mod tests {
assert_eq!(hv.cpu_info.default_maxvcpus, 4);
}
#[test]
fn test_setup_config_static_reduces_maxvcpus_to_static_total() {
let mut config = make_config(1.0, 8, 256, 4096, true);
let mut mgr = InitialSizeManager {
resource: InitialSize {
vcpu: 1.2,
mem_mb: 0,
orig_toml_default_mem: 0,
},
};
mgr.setup_config(&mut config).unwrap();
let hv = config.hypervisor.get("qemu").unwrap();
assert_eq!(hv.cpu_info.default_vcpus, 2.2);
assert_eq!(hv.cpu_info.default_maxvcpus, 3);
}
#[test]
fn test_setup_config_clamps_maxmemory() {
let mut config = make_config(1.0, 4, 256, 300, true);