[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mesos-commits
Subject:    (mesos) branch master updated: [cgroups2] Add path helpers that define the cgroup v2 filesystem.
From:       bmahler () apache ! org
Date:       2024-03-27 20:58:43
Message-ID: 171157326303.3227421.7624609150934834310 () gitbox2-he-fi ! apache ! org
[Download RAW message or body]

This is an automated email from the ASF dual-hosted git repository.

bmahler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git


The following commit(s) were added to refs/heads/master by this push:
     new 1d9638af4 [cgroups2] Add path helpers that define the cgroup v2 filesystem.
1d9638af4 is described below

commit 1d9638af476685ca355d890f4c2cd6b692db6b59
Author: Devin Leamy <dleamy@twitter.com>
AuthorDate: Wed Mar 27 16:52:02 2024 -0400

    [cgroups2] Add path helpers that define the cgroup v2 filesystem.
    
    Because of the unified hierarchy and internal processes constraint in
    cgroups v2, a new cgroup directory structure is used.
    
    Here we introduce paths helpers and lay out the directory structure
    of the cgroup2 filesystem.
    
    This closes #537
---
 src/slave/containerizer/mesos/paths.cpp            | 24 ++++++++++++++
 src/slave/containerizer/mesos/paths.hpp            | 35 ++++++++++++++++++++
 .../mesos_containerizer_paths_tests.cpp            | 37 ++++++++++++++++++++++
 3 files changed, 96 insertions(+)

diff --git a/src/slave/containerizer/mesos/paths.cpp \
b/src/slave/containerizer/mesos/paths.cpp index 8230028e9..c379dc1d8 100644
--- a/src/slave/containerizer/mesos/paths.cpp
+++ b/src/slave/containerizer/mesos/paths.cpp
@@ -654,6 +654,30 @@ Option<ContainerID> parseCgroupPath(
   return current;
 }
 
+namespace cgroups2 {
+
+string agent(const string& root, bool leaf)
+{
+  if (leaf) { return path::join(root, "agent", "leaf"); }
+  else      { return path::join(root, "agent"); }
+}
+
+
+string container(
+    const string& root,
+    const ContainerID& containerId,
+    bool leaf)
+{
+  const string& container = containerizer::paths::buildPath(
+      containerId,
+      CGROUP_SEPARATOR,
+      containerizer::paths::JOIN);
+
+  if (leaf) { return path::join(root, container, "leaf"); }
+  else      { return path::join(root, container);}
+}
+
+} // namespace cgroups2 {
 } // namespace paths {
 } // namespace containerizer {
 } // namespace slave {
diff --git a/src/slave/containerizer/mesos/paths.hpp \
b/src/slave/containerizer/mesos/paths.hpp index 5f188e5bb..a5edb98d4 100644
--- a/src/slave/containerizer/mesos/paths.hpp
+++ b/src/slave/containerizer/mesos/paths.hpp
@@ -286,6 +286,41 @@ Option<ContainerID> parseCgroupPath(
     const std::string& cgroupsRoot,
     const std::string& cgroup);
 
+// All cgroups v2 paths are either leaf or non-leaf paths. Leaf paths end
+// in `/leaf`, contain processes, and may impose resource constraints. Non-leaf
+// paths do not contain processes and may impose resource constraints.
+// This is done to avoid the restrictions of the "Internal Process Contraint".
+// More information: \
https://docs.kernel.org/admin-guide/cgroup-v2.html#no-internal-process-constraint +//
+// The cgroup2 file system has the structure:
+// <MOUNT>/<root>/agent                    Mesos Agent constraints
+// <MOUNT>/<root>/agent/leaf               Mesos Agent process
+//
+// <MOUNT>/<root>/<id>                     Container constraints
+// <MOUNT>/<root>/<id>/leaf                Container process
+//
+// <MOUNT>/<root>/<id>/mesos/<id2>         Nested container constraints
+// <MOUNT>/<root>/<id>/mesos/<id2>/leaf    Nested container process
+//
+// For every new level of nesting, `/mesos/<idN>` is added to the path.
+//
+// <root>        Value of the `cgroups_root` flag.
+// <MOUNT>       /sys/fs/cgroup, where the cgroup2 hierarchy is mounted.
+namespace cgroups2 {
+
+// Path to the Mesos Agent's cgroup.
+// `root` is the value of the `cgroups_root` flag.
+std::string agent(const std::string& root, bool leaf = false);
+
+
+// Path to a container's cgroup.
+// `root` is the value of the `cgroups_root` flag.
+std::string container(
+    const std::string& root,
+    const ContainerID& containerId,
+    bool leaf = false);
+
+} // namespace cgroups2 {
 } // namespace paths {
 } // namespace containerizer {
 } // namespace slave {
diff --git a/src/tests/containerizer/mesos_containerizer_paths_tests.cpp \
b/src/tests/containerizer/mesos_containerizer_paths_tests.cpp index \
                1f35703ac..e194b3b92 100644
--- a/src/tests/containerizer/mesos_containerizer_paths_tests.cpp
+++ b/src/tests/containerizer/mesos_containerizer_paths_tests.cpp
@@ -95,6 +95,43 @@ TEST(MesosContainerizerPathsTest, BuildPathJoinMode)
       path::join(parent.value(), separator, child.value()));
 }
 
+
+TEST(MesosContainerizerPathsTest, CGROUPS2_Cgroups2Paths)
+{
+  namespace cgroups2 = mesos::internal::slave::containerizer::paths::cgroups2;
+
+  ContainerID parent;
+  parent.set_value("parent");
+
+  ContainerID child1;
+  child1.set_value("child1");
+  child1.mutable_parent()->CopyFrom(parent);
+
+  ContainerID child2;
+  child2.set_value("child2");
+  child2.mutable_parent()->CopyFrom(child1);
+
+  EXPECT_EQ("mesos/agent",
+            cgroups2::agent("mesos"));
+  EXPECT_EQ("mesos/agent/leaf",
+            cgroups2::agent("mesos", true));
+
+  EXPECT_EQ("mesos/parent",
+            cgroups2::container("mesos", parent));
+  EXPECT_EQ("mesos/parent/leaf",
+            cgroups2::container("mesos", parent, true));
+
+  EXPECT_EQ("mesos/parent/mesos/child1",
+            cgroups2::container("mesos", child1));
+  EXPECT_EQ("mesos/parent/mesos/child1/leaf",
+            cgroups2::container("mesos", child1, true));
+
+  EXPECT_EQ("mesos/parent/mesos/child1/mesos/child2",
+            cgroups2::container("mesos", child2));
+  EXPECT_EQ("mesos/parent/mesos/child1/mesos/child2/leaf",
+            cgroups2::container("mesos", child2, true));
+}
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic