From nobody Fri May 17 22:49:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1670602127; cv=none; d=zohomail.com; s=zohoarc; b=PR7LSIziKbJQS1841vxr+6yupMIwyK0lOLhAYWB7mwywEbATD0qC7puh/+Jsg8kbF7fp3qkZe3IOBo5aZNvramgBtMntyZoIsweizdqxNowod209MuOsT1nOaP84MO0P28PmHe+7CorQPp6HCcJmPQv7ArbOREQdMwXqe4ClyN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670602127; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=HH3SzfLABElSQrQBDyehorsw6f9vOZb2R1xKuy3HBFY=; b=HNjjspEydOA9g0uM5RV2D3jtCiEJIvx5cqVbU/C4hGBm4vivGjNPxL/uiwbc68l1oUvbENaV1/XRN4dd4wBEmtkgh11V/WoEFrrKKV2EVrXfcJkR2l/l7qeH6JsAxyPTPdheAqi04vYspVD7zE4BDdXynbj9FPEnwGOMPR3obIU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1670602127234639.4053783933383; Fri, 9 Dec 2022 08:08:47 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-6-_nfFUs-rN6miMN3lqBd7BA-1; Fri, 09 Dec 2022 11:08:44 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B0A6580A0BF; Fri, 9 Dec 2022 16:08:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28BA81121331; Fri, 9 Dec 2022 16:08:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DCFF51946A7E; Fri, 9 Dec 2022 16:08:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 78D231946A7C for ; Fri, 9 Dec 2022 16:08:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D5184422A9; Fri, 9 Dec 2022 16:08:37 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78D1A42222 for ; Fri, 9 Dec 2022 16:08:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670602126; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HH3SzfLABElSQrQBDyehorsw6f9vOZb2R1xKuy3HBFY=; b=cZD38Cieb6kSzSWQJnE+LJ8w3l07tSD8fwQfK7uwm/SsRyGeOHoP8o9TJjg/VZl809M79C c+TuWtUAfMsqlLPXeJxKB0HnsUwsMmYj9m8bSRU9pIYVZVEIQZ9APk+x3yAFm3CnXZwk43 gFA4UXfbSGmrD+IGEntVdxzEipaHs9U= X-MC-Unique: _nfFUs-rN6miMN3lqBd7BA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virnuma: Allow multiple nodes for preferred policy Date: Fri, 9 Dec 2022 17:08:35 +0100 Message-Id: <162138dd0eb3e48975d57b2b2e08d1a7186efc13.1670602115.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1670602128221100001 Content-Type: text/plain; charset="utf-8"; x-default="true" In the past, the preferred policy (VIR_DOMAIN_NUMATUNE_MEM_PREFERRED) required exactly one (host) NUMA node. This made sense because: 1) the libnuma API - numa_set_preferred() allowed exactly one node, because 2) corresponding kernel syscall (__NR_set_mempolicy) accepted exactly one node (for MPOL_PREFERRED mode). But things have changed since then. Firstly, kernel introduced new MPOL_PREFERRED_MANY mode (v5.15-rc1~107^2~21) which was then exposed in libnuma as numa_set_preferred_many() (v2.0.15~24). Fortunately, libnuma also exposes numa_has_preferred_many() which returns whether the kernel has support for the new mode (1) or not (0). Putting this all together, we can lift our check for sufficiently new kernel and libnuma. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D2151064 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- meson.build | 3 +++ src/util/virnuma.c | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index f9834a36c2..c26778a68d 100644 --- a/meson.build +++ b/meson.build @@ -1103,6 +1103,9 @@ endif numactl_dep =3D cc.find_library('numa', required: get_option('numactl')) if numactl_dep.found() conf.set('WITH_NUMACTL', 1) + if cc.has_function('numa_set_preferred_many', dependencies: numactl_dep) + conf.set('WITH_NUMACTL_SET_PREFERRED_MANY', 1) + endif endif =20 openwsman_version =3D '2.6.3' diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 2306ab0cb1..43e299f4bb 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -93,7 +93,6 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mode, virBitmap *nodeset) { nodemask_t mask; - int node =3D -1; int bit =3D 0; size_t i; int maxnode =3D 0; @@ -128,7 +127,19 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mode, =20 case VIR_DOMAIN_NUMATUNE_MEM_PREFERRED: { +# ifdef WITH_NUMACTL_SET_PREFERRED_MANY + struct bitmask *bitmask =3D NULL; +# endif + int G_GNUC_UNUSED node =3D -1; int nnodes =3D 0; + bool has_preferred_many =3D false; + +# ifdef WITH_NUMACTL_SET_PREFERRED_MANY + if (numa_has_preferred_many() > 0) { + has_preferred_many =3D true; + } +# endif + for (i =3D 0; i < NUMA_NUM_NODES; i++) { if (nodemask_isset(&mask, i)) { node =3D i; @@ -136,15 +147,25 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mod= e, } } =20 - if (nnodes !=3D 1) { + if (!has_preferred_many && nnodes !=3D 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("NUMA memory tuning in 'preferred' mode= " "only supports single node")); return -1; } =20 + /* The following automatically sets MPOL_PREFERRED_MANY + * whenever possible, so no need to special case it. */ numa_set_bind_policy(0); + +# ifdef WITH_NUMACTL_SET_PREFERRED_MANY + bitmask =3D numa_bitmask_alloc(maxnode + 1); + copy_nodemask_to_bitmask(&mask, bitmask); + numa_set_preferred_many(bitmask); + numa_bitmask_free(bitmask); +# else numa_set_preferred(node); +# endif } break; =20 --=20 2.37.4