From nobody Sun Feb 8 12:43:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15338222908581.3571853122042512; Thu, 9 Aug 2018 06:44:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D259D81F07; Thu, 9 Aug 2018 13:44:48 +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 07117182D0; Thu, 9 Aug 2018 13:44:48 +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 21D3E1841C69; Thu, 9 Aug 2018 13:44:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w79DiQwG015110 for ; Thu, 9 Aug 2018 09:44:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6F76E2314D; Thu, 9 Aug 2018 13:44:26 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F0242314E for ; Thu, 9 Aug 2018 13:44:25 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 9 Aug 2018 15:44:11 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 16/17] vircgroup: Introduce virCgroupGetMemoryStat 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 09 Aug 2018 13:44:49 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/libvirt_private.syms | 1 + src/util/vircgroup.c | 88 ++++++++++++++++++++++++++++++++++++++++ src/util/vircgroup.h | 7 ++++ 3 files changed, 96 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 59d9bc380e..ee0dca6129 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1532,6 +1532,7 @@ virCgroupGetDomainTotalCpuStats; virCgroupGetFreezerState; virCgroupGetMemoryHardLimit; virCgroupGetMemorySoftLimit; +virCgroupGetMemoryStat; virCgroupGetMemoryUsage; virCgroupGetMemSwapHardLimit; virCgroupGetMemSwapUsage; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 37982a9607..b91acd13c7 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2427,6 +2427,94 @@ virCgroupSetMemory(virCgroupPtr group, unsigned long= long kb) } =20 =20 +/** + * virCgroupGetMemoryStat: + * + * @group: The cgroup to change memory for + * @cache: page cache memory in KiB + * @activeAnon: anonymous and swap cache memory in KiB + * @inactiveAnon: anonymous and swap cache memory in KiB + * @activeFile: file-backed memory in KiB + * @inactiveFile: file-backed memory in KiB + * @unevictable: memory that cannot be reclaimed KiB + * + * Returns: 0 on success, -1 on error + */ +int +virCgroupGetMemoryStat(virCgroupPtr group, + unsigned long long *cache, + unsigned long long *activeAnon, + unsigned long long *inactiveAnon, + unsigned long long *activeFile, + unsigned long long *inactiveFile, + unsigned long long *unevictable) +{ + int ret =3D -1; + char *stat =3D NULL; + char *line =3D NULL; + unsigned long long cacheVal =3D 0; + unsigned long long activeAnonVal =3D 0; + unsigned long long inactiveAnonVal =3D 0; + unsigned long long activeFileVal =3D 0; + unsigned long long inactiveFileVal =3D 0; + unsigned long long unevictableVal =3D 0; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.stat", + &stat) < 0) { + return -1; + } + + line =3D stat; + + while (line) { + char *newLine =3D strchr(line, '\n'); + char *valueStr =3D strchr(line, ' '); + unsigned long long value; + + if (newLine) + *newLine =3D '\0'; + + if (!valueStr) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'memory.stat' cgroup file.")); + goto cleanup; + } + *valueStr =3D '\0'; + + if (virStrToLong_ull(valueStr + 1, NULL, 10, &value) < 0) + goto cleanup; + + if (STREQ(line, "cache")) + cacheVal =3D value >> 10; + else if (STREQ(line, "active_anon")) + activeAnonVal =3D value >> 10; + else if (STREQ(line, "inactive_anon")) + inactiveAnonVal =3D value >> 10; + else if (STREQ(line, "active_file")) + activeFileVal =3D value >> 10; + else if (STREQ(line, "inactive_file")) + inactiveFileVal =3D value >> 10; + else if (STREQ(line, "unevictable")) + unevictableVal =3D value >> 10; + } + + *cache =3D cacheVal; + *activeAnon =3D activeAnonVal; + *inactiveAnon =3D inactiveAnonVal; + *activeFile =3D activeFileVal; + *inactiveFile =3D inactiveFileVal; + *unevictable =3D unevictableVal; + + ret =3D 0; + + cleanup: + VIR_FREE(stat); + return ret; +} + + /** * virCgroupGetMemoryUsage: * diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 48be077aba..c7fdaaede4 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -177,6 +177,13 @@ int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, unsigned long long *wbps); =20 int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb); +int virCgroupGetMemoryStat(virCgroupPtr group, + unsigned long long *cache, + unsigned long long *activeAnon, + unsigned long long *inactiveAnon, + unsigned long long *activeFile, + unsigned long long *inactiveFile, + unsigned long long *unevictable); int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb); =20 int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list