aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/ContainerUtils.py
diff options
context:
space:
mode:
authorPeter Mikus <pmikus@cisco.com>2018-02-12 07:39:16 +0100
committerPeter Mikus <pmikus@cisco.com>2018-02-23 09:24:30 +0000
commitdbb2fccef88f1633ee5278ca373418ab1883a5a4 (patch)
tree9f8837101f0a3f5cd15aa8cf64619c9757c0b424 /resources/libraries/python/ContainerUtils.py
parent3b5e5e14a10c3cac63a526b5d9ac495822fd663f (diff)
FIX: LXC/DOCKER exclusive CPU
By default the cpuset cgroup is using exclusive CPU/MEM. When Docker container is initialized a new cgroup /docker or /lxc is created under cpuset parent tree. This newly created cgroup is inheriting parent setting for cpu/mem exclusive parameter and thus cannot be overriden within /docker or /lxc cgroup. This patch is supposed to set cpu/mem exclusive parameter for both parent and subgroup. Change-Id: I14b44db3f77c842756ec78aa60df7aca508d9545 Signed-off-by: Peter Mikus <pmikus@cisco.com>
Diffstat (limited to 'resources/libraries/python/ContainerUtils.py')
-rw-r--r--resources/libraries/python/ContainerUtils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/resources/libraries/python/ContainerUtils.py b/resources/libraries/python/ContainerUtils.py
index b56fb0dc24..ed058b7597 100644
--- a/resources/libraries/python/ContainerUtils.py
+++ b/resources/libraries/python/ContainerUtils.py
@@ -357,11 +357,28 @@ class ContainerEngine(object):
def _configure_cgroup(self, name):
"""Configure the control group associated with a container.
+ By default the cpuset cgroup is using exclusive CPU/MEM. When Docker
+ container is initialized a new cgroup /docker or /lxc is created under
+ cpuset parent tree. This newly created cgroup is inheriting parent
+ setting for cpu/mem exclusive parameter and thus cannot be overriden
+ within /docker or /lxc cgroup. This patch is supposed to set cpu/mem
+ exclusive parameter for both parent and subgroup.
+
:param name: Name of cgroup.
:type name: str
:raises RuntimeError: If applying cgroup settings via cgset failed.
"""
ret, _, _ = self.container.ssh.exec_command_sudo(
+ 'cgset -r cpuset.cpu_exclusive=0 /')
+ if int(ret) != 0:
+ raise RuntimeError('Failed to apply cgroup settings.')
+
+ ret, _, _ = self.container.ssh.exec_command_sudo(
+ 'cgset -r cpuset.mem_exclusive=0 /')
+ if int(ret) != 0:
+ raise RuntimeError('Failed to apply cgroup settings.')
+
+ ret, _, _ = self.container.ssh.exec_command_sudo(
'cgcreate -g cpuset:/{name}'.format(name=name))
if int(ret) != 0:
raise RuntimeError('Failed to copy cgroup settings from root.')