|
Pablo Greco |
40546a |
From 6a1f3fdcf13ff1fdcbd1f63443a1e5d05b2ddd1c Mon Sep 17 00:00:00 2001
|
|
Pablo Greco |
40546a |
Message-Id: <6a1f3fdcf13ff1fdcbd1f63443a1e5d05b2ddd1c@dist-git>
|
|
Pablo Greco |
40546a |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Date: Mon, 1 Jul 2019 17:07:43 +0200
|
|
Pablo Greco |
40546a |
Subject: [PATCH] vircgroup: introduce virCgroupV2(Set|Get)MemorySoftLimit
|
|
Pablo Greco |
40546a |
MIME-Version: 1.0
|
|
Pablo Greco |
40546a |
Content-Type: text/plain; charset=UTF-8
|
|
Pablo Greco |
40546a |
Content-Transfer-Encoding: 8bit
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
(cherry picked from commit 94db4bf86ea10e9853f62c4ea079a432482a58df)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Message-Id: <a59c442f9098898c0196a5fb2a0d3527ce277153.1561993100.git.phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
Pablo Greco |
40546a |
---
|
|
Pablo Greco |
40546a |
src/util/vircgroupv2.c | 61 ++++++++++++++++++++++++++++++++++++++++++
|
|
Pablo Greco |
40546a |
1 file changed, 61 insertions(+)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
|
|
Pablo Greco |
40546a |
index 81a577d28f..d8a1d7712f 100644
|
|
Pablo Greco |
40546a |
--- a/src/util/vircgroupv2.c
|
|
Pablo Greco |
40546a |
+++ b/src/util/vircgroupv2.c
|
|
Pablo Greco |
40546a |
@@ -1171,6 +1171,65 @@ virCgroupV2GetMemoryHardLimit(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
+static int
|
|
Pablo Greco |
40546a |
+virCgroupV2SetMemorySoftLimit(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
+ unsigned long long kb)
|
|
Pablo Greco |
40546a |
+{
|
|
Pablo Greco |
40546a |
+ unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (kb > maxkb) {
|
|
Pablo Greco |
40546a |
+ virReportError(VIR_ERR_INVALID_ARG,
|
|
Pablo Greco |
40546a |
+ _("Memory '%llu' must be less than %llu"),
|
|
Pablo Greco |
40546a |
+ kb, maxkb);
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (kb == maxkb) {
|
|
Pablo Greco |
40546a |
+ return virCgroupSetValueStr(group,
|
|
Pablo Greco |
40546a |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
Pablo Greco |
40546a |
+ "memory.high",
|
|
Pablo Greco |
40546a |
+ "max");
|
|
Pablo Greco |
40546a |
+ } else {
|
|
Pablo Greco |
40546a |
+ return virCgroupSetValueU64(group,
|
|
Pablo Greco |
40546a |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
Pablo Greco |
40546a |
+ "memory.high",
|
|
Pablo Greco |
40546a |
+ kb << 10);
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+}
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+static int
|
|
Pablo Greco |
40546a |
+virCgroupV2GetMemorySoftLimit(virCgroupPtr group,
|
|
Pablo Greco |
40546a |
+ unsigned long long *kb)
|
|
Pablo Greco |
40546a |
+{
|
|
Pablo Greco |
40546a |
+ VIR_AUTOFREE(char *) value = NULL;
|
|
Pablo Greco |
40546a |
+ unsigned long long high;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virCgroupGetValueStr(group,
|
|
Pablo Greco |
40546a |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
Pablo Greco |
40546a |
+ "memory.high", &value) < 0)
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (STREQ(value, "max")) {
|
|
Pablo Greco |
40546a |
+ *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
Pablo Greco |
40546a |
+ return 0;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ if (virStrToLong_ull(value, NULL, 10, &high) < 0) {
|
|
Pablo Greco |
40546a |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
Pablo Greco |
40546a |
+ _("Failed to parse value '%s' as number."),
|
|
Pablo Greco |
40546a |
+ value);
|
|
Pablo Greco |
40546a |
+ return -1;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ *kb = high >> 10;
|
|
Pablo Greco |
40546a |
+ if (*kb >= VIR_DOMAIN_MEMORY_PARAM_UNLIMITED)
|
|
Pablo Greco |
40546a |
+ *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+ return 0;
|
|
Pablo Greco |
40546a |
+}
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
virCgroupBackend virCgroupV2Backend = {
|
|
Pablo Greco |
40546a |
.type = VIR_CGROUP_BACKEND_TYPE_V2,
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
@@ -1213,6 +1272,8 @@ virCgroupBackend virCgroupV2Backend = {
|
|
Pablo Greco |
40546a |
.getMemoryUsage = virCgroupV2GetMemoryUsage,
|
|
Pablo Greco |
40546a |
.setMemoryHardLimit = virCgroupV2SetMemoryHardLimit,
|
|
Pablo Greco |
40546a |
.getMemoryHardLimit = virCgroupV2GetMemoryHardLimit,
|
|
Pablo Greco |
40546a |
+ .setMemorySoftLimit = virCgroupV2SetMemorySoftLimit,
|
|
Pablo Greco |
40546a |
+ .getMemorySoftLimit = virCgroupV2GetMemorySoftLimit,
|
|
Pablo Greco |
40546a |
};
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
--
|
|
Pablo Greco |
40546a |
2.22.0
|
|
Pablo Greco |
40546a |
|