[libvirt] [PATCH V2 0/3] Fix some problems of numatune

Fix startup failing with memory mode(strict, preferred or interleave) in numatune V1: https://www.redhat.com/archives/libvir-list/2014-November/msg00057.html V2 has been revised as Martin' suggestion. Wang Rui (3): qemu: don't setup cpuset.mems if memory mode in numatune is not 'strict' lxc: don't setup cpuset.mems if memory mode in numatune is not 'strict' qemu: fix domain startup failing with 'strict' mode in numatune src/lxc/lxc_cgroup.c | 4 ++++ src/qemu/qemu_cgroup.c | 14 +++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) -- 1.7.12.4

If the memory mode in numatune is specified as 'preferred' with one node (such as nodeset='0'), domain's memory is not all in node 0 absolutely. Assumption that node 0 doesn't have enough memory, memory can be allocated on node 1 when qemu process startup. Then if we set cpuset.mems to '0', it may invoke OOM. Commit 1a7be8c600905aa07ac2d78293336ba8523ad48e changed the former logic of checking memory mode in virDomainNumatuneGetNodeset. This patch adds the check as before. Signed-off-by: Wang Rui <moon.wangrui@huawei.com> --- src/qemu/qemu_cgroup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index b5bdb36..a87ef40 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -618,6 +618,10 @@ qemuSetupCpusetMems(virDomainObjPtr vm, if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) return 0; + if (virDomainNumatuneGetMode(vm->def->numatune, -1) != + VIR_DOMAIN_NUMATUNE_MEM_STRICT) + return 0; + if (virDomainNumatuneMaybeFormatNodeset(vm->def->numatune, nodemask, &mem_mask, -1) < 0) -- 1.7.12.4

If the memory mode in numatune is not 'strict', we should not setup cpuset.mems. Before commit 1a7be8c600905aa07ac2d78293336ba8523ad48e we have checked the memory mode in virDomainNumatuneGetNodeset. This patch adds the check as before. Signed-off-by: Wang Rui <moon.wangrui@huawei.com> --- src/lxc/lxc_cgroup.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index f9af31c..eb67191 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -79,6 +79,10 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr def, goto cleanup; } + if (virDomainNumatuneGetMode(def->numatune, -1) != + VIR_DOMAIN_NUMATUNE_MEM_STRICT) + goto cleanup; + if (virDomainNumatuneMaybeFormatNodeset(def->numatune, nodemask, &mask, -1) < 0) goto cleanup; -- 1.7.12.4

If the memory mode is specified as 'strict' and with one node, we get the following error when starting domain. error: Unable to write to '$cgroup_path/cpuset.mems': Device or resource busy XML is configured with numatune as follows: <numatune> <memory mode='strict' nodeset='0'/> </numatune> It's broken by Commit 411cea638f6ec8503b7142a31e58b1cd85dbeaba which moved qemuSetupCgroupForEmulator() before setting cpuset.mems in qemuSetupCgroupPostInit. Directory '$cgroup_path/emulator/' is created in qemuSetupCgroupForEmulator. But '$cgroup_path/emulator/cpuset.mems' it not set and has a default value (all nodes, such as 0-1). Then we setup '$cgroup_path/cpuset.mems' to the nodemask (in this case it's '0') in qemuSetupCgroupPostInit. It must fail. This patch makes '$cgroup_path/emulator/cpuset.mems' is set before '$cgroup_path/cpuset.mems'. The action is similar with that in qemuDomainSetNumaParamsLive. Signed-off-by: Wang Rui <moon.wangrui@huawei.com> --- src/qemu/qemu_cgroup.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index a87ef40..3b1d16d 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -611,6 +611,7 @@ static int qemuSetupCpusetMems(virDomainObjPtr vm, virBitmapPtr nodemask) { + virCgroupPtr cgroup_temp = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; char *mem_mask = NULL; int ret = -1; @@ -627,13 +628,16 @@ qemuSetupCpusetMems(virDomainObjPtr vm, &mem_mask, -1) < 0) goto cleanup; - if (mem_mask && - virCgroupSetCpusetMems(priv->cgroup, mem_mask) < 0) - goto cleanup; + if (mem_mask) + if (virCgroupNewEmulator(priv->cgroup, false, &cgroup_temp) < 0 || + virCgroupSetCpusetMems(cgroup_temp, mem_mask) < 0 || + virCgroupSetCpusetMems(priv->cgroup, mem_mask) < 0) + goto cleanup; ret = 0; cleanup: VIR_FREE(mem_mask); + virCgroupFree(&cgroup_temp); return ret; } -- 1.7.12.4

On Mon, Nov 10, 2014 at 09:53:16PM +0800, Wang Rui wrote:
Fix startup failing with memory mode(strict, preferred or interleave) in numatune
V1: https://www.redhat.com/archives/libvir-list/2014-November/msg00057.html
V2 has been revised as Martin' suggestion.
ACK && Pushed. Thank you, Martin
participants (2)
-
Martin Kletzander
-
Wang Rui