From nobody Mon Feb 9 02:13:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618576961; cv=none; d=zohomail.com; s=zohoarc; b=oKhggnqbpFrRkGUTLawwqymCTF7Bd7XbfElpFxj9zN4FaL5xW/qhGFbfXR4W2e4vkRSIxbemhIPk4fGgB+tqN+QmDZ9awCkC2vEfosikjr0SrOlAuHvg/ACJrN3KueacctYF1oXNRuqS0juTJi6Lr22rvfCqvFj85joiy871D8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618576961; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kvcAEVYt1ZsvyluPhlO7aQovxDAWfO6xVB6BCw1RRcI=; b=FceADO1qM2cUxHqDKdXbrpz2zDkOKr6AmoNuNqSF3jweK8R/xz7bN4S4nPEfJxlCuw44lc7ROO1FyfI9fLNk5G7rYOlCn/r/se+m6LsMGhYyQv4gG755LyjbjjtzAqDK/HD510tl/bfgxWSouR/EuuaYsghdhriA0VR/vPw/PXk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618576961546185.7753240363021; Fri, 16 Apr 2021 05:42:41 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-107-vJMpRCiPMneHARBfttWllA-1; Fri, 16 Apr 2021 08:42:38 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 065F31926DA4; Fri, 16 Apr 2021 12:42:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7B8F60C0F; Fri, 16 Apr 2021 12:42:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3B9411806D0F; Fri, 16 Apr 2021 12:42:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13GCgUsl024541 for ; Fri, 16 Apr 2021 08:42:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0FEFC6294D; Fri, 16 Apr 2021 12:42:30 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.193.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AF85C62A22 for ; Fri, 16 Apr 2021 12:42:26 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id 35372C21099 for ; Fri, 16 Apr 2021 14:42:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618576960; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kvcAEVYt1ZsvyluPhlO7aQovxDAWfO6xVB6BCw1RRcI=; b=EbtGkktf84a74ob8uPmlhysDJeUaQ0ESSTFLrQZCxMvpHWPMW7vjivOP+roMN8Bt2R9ByN DbPoU3Gp470CoOWlJxrpJPHYsxuhvi9KJrwHLskiRzSdETlwMVJIsqK9FvEz3pLmTTj7+0 eUCgn2NKqoOmxMIbi3ktKOsZzgQatFU= X-MC-Unique: vJMpRCiPMneHARBfttWllA-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] qemu: Add support for 'restrictive' mode in numatune Date: Fri, 16 Apr 2021 14:42:25 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Luyao Zhong Reviewed-by: Daniel Henrique Barboza Signed-off-by: Luyao Zhong Signed-off-by: Martin Kletzander --- src/qemu/qemu_command.c | 5 ++- src/qemu/qemu_process.c | 32 ++++++++++++++++ ...emnode-restrictive-mode.x86_64-latest.args | 38 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/numatune-memnode-restrictive-mod= e.x86_64-latest.args diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 6d40983ce1ea..278590c2c18d 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3302,7 +3302,10 @@ qemuBuildMemoryBackendProps(virJSONValue **backendPr= ops, return -1; } =20 - if (nodemask) { + /* If mode is "restrictive", we should only use cgroups setting allowe= d memory + * nodes, and skip passing the host-nodes and policy parameters to QEM= U command + * line which means we will use system default memory policy. */ + if (nodemask && mode !=3D VIR_DOMAIN_NUMATUNE_MEM_RESTRICTIVE) { if (!virNumaNodesetIsAvailable(nodemask)) return -1; if (virJSONValueObjectAdd(props, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 4df33dc0d53c..05104e309877 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2692,6 +2692,7 @@ qemuProcessSetupPid(virDomainObj *vm, g_autoptr(virBitmap) hostcpumap =3D NULL; g_autofree char *mem_mask =3D NULL; int ret =3D -1; + size_t i; =20 if ((period || quota) && !virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) { @@ -2732,6 +2733,37 @@ qemuProcessSetupPid(virDomainObj *vm, &mem_mask, -1) < 0) goto cleanup; =20 + /* For restrictive numatune mode we need to set cpuset.mems for vC= PU + * threads based on the node they are in as there is nothing else = uses + * for such restriction (e.g. numa_set_membind). */ + if (nameval =3D=3D VIR_CGROUP_THREAD_VCPU) { + virDomainNuma *numatune =3D vm->def->numa; + + /* Look for the guest NUMA node of this vCPU */ + for (i =3D 0; i < virDomainNumaGetNodeCount(numatune); i++) { + g_autoptr(virBitmap) node_cpus =3D NULL; + node_cpus =3D virDomainNumaGetNodeCpumask(numatune, i); + + if (!virBitmapIsBitSet(node_cpus, id)) + continue; + + /* Update the mem_mask for this vCPU if the mode of its no= de is + * 'restrictive'. */ + if (virDomainNumatuneGetMode(numatune, i, &mem_mode) =3D= =3D 0 && + mem_mode =3D=3D VIR_DOMAIN_NUMATUNE_MEM_RESTRICTIVE) { + VIR_FREE(mem_mask); + + if (virDomainNumatuneMaybeFormatNodeset(numatune, + priv->autoNode= set, + &mem_mask, i) = < 0) { + goto cleanup; + } + } + + break; + } + } + if (virCgroupNewThread(priv->cgroup, nameval, id, true, &cgroup) <= 0) goto cleanup; =20 diff --git a/tests/qemuxml2argvdata/numatune-memnode-restrictive-mode.x86_6= 4-latest.args b/tests/qemuxml2argvdata/numatune-memnode-restrictive-mode.x8= 6_64-latest.args new file mode 100644 index 000000000000..6d5e2eb76ef7 --- /dev/null +++ b/tests/qemuxml2argvdata/numatune-memnode-restrictive-mode.x86_64-lates= t.args @@ -0,0 +1,38 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-QEMUGuest/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tm= p/lib/domain--1-QEMUGuest/master-key.aes"}' \ +-machine pc,accel=3Dtcg,usb=3Doff,dump-guest-core=3Doff \ +-cpu qemu64 \ +-m 24105 \ +-overcommit mem-lock=3Doff \ +-smp 32,sockets=3D32,cores=3D1,threads=3D1 \ +-object '{"qom-type":"memory-backend-ram","id":"ram-node0","size":20971520= }' \ +-numa node,nodeid=3D0,cpus=3D0,memdev=3Dram-node0 \ +-object '{"qom-type":"memory-backend-ram","id":"ram-node1","size":67633152= 0}' \ +-numa node,nodeid=3D1,cpus=3D1-27,cpus=3D29,memdev=3Dram-node1 \ +-object '{"qom-type":"memory-backend-ram","id":"ram-node2","size":24578621= 440}' \ +-numa node,nodeid=3D2,cpus=3D28,cpus=3D30-31,memdev=3Dram-node2 \ +-uuid 9f4b6512-e73a-4a25-93e8-5307802821ce \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot strict=3Don \ +-device piix3-usb-uhci,id=3Dusb,bus=3Dpci.0,addr=3D0x1.0x2 \ +-audiodev id=3Daudio1,driver=3Dnone \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x2 \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index e919bef98650..572c7b251a30 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2172,6 +2172,7 @@ mymain(void) DO_TEST_CAPS_VER("numatune-memnode", "5.2.0"); DO_TEST_CAPS_LATEST("numatune-memnode"); DO_TEST_PARSE_ERROR("numatune-memnode-invalid-mode", NONE); + DO_TEST_CAPS_LATEST("numatune-memnode-restrictive-mode"); =20 DO_TEST("numatune-memnode-no-memory", QEMU_CAPS_NUMA, --=20 2.31.1