From nobody Tue May 13 15:43:17 2025 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 1538469957886554.864163184837; Tue, 2 Oct 2018 01:45:57 -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 940BE804E2; Tue, 2 Oct 2018 08:45:55 +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 5763D6D01C; Tue, 2 Oct 2018 08:45:55 +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 E4F39181B9FC; Tue, 2 Oct 2018 08:45:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928jAb9031489 for ; Tue, 2 Oct 2018 04:45:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 69EE91001903; Tue, 2 Oct 2018 08:45:10 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id E064810016DC for ; Tue, 2 Oct 2018 08:45:09 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:14 +0200 Message-Id: <432b8045335af410a12936bc075f17e77893ec1a.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 30/53] vircgroup: introduce virCgroupV2GetMemoryStat 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.27]); Tue, 02 Oct 2018 08:45:56 +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/util/vircgroupv2.c | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 32d20f2ff6..da3b3a984c 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -1044,6 +1044,80 @@ virCgroupV2SetMemory(virCgroupPtr group, } =20 =20 +static int +virCgroupV2GetMemoryStat(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) +{ + VIR_AUTOFREE(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.")); + return -1; + } + *valueStr =3D '\0'; + + if (virStrToLong_ull(valueStr + 1, NULL, 10, &value) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + valueStr + 1); + return -1; + } + + if (STREQ(line, "file")) + 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; + + return 0; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -1082,6 +1156,7 @@ virCgroupBackend virCgroupV2Backend =3D { .getBlkioDeviceWriteBps =3D virCgroupV2GetBlkioDeviceWriteBps, =20 .setMemory =3D virCgroupV2SetMemory, + .getMemoryStat =3D virCgroupV2GetMemoryStat, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list