118 lines
3.7 KiB
Diff
118 lines
3.7 KiB
Diff
From 7b4215f8a38221fd90bf15a3ced42cce55adf105 Mon Sep 17 00:00:00 2001
|
|
Message-Id: <7b4215f8a38221fd90bf15a3ced42cce55adf105@dist-git>
|
|
From: Pavel Hrdina <phrdina@redhat.com>
|
|
Date: Mon, 1 Jul 2019 17:07:40 +0200
|
|
Subject: [PATCH] vircgroup: introduce virCgroupV2GetMemoryStat
|
|
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 d080c001660ed0f173066b3db63ecac4edb773fc)
|
|
|
|
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
|
|
|
|
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Message-Id: <9ebb30d0c01bdb6e356928701cd56501fe43af5e.1561993100.git.phrdina@redhat.com>
|
|
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
---
|
|
src/util/vircgroupv2.c | 75 ++++++++++++++++++++++++++++++++++++++++++
|
|
1 file changed, 75 insertions(+)
|
|
|
|
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
|
|
index 1b7215d98b..1c7854909f 100644
|
|
--- a/src/util/vircgroupv2.c
|
|
+++ b/src/util/vircgroupv2.c
|
|
@@ -1042,6 +1042,80 @@ virCgroupV2SetMemory(virCgroupPtr group,
|
|
}
|
|
|
|
|
|
+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 = NULL;
|
|
+ char *line = NULL;
|
|
+ unsigned long long cacheVal = 0;
|
|
+ unsigned long long activeAnonVal = 0;
|
|
+ unsigned long long inactiveAnonVal = 0;
|
|
+ unsigned long long activeFileVal = 0;
|
|
+ unsigned long long inactiveFileVal = 0;
|
|
+ unsigned long long unevictableVal = 0;
|
|
+
|
|
+ if (virCgroupGetValueStr(group,
|
|
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
+ "memory.stat",
|
|
+ &stat) < 0) {
|
|
+ return -1;
|
|
+ }
|
|
+
|
|
+ line = stat;
|
|
+
|
|
+ while (line) {
|
|
+ char *newLine = strchr(line, '\n');
|
|
+ char *valueStr = strchr(line, ' ');
|
|
+ unsigned long long value;
|
|
+
|
|
+ if (newLine)
|
|
+ *newLine = '\0';
|
|
+
|
|
+ if (!valueStr) {
|
|
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
+ _("Cannot parse 'memory.stat' cgroup file."));
|
|
+ return -1;
|
|
+ }
|
|
+ *valueStr = '\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 = value >> 10;
|
|
+ else if (STREQ(line, "active_anon"))
|
|
+ activeAnonVal = value >> 10;
|
|
+ else if (STREQ(line, "inactive_anon"))
|
|
+ inactiveAnonVal = value >> 10;
|
|
+ else if (STREQ(line, "active_file"))
|
|
+ activeFileVal = value >> 10;
|
|
+ else if (STREQ(line, "inactive_file"))
|
|
+ inactiveFileVal = value >> 10;
|
|
+ else if (STREQ(line, "unevictable"))
|
|
+ unevictableVal = value >> 10;
|
|
+ }
|
|
+
|
|
+ *cache = cacheVal;
|
|
+ *activeAnon = activeAnonVal;
|
|
+ *inactiveAnon = inactiveAnonVal;
|
|
+ *activeFile = activeFileVal;
|
|
+ *inactiveFile = inactiveFileVal;
|
|
+ *unevictable = unevictableVal;
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+
|
|
virCgroupBackend virCgroupV2Backend = {
|
|
.type = VIR_CGROUP_BACKEND_TYPE_V2,
|
|
|
|
@@ -1080,6 +1154,7 @@ virCgroupBackend virCgroupV2Backend = {
|
|
.getBlkioDeviceWriteBps = virCgroupV2GetBlkioDeviceWriteBps,
|
|
|
|
.setMemory = virCgroupV2SetMemory,
|
|
+ .getMemoryStat = virCgroupV2GetMemoryStat,
|
|
};
|
|
|
|
|
|
--
|
|
2.22.0
|
|
|