render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From 0f9d55fe0fbbdc66a5fdc2236c9433aab840a1b9 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <0f9d55fe0fbbdc66a5fdc2236c9433aab840a1b9@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:07:41 +0200
c480ed
Subject: [PATCH] vircgroup: introduce virCgroupV2GetMemoryUsage
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit 495f60edcb123a714706f765027ea190f8d20da3)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <fe7485f1f5e5743721ff623ecddac0d27dbc3f1e.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroupv2.c | 15 +++++++++++++++
c480ed
 1 file changed, 15 insertions(+)
c480ed
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
index 1c7854909f..87d357b0a7 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -1116,6 +1116,20 @@ virCgroupV2GetMemoryStat(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV2GetMemoryUsage(virCgroupPtr group,
c480ed
+                          unsigned long *kb)
c480ed
+{
c480ed
+    unsigned long long usage_in_bytes;
c480ed
+    int ret = virCgroupGetValueU64(group,
c480ed
+                                   VIR_CGROUP_CONTROLLER_MEMORY,
c480ed
+                                   "memory.current", &usage_in_bytes);
c480ed
+    if (ret == 0)
c480ed
+        *kb = (unsigned long) usage_in_bytes >> 10;
c480ed
+    return ret;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV2Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
c480ed
 
c480ed
@@ -1155,6 +1169,7 @@ virCgroupBackend virCgroupV2Backend = {
c480ed
 
c480ed
     .setMemory = virCgroupV2SetMemory,
c480ed
     .getMemoryStat = virCgroupV2GetMemoryStat,
c480ed
+    .getMemoryUsage = virCgroupV2GetMemoryUsage,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed