From nobody Sun Apr 19 12:43:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=oss.nttdata.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1776273553920760.4486974231143; Wed, 15 Apr 2026 10:19:13 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id D631D3F363; Wed, 15 Apr 2026 13:19:12 -0400 (EDT) Received: from [172.19.199.3] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id 8016F417FF; Wed, 15 Apr 2026 13:18:19 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 4E2A13F2FA; Wed, 15 Apr 2026 13:18:07 -0400 (EDT) Received: from oss.nttdata.com (oss.nttdata.com [49.212.34.109]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 8D9143F2EF for ; Wed, 15 Apr 2026 13:18:05 -0400 (EDT) Received: from fedora.. (madb688a0d.ap.nuro.jp [219.104.138.13]) by oss.nttdata.com (Postfix) with ESMTPSA id 7D0E32020282; Thu, 16 Apr 2026 02:18:01 +0900 (JST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=4.0.1 From: Takashi Kajinami To: devel@lists.libvirt.org Subject: [PATCH] Add MemAvailable to node memory stats Date: Thu, 16 Apr 2026 02:17:56 +0900 Message-ID: <20260415171757.2146769-1-kajinamit@oss.nttdata.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: clamav-milter 1.4.3 at oss.nttdata.com X-Virus-Status: Clean Message-ID-Hash: 24OOEOH5QVATRM73CLSICLBVPFQOTD7S X-Message-ID-Hash: 24OOEOH5QVATRM73CLSICLBVPFQOTD7S X-MailFrom: kajinamit@oss.nttdata.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Takashi Kajinami X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-ZM-MESSAGEID: 1776273558216154100 Content-Type: text/plain; charset="utf-8" MemAvailable was introduced in kernel version 3.10 (and it was even backported to older kernels in some distributions) and has been a quite popular method to estimate the available method (totally fully amount + reclaimable amount). Signed-off-by: Takashi Kajinami Reviewed-by: Peter Krempa --- include/libvirt/libvirt-host.h | 10 ++++++++++ src/libvirt-host.c | 2 ++ src/util/virhostmem.c | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h index 398b40c35a..5b448e7954 100644 --- a/include/libvirt/libvirt-host.h +++ b/include/libvirt/libvirt-host.h @@ -364,6 +364,16 @@ typedef enum { */ # define VIR_NODE_MEMORY_STATS_CACHED "cached" =20 +/** + * VIR_NODE_MEMORY_STATS_AVAILABLE: + * + * Macro for the available memory: On Linux, it is only returned in case of + * VIR_NODE_MEMORY_STATS_ALL_CELLS. + * + * Since: 12.3.0 + */ +# define VIR_NODE_MEMORY_STATS_AVAILABLE "available" + /** * virNodeMemoryStats: * diff --git a/src/libvirt-host.c b/src/libvirt-host.c index da75f5f30b..6b4345b09d 100644 --- a/src/libvirt-host.c +++ b/src/libvirt-host.c @@ -633,6 +633,8 @@ virNodeGetCPUStats(virConnectPtr conn, * The buffers memory usage.(KB) * VIR_NODE_MEMORY_STATS_CACHED: * The cached memory usage.(KB) + * VIR_NODE_MEMORY_STATS_AVAILABLE: + * The available memory usage.(KB) * * Returns -1 in case of error, 0 in case of success. * diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c index a7027af835..09a322fdea 100644 --- a/src/util/virhostmem.c +++ b/src/util/virhostmem.c @@ -136,7 +136,7 @@ virHostMemGetStatsFreeBSD(virNodeMemoryStatsPtr params, # define SYSFS_MEMORY_SHARED_PATH "/sys/kernel/mm/ksm" # define SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX 8192 =20 -# define LINUX_NB_MEMORY_STATS_ALL 4 +# define LINUX_NB_MEMORY_STATS_ALL 5 # define LINUX_NB_MEMORY_STATS_CELL 2 =20 static int @@ -159,6 +159,7 @@ virHostMemGetStatsLinux(FILE *meminfo, {"MemFree:", VIR_NODE_MEMORY_STATS_FREE}, {"Buffers:", VIR_NODE_MEMORY_STATS_BUFFERS}, {"Cached:", VIR_NODE_MEMORY_STATS_CACHED}, + {"MemAvailable:", VIR_NODE_MEMORY_STATS_AVAILABLE}, {NULL, NULL} }; =20 --=20 2.49.0