You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ab...@apache.org on 2020/03/13 10:00:05 UTC
[mesos] 02/06: Fixed `cgroups::create` for nested cgroups.
This is an automated email from the ASF dual-hosted git repository.
abudnik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 81555e8d73507afcc28bc6ee92c2ef456adbaf87
Author: Andrei Budnik <ab...@mesosphere.com>
AuthorDate: Tue Mar 3 14:57:49 2020 +0100
Fixed `cgroups::create` for nested cgroups.
This patch modifies `cgroups::create` function to call
`cloneCpusetCpusMems` for all absent nested cgroups along
the path to a cgroup that is accepted as an argument to this function.
For instance, if `cgroups::create` is called to create three
non-existent cgroups recursively for the path `/a/b/c`, then
`cloneCpusetCpusMems` is called to clone both `cpuset.cpus` and
`cpuset.mems` for `/a` from its parent, then `/a/b` from `/a`,
and so on down the path.
Review: https://reviews.apache.org/r/72122/
---
src/linux/cgroups.cpp | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/linux/cgroups.cpp b/src/linux/cgroups.cpp
index 73646c9..2234f0d 100644
--- a/src/linux/cgroups.cpp
+++ b/src/linux/cgroups.cpp
@@ -646,7 +646,19 @@ Try<Nothing> create(
const string& cgroup,
bool recursive)
{
+ vector<string> missingCgroups;
+ string currentCgroup;
+ Path cgroupPath(cgroup);
+ for (auto it = cgroupPath.begin(); it != cgroupPath.end(); ++it) {
+ currentCgroup = path::join(currentCgroup, *it);
+ if (!missingCgroups.empty() ||
+ !os::exists(path::join(hierarchy, currentCgroup))) {
+ missingCgroups.push_back(currentCgroup);
+ }
+ }
+
string path = path::join(hierarchy, cgroup);
+
Try<Nothing> mkdir = os::mkdir(path, recursive);
if (mkdir.isError()) {
return Error(
@@ -661,8 +673,18 @@ Try<Nothing> create(
"Failed to determine if hierarchy '" + hierarchy +
"' has the 'cpuset' subsystem attached: " + attached.error());
} else if (attached->count("cpuset") > 0) {
- string parent = Path(path::join("/", cgroup)).dirname();
- return internal::cloneCpusetCpusMems(hierarchy, parent, cgroup);
+ foreach (const string& cgroup, missingCgroups) {
+ string parent = Path(cgroup).dirname();
+
+ Try<Nothing> clone =
+ internal::cloneCpusetCpusMems(hierarchy, parent, cgroup);
+
+ if (clone.isError()) {
+ return Error(
+ "Failed to clone `cpuset.cpus` and `cpuset.mems` from '" +
+ parent + "' to '" + cgroup + "': " + clone.error());
+ }
+ }
}
return Nothing();