]> xenbits.xensource.com Git - libvirt.git/commitdiff
Adding memtunables to qemuSetupCgroup
authorNikunj A. Dadhania <nikunj@linux.vnet.ibm.com>
Tue, 12 Oct 2010 16:12:31 +0000 (18:12 +0200)
committerDaniel Veillard <veillard@redhat.com>
Tue, 12 Oct 2010 17:26:09 +0000 (19:26 +0200)
QEmu startup will pick up the memory tunables specified in the domain
configuration file

src/qemu/qemu.conf
src/qemu/qemu_conf.c
src/qemu/qemu_driver.c

index dc8eb83d05e264fc1a7c4759ac40bd81e5df5828..bfb9f6ae85b3c0c8c9df82d5adf05455e4354001 100644 (file)
 # 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.
index b0c8dcc7017a9352f31511be3972d44aa13f0589..95b97842baf76320f13c69e59047aa66ac6986d2 100644 (file)
@@ -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)) {
index 18b2b975c715dae3f66febc94be8c6f961557741..607e4e452af375b2a9344b4f2574e8519fe69dc3 100644 (file)
@@ -3497,6 +3497,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;