You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by br...@apache.org on 2013/07/25 00:04:20 UTC

git commit: Changed cgroups killTasks() sequence.

Updated Branches:
  refs/heads/master 26f252ec1 -> 77db3cb32


Changed cgroups killTasks() sequence.

The sequence is as follows:
  stop -> kill -> empty -> freeze -> kill -> thaw -> empty

We also now ignore ESRCH errors from kill() in cgroups::kill().

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


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

Branch: refs/heads/master
Commit: 77db3cb32f9d25656b86607f6f241b2303dbd982
Parents: 26f252e
Author: Brenden Matthews <br...@airbnb.com>
Authored: Fri May 10 16:00:15 2013 -0700
Committer: Brenden Matthews <br...@airbnb.com>
Committed: Wed Jul 24 15:03:31 2013 -0700

----------------------------------------------------------------------
 src/linux/cgroups.cpp | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/77db3cb3/src/linux/cgroups.cpp
----------------------------------------------------------------------
diff --git a/src/linux/cgroups.cpp b/src/linux/cgroups.cpp
index 5207ded..b97a89c 100644
--- a/src/linux/cgroups.cpp
+++ b/src/linux/cgroups.cpp
@@ -825,9 +825,14 @@ Try<Nothing> kill(
 
   foreach (pid_t pid, pids.get()) {
     if (::kill(pid, signal) == -1) {
-      return ErrnoError(
-          "Failed to send " + string(strsignal(signal)) +
-          " to process " + stringify(pid));
+      // If errno is set to ESRCH, it means that either a) this process already
+      // terminated, or b) it's in a 'zombie' state and we can't signal it
+      // anyway.  In either case, ignore the error.
+      if (errno != ESRCH) {
+        return ErrnoError(
+            "Failed to send " + string(strsignal(signal)) +
+            " to process " + stringify(pid));
+      }
     }
   }
 
@@ -1505,15 +1510,21 @@ protected:
   }
 
 private:
+  // The sequence of operations to kill a cgroup is as follows:
+  // SIGSTOP -> SIGKILL -> empty -> freeze -> SIGKILL -> thaw -> empty
+  // This process is repeated until the cgroup becomes empty.
   void killTasks() {
     // Chain together the steps needed to kill the tasks. Note that we
     // ignore the return values of freeze, kill, and thaw because,
     // provided there are no errors, we'll just retry the chain as
     // long as tasks still exist.
-    chain = freeze()                      // Freeze the cgroup.
-      .then(defer(self(), &Self::kill))   // Send kill signals to all tasks.
-      .then(defer(self(), &Self::thaw))   // Thaw cgroup to deliver signals.
-      .then(defer(self(), &Self::empty)); // Wait until cgroup is empty.
+    chain = kill(SIGSTOP)                        // Send stop signal to all tasks.
+      .then(defer(self(), &Self::kill, SIGKILL)) // Now send kill signal.
+      .then(defer(self(), &Self::empty))         // Wait until cgroup is empty.
+      .then(defer(self(), &Self::freeze))        // Freeze cgroug.
+      .then(defer(self(), &Self::kill, SIGKILL)) // Send kill signal to any remaining tasks.
+      .then(defer(self(), &Self::thaw))          // Thaw cgroup to deliver signals.
+      .then(defer(self(), &Self::empty));        // Wait until cgroup is empty.
 
     chain.onAny(defer(self(), &Self::finished, lambda::_1));
   }
@@ -1523,9 +1534,9 @@ private:
     return cgroups::freeze(hierarchy, cgroup, interval);
   }
 
-  Future<Nothing> kill()
+  Future<Nothing> kill(const int signal)
   {
-    Try<Nothing> kill = cgroups::kill(hierarchy, cgroup, SIGKILL);
+    Try<Nothing> kill = cgroups::kill(hierarchy, cgroup, signal);
     if (kill.isError()) {
       return Future<Nothing>::failed(kill.error());
     }