From f3fd0664cf96590b4b82c03610d05b2db462991b Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Wed, 11 Sep 2024 15:06:04 +0200 Subject: [PATCH] resctrl: Don't assume MBA availability in virResctrlAllocNewFromInfo Weirdly, the existence of /sys/fs/resctrl/info/MB does not always mean that MBA is available and used on the system. Instead of assuming that copy the values from the default (root) allocation. This also makes it nicer to use the proper values in case the system does not use percentages or when the root allocation already limits the bandwidth. Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- src/util/virresctrl.c | 16 +++------------- tests/virresctrldata/resctrl.schemata | 1 - 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 30695092a1..f3ec4d6705 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1805,19 +1805,6 @@ virResctrlAllocNewFromInfo(virResctrlInfo *info) } } - /* set default free memory bandwidth to 100% */ - if (info->membw_info) { - ret->mem_bw = g_new0(virResctrlAllocMemBW, 1); - - VIR_EXPAND_N(ret->mem_bw->bandwidths, ret->mem_bw->nbandwidths, - info->membw_info->max_id + 1); - - for (i = 0; i < ret->mem_bw->nbandwidths; i++) { - ret->mem_bw->bandwidths[i] = g_new0(unsigned int, 1); - *(ret->mem_bw->bandwidths[i]) = 100; - } - } - return g_steal_pointer(&ret); } @@ -1890,6 +1877,9 @@ virResctrlAllocGetUnused(virResctrlInfo *resctrl) if (!alloc_default) return NULL; + /* Take MBA maximums from the root allocation */ + virResctrlAllocCopyMemBW(ret, alloc_default); + virResctrlAllocSubtract(ret, alloc_default); if (virDirOpen(&dirp, SYSFS_RESCTRL_PATH) < 0) diff --git a/tests/virresctrldata/resctrl.schemata b/tests/virresctrldata/resctrl.schemata index 2578822b70..fa980e58c9 100644 --- a/tests/virresctrldata/resctrl.schemata +++ b/tests/virresctrldata/resctrl.schemata @@ -1,2 +1 @@ L3:0=000ff;1=000f0 -MB:0=100;1=100