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