You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gi...@apache.org on 2018/07/20 21:37:46 UTC

[1/2] mesos git commit: Added container-specific cgroups mount for freezer & systemd subsystems.

Repository: mesos
Updated Branches:
  refs/heads/master 7f74785fc -> 90301b521


Added container-specific cgroups mount for freezer & systemd subsystems.

Review: https://reviews.apache.org/r/67896/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/11658749
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/11658749
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/11658749

Branch: refs/heads/master
Commit: 116587498859cfd23d605941d7d0de0ce618f2ca
Parents: 7f74785
Author: Qian Zhang <zh...@gmail.com>
Authored: Fri Jul 20 14:37:27 2018 -0700
Committer: Gilbert Song <so...@gmail.com>
Committed: Fri Jul 20 14:37:27 2018 -0700

----------------------------------------------------------------------
 src/slave/containerizer/mesos/constants.hpp     |  2 +
 .../mesos/isolators/cgroups/cgroups.cpp         | 50 ++++++++++++++++++++
 .../containerizer/mesos/linux_launcher.cpp      |  4 +-
 3 files changed, 53 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/11658749/src/slave/containerizer/mesos/constants.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/constants.hpp b/src/slave/containerizer/mesos/constants.hpp
index 5be3950..981c1ab 100644
--- a/src/slave/containerizer/mesos/constants.hpp
+++ b/src/slave/containerizer/mesos/constants.hpp
@@ -27,6 +27,8 @@ constexpr char MESOS_CONTAINERIZER[] = "mesos-containerizer";
 constexpr char MESOS_CONTAINERIZER[] = "mesos-containerizer.exe";
 #endif // __WINDOWS__
 
+constexpr char CGROUP_SEPARATOR[] = "mesos";
+
 } // namespace slave {
 } // namespace internal {
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/11658749/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
index 8fba6f9..e016d6d 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
@@ -34,6 +34,10 @@
 #include "linux/cgroups.hpp"
 #include "linux/fs.hpp"
 #include "linux/ns.hpp"
+#include "linux/systemd.hpp"
+
+#include "slave/containerizer/mesos/constants.hpp"
+#include "slave/containerizer/mesos/paths.hpp"
 
 #include "slave/containerizer/mesos/isolators/cgroups/cgroups.hpp"
 #include "slave/containerizer/mesos/isolators/cgroups/constants.hpp"
@@ -605,6 +609,52 @@ Future<Option<ContainerLaunchInfo>> CgroupsIsolatorProcess::__prepare(
     mount->set_flags(MS_BIND | MS_REC);
   }
 
+  // Linux launcher will create freezer and systemd cgroups for the container,
+  // so here we need to do the container-specific cgroups mounts for them too,
+  // see MESOS-9070 for details.
+  if (flags.launcher == "linux") {
+    Result<string> hierarchy = cgroups::hierarchy("freezer");
+    if (hierarchy.isError()) {
+      return Failure(
+          "Failed to retrieve the 'freezer' subsystem hierarchy: " +
+          hierarchy.error());
+    }
+
+    ContainerMountInfo* mount = launchInfo.add_mounts();
+    mount->set_source(path::join(
+        hierarchy.get(),
+        flags.cgroups_root,
+        containerizer::paths::buildPath(
+            containerId,
+            CGROUP_SEPARATOR,
+            containerizer::paths::JOIN)));
+
+    mount->set_target(path::join(
+        containerConfig.rootfs(),
+        "/sys/fs/cgroup",
+        "freezer"));
+
+    mount->set_flags(MS_BIND | MS_REC);
+
+    if (systemd::enabled()) {
+      mount = launchInfo.add_mounts();
+      mount->set_source(path::join(
+          systemd::hierarchy(),
+          flags.cgroups_root,
+          containerizer::paths::buildPath(
+              containerId,
+              CGROUP_SEPARATOR,
+              containerizer::paths::JOIN)));
+
+      mount->set_target(path::join(
+          containerConfig.rootfs(),
+          "/sys/fs/cgroup",
+          "systemd"));
+
+      mount->set_flags(MS_BIND | MS_REC);
+    }
+  }
+
   // TODO(qianzhang): This is a hack to pass the container-specific cgroups
   // mounts and the symbolic links to the command executor to do for the
   // command task. The reasons that we do it in this way are:

http://git-wip-us.apache.org/repos/asf/mesos/blob/11658749/src/slave/containerizer/mesos/linux_launcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/linux_launcher.cpp b/src/slave/containerizer/mesos/linux_launcher.cpp
index 3bddcec..cd677cc 100644
--- a/src/slave/containerizer/mesos/linux_launcher.cpp
+++ b/src/slave/containerizer/mesos/linux_launcher.cpp
@@ -37,6 +37,7 @@
 
 #include "mesos/resources.hpp"
 
+#include "slave/containerizer/mesos/constants.hpp"
 #include "slave/containerizer/mesos/linux_launcher.hpp"
 #include "slave/containerizer/mesos/paths.hpp"
 
@@ -53,9 +54,6 @@ namespace mesos {
 namespace internal {
 namespace slave {
 
-static const char CGROUP_SEPARATOR[] = "mesos";
-
-
 // Launcher for Linux systems with cgroups. Uses a freezer cgroup to
 // track pids.
 class LinuxLauncherProcess : public Process<LinuxLauncherProcess>


[2/2] mesos git commit: Updated two tests to verfiy freezer subsystem.

Posted by gi...@apache.org.
Updated two tests to verfiy freezer subsystem.

Review: https://reviews.apache.org/r/67897/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/90301b52
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/90301b52
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/90301b52

Branch: refs/heads/master
Commit: 90301b521da1084509716af484045add091c3d50
Parents: 1165874
Author: Qian Zhang <zh...@gmail.com>
Authored: Fri Jul 20 14:37:31 2018 -0700
Committer: Gilbert Song <so...@gmail.com>
Committed: Fri Jul 20 14:37:31 2018 -0700

----------------------------------------------------------------------
 .../containerizer/cgroups_isolator_tests.cpp    | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/90301b52/src/tests/containerizer/cgroups_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/cgroups_isolator_tests.cpp b/src/tests/containerizer/cgroups_isolator_tests.cpp
index 3041640..368ab93 100644
--- a/src/tests/containerizer/cgroups_isolator_tests.cpp
+++ b/src/tests/containerizer/cgroups_isolator_tests.cpp
@@ -1904,8 +1904,8 @@ TEST_F(CgroupsIsolatorTest, ROOT_CGROUPS_AutoLoadSubsystems)
 }
 
 
-// This test verifies container-specific cgroup is correctly mounted inside the
-// nested container.
+// This test verifies the container-specific cgroups are correctly mounted
+// inside the nested container.
 TEST_F(CgroupsIsolatorTest, ROOT_CGROUPS_NestedContainerSpecificCgroupsMount)
 {
   // Disable AuthN on the agent.
@@ -1962,10 +1962,14 @@ TEST_F(CgroupsIsolatorTest, ROOT_CGROUPS_NestedContainerSpecificCgroupsMount)
   // Create a task to check if its memory (including both executor and task's
   // memory) is correctly set in its specific cgroup, e.g.:
   //  `/sys/fs/cgroup/memory/memory.soft_limit_in_bytes`
+  //
+  // And we also verify the freezer cgroup is correctly mounted for this task
+  // by checking if the current shell PID is included in the freezer cgroup.
   v1::TaskInfo taskInfo = v1::createTask(
       offer.agent_id(),
       v1::Resources::parse("cpus:0.1;mem:32;disk:32").get(),
-      "test `cat /sys/fs/cgroup/memory/memory.soft_limit_in_bytes` = 67108864");
+      "test `cat /sys/fs/cgroup/memory/memory.soft_limit_in_bytes` = 67108864 "
+      "&& grep $$ /sys/fs/cgroup/freezer/cgroup.procs");
 
   mesos::v1::Image image;
   image.set_type(mesos::v1::Image::DOCKER);
@@ -2010,8 +2014,8 @@ TEST_F(CgroupsIsolatorTest, ROOT_CGROUPS_NestedContainerSpecificCgroupsMount)
 }
 
 
-// This test verifies container-specific cgroup is correctly mounted for the
-// command task.
+// This test verifies the container-specific cgroups are correctly mounted for
+// the command task.
 TEST_F(CgroupsIsolatorTest, ROOT_CGROUPS_CommandTaskSpecificCgroupsMount)
 {
   Try<Owned<cluster::Master>> master = StartMaster();
@@ -2045,10 +2049,14 @@ TEST_F(CgroupsIsolatorTest, ROOT_CGROUPS_CommandTaskSpecificCgroupsMount)
   // Create a task to check if its memory (including both executor and task's
   // memory) is correctly set in its specific cgroup, e.g.:
   //  `/sys/fs/cgroup/memory/memory.soft_limit_in_bytes`
+  //
+  // And we also verify the freezer cgroup is correctly mounted for this task
+  // by checking if the current shell PID is included in the freezer cgroup.
   TaskInfo task = createTask(
       offers->front().slave_id(),
       Resources::parse("cpus:0.1;mem:32;disk:32").get(),
-      "test `cat /sys/fs/cgroup/memory/memory.soft_limit_in_bytes` = 67108864");
+      "test `cat /sys/fs/cgroup/memory/memory.soft_limit_in_bytes` = 67108864 "
+      "&& grep $$ /sys/fs/cgroup/freezer/cgroup.procs");
 
   Image image;
   image.set_type(Image::DOCKER);