|
|
c480ed |
From 86212853c9f16bbed77c2310aed1795fdb04f59d Mon Sep 17 00:00:00 2001
|
|
|
c480ed |
Message-Id: <86212853c9f16bbed77c2310aed1795fdb04f59d@dist-git>
|
|
|
c480ed |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
Date: Mon, 1 Jul 2019 17:07:44 +0200
|
|
|
c480ed |
Subject: [PATCH] vircgroup: introduce virCgroupV2(Set|Get)MemSwapHardLimit
|
|
|
c480ed |
MIME-Version: 1.0
|
|
|
c480ed |
Content-Type: text/plain; charset=UTF-8
|
|
|
c480ed |
Content-Transfer-Encoding: 8bit
|
|
|
c480ed |
|
|
|
c480ed |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
c480ed |
(cherry picked from commit df63fd1f8f17354c5f81c991ff1bb7d12f96d986)
|
|
|
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: <39af05bcaea91a81740ba6d0b766f773f0e8580b.1561993100.git.phrdina@redhat.com>
|
|
|
c480ed |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c480ed |
---
|
|
|
c480ed |
src/util/vircgroupv2.c | 62 ++++++++++++++++++++++++++++++++++++++++++
|
|
|
c480ed |
1 file changed, 62 insertions(+)
|
|
|
c480ed |
|
|
|
c480ed |
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
|
|
|
c480ed |
index d8a1d7712f..fed6792e16 100644
|
|
|
c480ed |
--- a/src/util/vircgroupv2.c
|
|
|
c480ed |
+++ b/src/util/vircgroupv2.c
|
|
|
c480ed |
@@ -1230,6 +1230,66 @@ virCgroupV2GetMemorySoftLimit(virCgroupPtr group,
|
|
|
c480ed |
}
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupV2SetMemSwapHardLimit(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long kb)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (kb > maxkb) {
|
|
|
c480ed |
+ virReportError(VIR_ERR_INVALID_ARG,
|
|
|
c480ed |
+ _("Memory '%llu' must be less than %llu"),
|
|
|
c480ed |
+ kb, maxkb);
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (kb == maxkb) {
|
|
|
c480ed |
+ return virCgroupSetValueStr(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.swap.max",
|
|
|
c480ed |
+ "max");
|
|
|
c480ed |
+ } else {
|
|
|
c480ed |
+ return virCgroupSetValueU64(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.swap.max",
|
|
|
c480ed |
+ kb << 10);
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
+static int
|
|
|
c480ed |
+virCgroupV2GetMemSwapHardLimit(virCgroupPtr group,
|
|
|
c480ed |
+ unsigned long long *kb)
|
|
|
c480ed |
+{
|
|
|
c480ed |
+ VIR_AUTOFREE(char *) value = NULL;
|
|
|
c480ed |
+ unsigned long long max;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virCgroupGetValueStr(group,
|
|
|
c480ed |
+ VIR_CGROUP_CONTROLLER_MEMORY,
|
|
|
c480ed |
+ "memory.swap.max", &value) < 0) {
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (STREQ(value, "max")) {
|
|
|
c480ed |
+ *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
+ return 0;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ if (virStrToLong_ull(value, NULL, 10, &max) < 0) {
|
|
|
c480ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c480ed |
+ _("Failed to parse value '%s' as number."),
|
|
|
c480ed |
+ value);
|
|
|
c480ed |
+ return -1;
|
|
|
c480ed |
+ }
|
|
|
c480ed |
+
|
|
|
c480ed |
+ *kb = max >> 10;
|
|
|
c480ed |
+ if (*kb >= VIR_DOMAIN_MEMORY_PARAM_UNLIMITED)
|
|
|
c480ed |
+ *kb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
|
|
|
c480ed |
+
|
|
|
c480ed |
+ return 0;
|
|
|
c480ed |
+}
|
|
|
c480ed |
+
|
|
|
c480ed |
+
|
|
|
c480ed |
virCgroupBackend virCgroupV2Backend = {
|
|
|
c480ed |
.type = VIR_CGROUP_BACKEND_TYPE_V2,
|
|
|
c480ed |
|
|
|
c480ed |
@@ -1274,6 +1334,8 @@ virCgroupBackend virCgroupV2Backend = {
|
|
|
c480ed |
.getMemoryHardLimit = virCgroupV2GetMemoryHardLimit,
|
|
|
c480ed |
.setMemorySoftLimit = virCgroupV2SetMemorySoftLimit,
|
|
|
c480ed |
.getMemorySoftLimit = virCgroupV2GetMemorySoftLimit,
|
|
|
c480ed |
+ .setMemSwapHardLimit = virCgroupV2SetMemSwapHardLimit,
|
|
|
c480ed |
+ .getMemSwapHardLimit = virCgroupV2GetMemSwapHardLimit,
|
|
|
c480ed |
};
|
|
|
c480ed |
|
|
|
c480ed |
|
|
|
c480ed |
--
|
|
|
c480ed |
2.22.0
|
|
|
c480ed |
|