From: Nikunj A. Dadhania <nikunj(a)linux.vnet.ibm.com>
v4:
* Fix: call cgroup apis only if tunables are non zero
QEmu startup would pick up the memory tunables specified in the domain
configuration file.
Acked-by: "Daniel P. Berrange" <berrange(a)redhat.com>
Signed-off-by: Nikunj A. Dadhania <nikunj(a)linux.vnet.ibm.com>
---
src/qemu/qemu.conf | 4 ++--
src/qemu/qemu_conf.c | 3 ++-
src/qemu/qemu_driver.c | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index dc8eb83..bfb9f6a 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -111,13 +111,13 @@
# the adminsitrator has mounted cgroups. eg
#
# mkdir /dev/cgroup
-# mount -t cgroup -o devices,cpu none /dev/cgroup
+# mount -t cgroup -o devices,cpu,memory none /dev/cgroup
#
# They can be mounted anywhere, and different controlers
# can be mounted in different locations. libvirt will detect
# where they are located.
#
-# cgroup_controllers = [ "cpu", "devices" ]
+# cgroup_controllers = [ "cpu", "devices", "memory" ]
# This is the basic set of devices allowed / required by
# all virtual machines.
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 731c554..3f5c1ac 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -275,7 +275,8 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
} else {
driver->cgroupControllers =
(1 << VIR_CGROUP_CONTROLLER_CPU) |
- (1 << VIR_CGROUP_CONTROLLER_DEVICES);
+ (1 << VIR_CGROUP_CONTROLLER_DEVICES) |
+ (1 << VIR_CGROUP_CONTROLLER_MEMORY);
}
for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) {
if (driver->cgroupControllers & (1 << i)) {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8eaa762..70b9bac 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3495,6 +3495,40 @@ static int qemuSetupCgroup(struct qemud_driver *driver,
goto cleanup;
}
+ if ((rc = qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY))) {
+ if (vm->def->mem.hard_limit != 0) {
+ rc = virCgroupSetMemoryHardLimit(cgroup, vm->def->mem.hard_limit);
+ if (rc != 0) {
+ virReportSystemError(-rc,
+ _("Unable to set memory hard limit for domain
%s"),
+ vm->def->name);
+ goto cleanup;
+ }
+ }
+ if (vm->def->mem.soft_limit != 0) {
+ rc = virCgroupSetMemorySoftLimit(cgroup, vm->def->mem.soft_limit);
+ if (rc != 0) {
+ virReportSystemError(-rc,
+ _("Unable to set memory soft limit for domain
%s"),
+ vm->def->name);
+ goto cleanup;
+ }
+ }
+
+ if (vm->def->mem.swap_hard_limit != 0) {
+ rc = virCgroupSetSwapHardLimit(cgroup, vm->def->mem.swap_hard_limit);
+ if (rc != 0) {
+ virReportSystemError(-rc,
+ _("Unable to set swap hard limit for domain
%s"),
+ vm->def->name);
+ goto cleanup;
+ }
+ }
+ } else {
+ VIR_WARN("Memory cgroup is disabled in qemu configuration file: %s",
+ vm->def->name);
+ }
+
done:
virCgroupFree(&cgroup);
return 0;