From 5b2ed130aac2cbc8c213ecd269f7b95e505b3bd3 Mon Sep 17 00:00:00 2001 From: wabct Date: Wed, 30 Aug 2023 19:21:49 +0800 Subject: [PATCH] [vmm]:Fix the division by zero bug when calculating CPU quota Signed-off-by: wabct --- vmm/sandbox/src/utils.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vmm/sandbox/src/utils.rs b/vmm/sandbox/src/utils.rs index 4c998db3..fe087f25 100644 --- a/vmm/sandbox/src/utils.rs +++ b/vmm/sandbox/src/utils.rs @@ -162,8 +162,11 @@ fn merge_resources( LinuxContainerResources { cpu_period: resource1.cpu_period, - cpu_quota: resource1.cpu_quota - + resource2.cpu_quota * resource1.cpu_period / resource2.cpu_period, + cpu_quota: if resource2.cpu_period != 0 { + resource1.cpu_quota + resource2.cpu_quota * resource1.cpu_period / resource2.cpu_period + } else { + resource1.cpu_quota + }, cpu_shares: resource1.cpu_shares + resource2.cpu_shares, memory_limit_in_bytes: resource1.memory_limit_in_bytes + resource2.memory_limit_in_bytes, oom_score_adj,