On 2013年03月18日 17:04, Gao feng wrote:
This patch adds cpuset cgroup support for LXC.
Signed-off-by: Gao feng<gaofeng(a)cn.fujitsu.com>
---
src/lxc/lxc_cgroup.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++-
src/lxc/lxc_cgroup.h | 2 +-
src/lxc/lxc_controller.c | 2 +-
3 files changed, 55 insertions(+), 3 deletions(-)
diff --git PATCH v3src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index a075335..d131932 100644
--- PATCH v3src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -68,6 +68,55 @@ cleanup:
}
+static int virLXCCgroupSetupCpusetTune(virDomainDefPtr def,
+ virCgroupPtr cgroup,
+ virBitmapPtr nodemask)
+{
+ int rc = 0;
+ char *mask = NULL;
+
+ if (def->placement_mode != VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO&&
+ def->cpumask) {
+ mask = virBitmapFormat(def->cpumask);
+ if (!mask) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to convert cpumask"));
+ return -1;
+ }
+
+ rc = virCgroupSetCpusetCpus(cgroup, mask);
+ VIR_FREE(mask);
+ if (rc< 0)
+ virReportSystemError(-rc, "%s",
+ _("Unable to set cpuset.cpus"));
+ }
+
+ if ((def->numatune.memory.nodemask ||
+ (def->numatune.memory.placement_mode ==
+ VIR_NUMATUNE_MEM_PLACEMENT_MODE_AUTO))&&
+ def->numatune.memory.mode == VIR_NUMATUNE_MEM_STRICT) {
+ if (def->numatune.memory.placement_mode ==
+ VIR_NUMATUNE_MEM_PLACEMENT_MODE_AUTO)
+ mask = virBitmapFormat(nodemask);
+ else
+ mask = virBitmapFormat(def->numatune.memory.nodemask);
+
+ if (!mask) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to convert memory nodemask"));
+ return -1;
+ }
+
+ rc = virCgroupSetCpusetMems(cgroup, mask);
+ VIR_FREE(mask);
+ if (rc< 0)
+ virReportSystemError(-rc, "%s", _("Unable to set
cpuset.mems"));
+ }
+
+ return rc;
+}
+
+
static int virLXCCgroupSetupBlkioTune(virDomainDefPtr def,
virCgroupPtr cgroup)
{
@@ -472,7 +521,7 @@ cleanup:
}
-int virLXCCgroupSetup(virDomainDefPtr def)
+int virLXCCgroupSetup(virDomainDefPtr def, virBitmapPtr nodemask)
{
virCgroupPtr driver = NULL;
virCgroupPtr cgroup = NULL;
@@ -497,6 +546,9 @@ int virLXCCgroupSetup(virDomainDefPtr def)
if (virLXCCgroupSetupCpuTune(def, cgroup)< 0)
goto cleanup;
+ if (virLXCCgroupSetupCpusetTune(def, cgroup, nodemask)< 0)
+ goto cleanup;
+
if (virLXCCgroupSetupBlkioTune(def, cgroup)< 0)
goto cleanup;
diff --git PATCH v3src/lxc/lxc_cgroup.h b/src/lxc/lxc_cgroup.h
index fff554b..29f21d6 100644
--- PATCH v3src/lxc/lxc_cgroup.h
+++ b/src/lxc/lxc_cgroup.h
@@ -26,7 +26,7 @@
# include "lxc_fuse.h"
# include "virusb.h"
-int virLXCCgroupSetup(virDomainDefPtr def);
+int virLXCCgroupSetup(virDomainDefPtr def, virBitmapPtr nodemask);
int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo);
int
diff --git PATCH v3src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 6c5b8c8..eea2595 100644
--- PATCH v3src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -578,7 +578,7 @@ static int virLXCControllerSetupResourceLimits(virLXCControllerPtr
ctrl)
if (virLXCControllerSetupCpuAffinity(ctrl)< 0)
goto cleanup;
- if (virLXCCgroupSetup(ctrl->def)< 0)
+ if (virLXCCgroupSetup(ctrl->def, nodemask)< 0)
goto cleanup;
ret = 0;
ACK