Blob Blame History Raw
From 0f9d55fe0fbbdc66a5fdc2236c9433aab840a1b9 Mon Sep 17 00:00:00 2001
Message-Id: <0f9d55fe0fbbdc66a5fdc2236c9433aab840a1b9@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:07:41 +0200
Subject: [PATCH] vircgroup: introduce virCgroupV2GetMemoryUsage
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 495f60edcb123a714706f765027ea190f8d20da3)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <fe7485f1f5e5743721ff623ecddac0d27dbc3f1e.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroupv2.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 1c7854909f..87d357b0a7 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -1116,6 +1116,20 @@ virCgroupV2GetMemoryStat(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV2GetMemoryUsage(virCgroupPtr group,
+                          unsigned long *kb)
+{
+    unsigned long long usage_in_bytes;
+    int ret = virCgroupGetValueU64(group,
+                                   VIR_CGROUP_CONTROLLER_MEMORY,
+                                   "memory.current", &usage_in_bytes);
+    if (ret == 0)
+        *kb = (unsigned long) usage_in_bytes >> 10;
+    return ret;
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
@@ -1155,6 +1169,7 @@ virCgroupBackend virCgroupV2Backend = {
 
     .setMemory = virCgroupV2SetMemory,
     .getMemoryStat = virCgroupV2GetMemoryStat,
+    .getMemoryUsage = virCgroupV2GetMemoryUsage,
 };
 
 
-- 
2.22.0