render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 64df2fa746eab23c73578c53b6d8501cbec2d04c Mon Sep 17 00:00:00 2001
Message-Id: <64df2fa746eab23c73578c53b6d8501cbec2d04c@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:07:45 +0200
Subject: [PATCH] vircgroup: introduce virCgroupV2GetMemSwapUsage
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 3f728c720b782e853de4c43999a37aeceb3f95b8)

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

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

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index fed6792e16..8d184bd963 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -1290,6 +1290,21 @@ virCgroupV2GetMemSwapHardLimit(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV2GetMemSwapUsage(virCgroupPtr group,
+                           unsigned long long *kb)
+{
+    unsigned long long usage_in_bytes;
+    int ret;
+    ret = virCgroupGetValueU64(group,
+                               VIR_CGROUP_CONTROLLER_MEMORY,
+                               "memory.swap.current", &usage_in_bytes);
+    if (ret == 0)
+        *kb = (unsigned long) usage_in_bytes >> 10;
+    return ret;
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
@@ -1336,6 +1351,7 @@ virCgroupBackend virCgroupV2Backend = {
     .getMemorySoftLimit = virCgroupV2GetMemorySoftLimit,
     .setMemSwapHardLimit = virCgroupV2SetMemSwapHardLimit,
     .getMemSwapHardLimit = virCgroupV2GetMemSwapHardLimit,
+    .getMemSwapUsage = virCgroupV2GetMemSwapUsage,
 };
 
 
-- 
2.22.0