From 9697d24cc223028555629af325af8607de350d06 Mon Sep 17 00:00:00 2001
Message-Id: <9697d24cc223028555629af325af8607de350d06@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:07:39 +0200
Subject: [PATCH] vircgroup: introduce virCgroupV2SetMemory
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 63bd23a6ad17331cdc31bc07fd8b21a96d4b2eb0)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <d2076f596f9e8b58571e19334f23e295f72a2ee5.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/vircgroupv2.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 52d31925c2..1b7215d98b 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -1015,6 +1015,33 @@ virCgroupV2GetBlkioDeviceWriteBps(virCgroupPtr group,
}
+static int
+virCgroupV2SetMemory(virCgroupPtr group,
+ unsigned long long kb)
+{
+ unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED;
+
+ if (kb > maxkb) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("Memory '%llu' must be less than %llu"),
+ kb, maxkb);
+ return -1;
+ }
+
+ if (kb == maxkb) {
+ return virCgroupSetValueStr(group,
+ VIR_CGROUP_CONTROLLER_MEMORY,
+ "memory.max",
+ "max");
+ } else {
+ return virCgroupSetValueU64(group,
+ VIR_CGROUP_CONTROLLER_MEMORY,
+ "memory.max",
+ kb << 10);
+ }
+}
+
+
virCgroupBackend virCgroupV2Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V2,
@@ -1051,6 +1078,8 @@ virCgroupBackend virCgroupV2Backend = {
.getBlkioDeviceReadBps = virCgroupV2GetBlkioDeviceReadBps,
.setBlkioDeviceWriteBps = virCgroupV2SetBlkioDeviceWriteBps,
.getBlkioDeviceWriteBps = virCgroupV2GetBlkioDeviceWriteBps,
+
+ .setMemory = virCgroupV2SetMemory,
};
--
2.22.0