|
|
c480ed |
From 22e8736edafd1ac369adead17d924bd6b9536817 Mon Sep 17 00:00:00 2001
|
|
|
c480ed |
Message-Id: <22e8736edafd1ac369adead17d924bd6b9536817@dist-git>
|
|
|
c480ed |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
Date: Mon, 1 Jul 2019 17:06:50 +0200
|
|
|
c480ed |
Subject: [PATCH] vircgroup: extract virCgroupV1GetMemoryStat
|
|
|
c480ed |
MIME-Version: 1.0
|
|
|
c480ed |
Content-Type: text/plain; charset=UTF-8
|
|
|
c480ed |
Content-Transfer-Encoding: 8bit
|
|
|
c480ed |
|
|
|
c480ed |
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
|
|
|
c480ed |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c480ed |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
(cherry picked from commit 64bfbd7ceb328d27becf98e0539d0ab4bcda8163)
|
|
|
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: <cafcbd973766d6e41a57c23e83b34912fe67e3f5.1561993100.git.phrdina@redhat.com>
|
|
|
c480ed |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c480ed |
---
|
|
|
c480ed |
src/util/vircgroup.c | 67 ++------------------------------
|
|
|
c480ed |
src/util/vircgroupbackend.h | 10 +++++
|
|
|
c480ed |
src/util/vircgroupv1.c | 76 +++++++++++++++++++++++++++++++++++++
|
|
|
c480ed |
3 files changed, 90 insertions(+), 63 deletions(-)
|
|
|
c480ed |
|
|
|
c480ed |
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
|
|
|
c480ed |
index 4053c65939..786034d555 100644
|
|
|
c480ed |
--- a/src/util/vircgroup.c
|
|
|
c480ed |
+++ b/src/util/vircgroup.c
|
|
|
c480ed |
@@ -1619,69 +1619,10 @@ virCgroupGetMemoryStat(virCgroupPtr group,
|
|
|
c480ed |
unsigned long long *inactiveFile,
|
|
|
c480ed |
unsigned long long *unevictable)
|
|
|
c480ed |
{
|
|
|
c480ed |
- int ret = -1;
|
|
|
c480ed |
- char *stat = NULL;
|
|
|
c480ed |
- char *line = NULL;
|
|
|
c480ed |
- unsigned long long cacheVal = 0;
|
|
|
c480ed |
- unsigned long long activeAnonVal = 0;
|
|
|
c480ed |
- unsigned long long inactiveAnonVal = 0;
|
|
|
c480ed |
- unsigned long long activeFileVal = 0;
|
|
|
c480ed |
- unsigned long long inactiveFileVal = 0;
|
|
|
c480ed |
- unsigned long long unevictableVal = 0;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virCgroupGetValueStr(group,
|
|
|
c480ed |
- VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
- "memory.stat",
|
|
|
c480ed |
- &stat) < 0) {
|
|
|
c480ed |
- return -1;
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- line = stat;
|
|
|
c480ed |
-
|
|
|
c480ed |
- while (line) {
|
|
|
c480ed |
- char *newLine = strchr(line, '\n');
|
|
|
c480ed |
- char *valueStr = strchr(line, ' ');
|
|
|
c480ed |
- unsigned long long value;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (newLine)
|
|
|
c480ed |
- *newLine = '\0';
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (!valueStr) {
|
|
|
c480ed |
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
c480ed |
- _("Cannot parse 'memory.stat' cgroup file."));
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
- }
|
|
|
c480ed |
- *valueStr = '\0';
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (virStrToLong_ull(valueStr + 1, NULL, 10, &value) < 0)
|
|
|
c480ed |
- goto cleanup;
|
|
|
c480ed |
-
|
|
|
c480ed |
- if (STREQ(line, "cache"))
|
|
|
c480ed |
- cacheVal = value >> 10;
|
|
|
c480ed |
- else if (STREQ(line, "active_anon"))
|
|
|
c480ed |
- activeAnonVal = value >> 10;
|
|
|
c480ed |
- else if (STREQ(line, "inactive_anon"))
|
|
|
c480ed |
- inactiveAnonVal = value >> 10;
|
|
|
c480ed |
- else if (STREQ(line, "active_file"))
|
|
|
c480ed |
- activeFileVal = value >> 10;
|
|
|
c480ed |
- else if (STREQ(line, "inactive_file"))
|
|
|
c480ed |
- inactiveFileVal = value >> 10;
|
|
|
c480ed |
- else if (STREQ(line, "unevictable"))
|
|
|
c480ed |
- unevictableVal = value >> 10;
|
|
|
c480ed |
- }
|
|
|
c480ed |
-
|
|
|
c480ed |
- *cache = cacheVal;
|
|
|
c480ed |
- *activeAnon = activeAnonVal;
|
|
|
c480ed |
- *inactiveAnon = inactiveAnonVal;
|
|
|
c480ed |
- *activeFile = activeFileVal;
|
|
|
c480ed |
- *inactiveFile = inactiveFileVal;
|
|
|
c480ed |
- *unevictable = unevictableVal;
|
|
|
c480ed |
-
|
|
|
c480ed |
- ret = 0;
|
|
|
c480ed |
-
|
|
|
c480ed |
- cleanup:
|
|
|
c480ed |
- VIR_FREE(stat);
|
|
|
c480ed |
- return ret;
|
|
|
c480ed |
+ VIR_CGROUP_BACKEND_CALL(group, getMemoryStat, -1, cache,
|
|
|
c480ed |
+ activeAnon, inactiveAnon,
|
|
|
c480ed |
+ activeFile, inactiveFile,
|
|
|
c480ed |
+ unevictable);
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
|
|
|
c480ed |
index e1f75c5c31..99754a6310 100644
|
|
|
c480ed |
--- a/src/util/vircgroupbackend.h
|
|
|
c480ed |
+++ b/src/util/vircgroupbackend.h
|
|
|
c480ed |
@@ -214,6 +214,15 @@ typedef int
|
|
|
c480ed |
(*virCgroupSetMemoryCB)(virCgroupPtr group,
|
|
|
c480ed |
unsigned long long kb);
|
|
|
c480ed |
|
|
|
c480ed |
+typedef int
|
|
|
c480ed |
+(*virCgroupGetMemoryStatCB)(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long *cache,
|
|
|
c480ed |
+ unsigned long long *activeAnon,
|
|
|
c480ed |
+ unsigned long long *inactiveAnon,
|
|
|
c480ed |
+ unsigned long long *activeFile,
|
|
|
c480ed |
+ unsigned long long *inactiveFile,
|
|
|
c480ed |
+ unsigned long long *unevictable);
|
|
|
c480ed |
+
|
|
|
c480ed |
struct _virCgroupBackend {
|
|
|
c480ed |
virCgroupBackendType type;
|
|
|
c480ed |
|
|
|
c480ed |
@@ -254,6 +263,7 @@ struct _virCgroupBackend {
|
|
|
c480ed |
virCgroupGetBlkioDeviceWriteBpsCB getBlkioDeviceWriteBps;
|
|
|
c480ed |
|
|
|
c480ed |
virCgroupSetMemoryCB setMemory;
|
|
|
c480ed |
+ virCgroupGetMemoryStatCB getMemoryStat;
|
|
|
c480ed |
};
|
|
|
c480ed |
typedef struct _virCgroupBackend virCgroupBackend;
|
|
|
c480ed |
typedef virCgroupBackend *virCgroupBackendPtr;
|
|
|
c480ed |
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
|
|
|
c480ed |
index 17a4d67972..fcb2607e26 100644
|
|
|
c480ed |
--- a/src/util/vircgroupv1.c
|
|
|
c480ed |
+++ b/src/util/vircgroupv1.c
|
|
|
c480ed |
@@ -1404,6 +1404,81 @@ virCgroupV1SetMemory(virCgroupPtr group,
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupV1GetMemoryStat(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long *cache,
|
|
|
c480ed |
+ unsigned long long *activeAnon,
|
|
|
c480ed |
+ unsigned long long *inactiveAnon,
|
|
|
c480ed |
+ unsigned long long *activeFile,
|
|
|
c480ed |
+ unsigned long long *inactiveFile,
|
|
|
c480ed |
+ unsigned long long *unevictable)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ int ret = -1;
|
|
|
c480ed |
+ char *stat = NULL;
|
|
|
c480ed |
+ char *line = NULL;
|
|
|
c480ed |
+ unsigned long long cacheVal = 0;
|
|
|
c480ed |
+ unsigned long long activeAnonVal = 0;
|
|
|
c480ed |
+ unsigned long long inactiveAnonVal = 0;
|
|
|
c480ed |
+ unsigned long long activeFileVal = 0;
|
|
|
c480ed |
+ unsigned long long inactiveFileVal = 0;
|
|
|
c480ed |
+ unsigned long long unevictableVal = 0;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virCgroupGetValueStr(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.stat",
|
|
|
c480ed |
+ &stat) < 0) {
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ line = stat;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ while (line) {
|
|
|
c480ed |
+ char *newLine = strchr(line, '\n');
|
|
|
c480ed |
+ char *valueStr = strchr(line, ' ');
|
|
|
c480ed |
+ unsigned long long value;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (newLine)
|
|
|
c480ed |
+ *newLine = '\0';
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (!valueStr) {
|
|
|
c480ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
c480ed |
+ _("Cannot parse 'memory.stat' cgroup file."));
|
|
|
c480ed |
+ goto cleanup;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+ *valueStr = '\0';
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virStrToLong_ull(valueStr + 1, NULL, 10, &value) < 0)
|
|
|
c480ed |
+ goto cleanup;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (STREQ(line, "cache"))
|
|
|
c480ed |
+ cacheVal = value >> 10;
|
|
|
c480ed |
+ else if (STREQ(line, "active_anon"))
|
|
|
c480ed |
+ activeAnonVal = value >> 10;
|
|
|
c480ed |
+ else if (STREQ(line, "inactive_anon"))
|
|
|
c480ed |
+ inactiveAnonVal = value >> 10;
|
|
|
c480ed |
+ else if (STREQ(line, "active_file"))
|
|
|
c480ed |
+ activeFileVal = value >> 10;
|
|
|
c480ed |
+ else if (STREQ(line, "inactive_file"))
|
|
|
c480ed |
+ inactiveFileVal = value >> 10;
|
|
|
c480ed |
+ else if (STREQ(line, "unevictable"))
|
|
|
c480ed |
+ unevictableVal = value >> 10;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ *cache = cacheVal;
|
|
|
c480ed |
+ *activeAnon = activeAnonVal;
|
|
|
c480ed |
+ *inactiveAnon = inactiveAnonVal;
|
|
|
c480ed |
+ *activeFile = activeFileVal;
|
|
|
c480ed |
+ *inactiveFile = inactiveFileVal;
|
|
|
c480ed |
+ *unevictable = unevictableVal;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ ret = 0;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ cleanup:
|
|
|
c480ed |
+ VIR_FREE(stat);
|
|
|
c480ed |
+ return ret;
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
virCgroupBackend virCgroupV1Backend = {
|
|
|
c480ed |
.type = VIR_CGROUP_BACKEND_TYPE_V1,
|
|
|
c480ed |
|
|
|
c480ed |
@@ -1442,6 +1517,7 @@ virCgroupBackend virCgroupV1Backend = {
|
|
|
c480ed |
.getBlkioDeviceWriteBps = virCgroupV1GetBlkioDeviceWriteBps,
|
|
|
c480ed |
|
|
|
c480ed |
.setMemory = virCgroupV1SetMemory,
|
|
|
c480ed |
+ .getMemoryStat = virCgroupV1GetMemoryStat,
|
|
|
c480ed |
};
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
--
|
|
|
c480ed |
2.22.0
|
|
|
c480ed |
|