You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by id...@apache.org on 2014/06/21 01:55:52 UTC
[1/2] git commit: Added cgroups::memory::oom and
cgroups::memory::oom::killer controls.
Repository: mesos
Updated Branches:
refs/heads/master a991580d7 -> ce09d171f
Added cgroups::memory::oom and cgroups::memory::oom::killer controls.
Review: https://reviews.apache.org/r/20137
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/326aa493
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/326aa493
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/326aa493
Branch: refs/heads/master
Commit: 326aa493fb445302137d538d456712249504d251
Parents: a991580
Author: Ian Downes <id...@twitter.com>
Authored: Tue Apr 8 14:52:20 2014 -0700
Committer: Ian Downes <id...@twitter.com>
Committed: Fri Jun 20 16:54:49 2014 -0700
----------------------------------------------------------------------
src/linux/cgroups.cpp | 93 ++++++++++++++++++++
src/linux/cgroups.hpp | 33 +++++++
.../containerizer/isolators/cgroups/mem.cpp | 21 ++---
.../containerizer/isolators/cgroups/mem.hpp | 4 +-
src/tests/cgroups_tests.cpp | 12 +--
5 files changed, 141 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/326aa493/src/linux/cgroups.cpp
----------------------------------------------------------------------
diff --git a/src/linux/cgroups.cpp b/src/linux/cgroups.cpp
index a4274a8..5472eb8 100644
--- a/src/linux/cgroups.cpp
+++ b/src/linux/cgroups.cpp
@@ -1908,6 +1908,99 @@ Try<Bytes> max_usage_in_bytes(const string& hierarchy, const string& cgroup)
return Bytes::parse(strings::trim(read.get()) + "B");
}
+
+namespace oom {
+
+namespace {
+
+Nothing _nothing() { return Nothing(); }
+
+} // namespace {
+
+Future<Nothing> listen(const string& hierarchy, const string& cgroup)
+{
+ return cgroups::listen(hierarchy, cgroup, "memory.oom_control")
+ .then(lambda::bind(&_nothing));
+}
+
+
+namespace killer {
+
+Try<bool> enabled(const string& hierarchy, const string& cgroup)
+{
+ Try<bool> exists = cgroups::exists(hierarchy, cgroup, "memory.oom_control");
+
+ if (exists.isError() || !exists.get()) {
+ return Error("Could not find 'memory.oom_control' control file: " +
+ (exists.isError() ? exists.error() : "does not exist"));
+ }
+
+ Try<string> read = cgroups::read(hierarchy, cgroup, "memory.oom_control");
+
+ if (read.isError()) {
+ return Error("Could not read 'memory.oom_control' control file: " +
+ read.error());
+ }
+
+ map<string, vector<string> > pairs = strings::pairs(read.get(), "\n", " ");
+
+ if (pairs.count("oom_kill_disable") != 1 ||
+ pairs["oom_kill_disable"].size() != 1) {
+ return Error("Could not determine oom control state");
+ }
+
+ // Enabled if not disabled.
+ return pairs["oom_kill_disable"].front() == "0";
+}
+
+
+Try<Nothing> enable(const string& hierarchy, const string& cgroup)
+{
+ Try<bool> enabled = killer::enabled(hierarchy, cgroup);
+
+ if (enabled.isError()) {
+ return Error(enabled.error());
+ }
+
+ if (!enabled.get()) {
+ Try<Nothing> write = cgroups::write(
+ hierarchy, cgroup, "memory.oom_control", "0");
+
+ if (write.isError()) {
+ return Error("Could not write 'memory.oom_control' control file: " +
+ write.error());
+ }
+ }
+
+ return Nothing();
+}
+
+
+Try<Nothing> disable(const string& hierarchy, const string& cgroup)
+{
+ Try<bool> enabled = killer::enabled(hierarchy, cgroup);
+
+ if (enabled.isError()) {
+ return Error(enabled.error());
+ }
+
+ if (enabled.get()) {
+ Try<Nothing> write = cgroups::write(
+ hierarchy, cgroup, "memory.oom_control", "1");
+
+ if (write.isError()) {
+ return Error("Could not write 'memory.oom_control' control file: " +
+ write.error());
+ }
+ }
+
+ return Nothing();
+}
+
+} // namespace killer {
+
+} // namespace oom {
+
} // namespace memory {
http://git-wip-us.apache.org/repos/asf/mesos/blob/326aa493/src/linux/cgroups.hpp
----------------------------------------------------------------------
diff --git a/src/linux/cgroups.hpp b/src/linux/cgroups.hpp
index 75c5602..eba4cdf 100644
--- a/src/linux/cgroups.hpp
+++ b/src/linux/cgroups.hpp
@@ -447,6 +447,39 @@ Try<Bytes> max_usage_in_bytes(
const std::string& hierarchy,
const std::string& cgroup);
+
+// Out-of-memory (OOM) controls.
+namespace oom {
+
+// Listen for an OOM event for the cgroup.
+process::Future<Nothing> listen(
+ const std::string& hierarchy,
+ const std::string& cgroup);
+
+// OOM killer controls.
+namespace killer {
+
+// Return whether the kernel OOM killer is enabled for the cgroup.
+Try<bool> enabled(
+ const std::string& hierarchy,
+ const std::string& cgroup);
+
+// Enable the kernel OOM killer for the cgroup. The control file will
+// only be written to if necessary.
+Try<Nothing> enable(
+ const std::string& hierarchy,
+ const std::string& cgroup);
+
+// Disable the kernel OOM killer. The control file will only be
+// written to if necessary.
+Try<Nothing> disable(
+ const std::string& hierarchy,
+ const std::string& cgroup);
+
+} // namespace killer {
+
+} // namespace oom {
+
} // namespace memory {
http://git-wip-us.apache.org/repos/asf/mesos/blob/326aa493/src/slave/containerizer/isolators/cgroups/mem.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/isolators/cgroups/mem.cpp b/src/slave/containerizer/isolators/cgroups/mem.cpp
index 3b731f9..e8d1e35 100644
--- a/src/slave/containerizer/isolators/cgroups/mem.cpp
+++ b/src/slave/containerizer/isolators/cgroups/mem.cpp
@@ -80,21 +80,15 @@ Try<Isolator*> CgroupsMemIsolatorProcess::create(const Flags& flags)
return Error("Failed to create memory cgroup: " + hierarchy.error());
}
- // Make sure the kernel supports OOM controls.
- Try<bool> exists = cgroups::exists(
- hierarchy.get(), flags.cgroups_root, "memory.oom_control");
- if (exists.isError() || !exists.get()) {
- return Error("Failed to determine if 'memory.oom_control' control exists");
- }
-
// Make sure the kernel OOM-killer is enabled.
// The Mesos OOM handler, as implemented, is not capable of handling
// the oom condition by itself safely given the limitations Linux
// imposes on this code path.
- Try<Nothing> write = cgroups::write(
- hierarchy.get(), flags.cgroups_root, "memory.oom_control", "0");
- if (write.isError()) {
- return Error("Failed to update memory.oom_control");
+ Try<Nothing> enable = cgroups::memory::oom::killer::enable(
+ hierarchy.get(), flags.cgroups_root);
+
+ if (enable.isError()) {
+ return Error(enable.error());
}
process::Owned<IsolatorProcess> process(
@@ -418,8 +412,7 @@ void CgroupsMemIsolatorProcess::oomListen(
CHECK(infos.contains(containerId));
Info* info = CHECK_NOTNULL(infos[containerId]);
- info->oomNotifier =
- cgroups::listen(hierarchy, info->cgroup, "memory.oom_control");
+ info->oomNotifier = cgroups::memory::oom::listen(hierarchy, info->cgroup);
// If the listening fails immediately, something very wrong
// happened. Therefore, we report a fatal error here.
@@ -442,7 +435,7 @@ void CgroupsMemIsolatorProcess::oomListen(
void CgroupsMemIsolatorProcess::oomWaited(
const ContainerID& containerId,
- const Future<uint64_t>& future)
+ const Future<Nothing>& future)
{
if (future.isDiscarded()) {
LOG(INFO) << "Discarded OOM notifier for container "
http://git-wip-us.apache.org/repos/asf/mesos/blob/326aa493/src/slave/containerizer/isolators/cgroups/mem.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/isolators/cgroups/mem.hpp b/src/slave/containerizer/isolators/cgroups/mem.hpp
index 33b0ca8..8c476c7 100644
--- a/src/slave/containerizer/isolators/cgroups/mem.hpp
+++ b/src/slave/containerizer/isolators/cgroups/mem.hpp
@@ -89,7 +89,7 @@ private:
process::Promise<Limitation> limitation;
// Used to cancel the OOM listening.
- process::Future<uint64_t> oomNotifier;
+ process::Future<Nothing> oomNotifier;
};
// Start listening on OOM events. This function will create an
@@ -100,7 +100,7 @@ private:
// result.
void oomWaited(
const ContainerID& containerId,
- const process::Future<uint64_t>& future);
+ const process::Future<Nothing>& future);
// This function is invoked when the OOM event happens.
void oom(const ContainerID& containerId);
http://git-wip-us.apache.org/repos/asf/mesos/blob/326aa493/src/tests/cgroups_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cgroups_tests.cpp b/src/tests/cgroups_tests.cpp
index bfb5858..815a266 100644
--- a/src/tests/cgroups_tests.cpp
+++ b/src/tests/cgroups_tests.cpp
@@ -503,7 +503,7 @@ TEST_F(CgroupsAnyHierarchyWithCpuMemoryTest, ROOT_CGROUPS_Listen)
std::string hierarchy = path::join(baseHierarchy, "memory");
ASSERT_SOME(cgroups::create(hierarchy, TEST_CGROUPS_ROOT));
ASSERT_SOME(
- cgroups::exists(hierarchy, TEST_CGROUPS_ROOT, "memory.oom_control"))
+ cgroups::memory::oom::killer::enabled(hierarchy, TEST_CGROUPS_ROOT))
<< "-------------------------------------------------------------\n"
<< "We cannot run this test because it appears you do not have\n"
<< "a modern enough version of the Linux kernel. You won't be\n"
@@ -512,8 +512,8 @@ TEST_F(CgroupsAnyHierarchyWithCpuMemoryTest, ROOT_CGROUPS_Listen)
<< "-------------------------------------------------------------";
// Disable oom killer.
- ASSERT_SOME(
- cgroups::write(hierarchy, TEST_CGROUPS_ROOT, "memory.oom_control", "1"));
+ ASSERT_SOME(cgroups::memory::oom::killer::disable(
+ hierarchy, TEST_CGROUPS_ROOT));
// Limit the memory usage of the test cgroup to 64MB.
size_t limit = 1024 * 1024 * 64;
@@ -524,15 +524,15 @@ TEST_F(CgroupsAnyHierarchyWithCpuMemoryTest, ROOT_CGROUPS_Listen)
stringify(limit)));
// Listen on oom events for test cgroup.
- Future<uint64_t> future = cgroups::listen(
- hierarchy, TEST_CGROUPS_ROOT, "memory.oom_control");
+ Future<Nothing> future =
+ cgroups::memory::oom::listen(hierarchy, TEST_CGROUPS_ROOT);
ASSERT_FALSE(future.isFailed());
// Test the cancellation.
future.discard();
// Test the normal operation below.
- future = cgroups::listen(hierarchy, TEST_CGROUPS_ROOT, "memory.oom_control");
+ future = cgroups::memory::oom::listen(hierarchy, TEST_CGROUPS_ROOT);
ASSERT_FALSE(future.isFailed());
pid_t pid = ::fork();
[2/2] git commit: Cleaned up test to use
cgroups::memory::limit_in_bytes
Posted by id...@apache.org.
Cleaned up test to use cgroups::memory::limit_in_bytes
Review: https://reviews.apache.org/r/20138
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ce09d171
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ce09d171
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ce09d171
Branch: refs/heads/master
Commit: ce09d171f6b40218b7ca72a220424fed10db39ff
Parents: 326aa49
Author: Ian Downes <id...@twitter.com>
Authored: Tue Apr 8 15:06:59 2014 -0700
Committer: Ian Downes <id...@twitter.com>
Committed: Fri Jun 20 16:54:52 2014 -0700
----------------------------------------------------------------------
src/tests/cgroups_tests.cpp | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/ce09d171/src/tests/cgroups_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cgroups_tests.cpp b/src/tests/cgroups_tests.cpp
index 815a266..01cf498 100644
--- a/src/tests/cgroups_tests.cpp
+++ b/src/tests/cgroups_tests.cpp
@@ -516,12 +516,8 @@ TEST_F(CgroupsAnyHierarchyWithCpuMemoryTest, ROOT_CGROUPS_Listen)
hierarchy, TEST_CGROUPS_ROOT));
// Limit the memory usage of the test cgroup to 64MB.
- size_t limit = 1024 * 1024 * 64;
- ASSERT_SOME(cgroups::write(
- hierarchy,
- TEST_CGROUPS_ROOT,
- "memory.limit_in_bytes",
- stringify(limit)));
+ ASSERT_SOME(cgroups::memory::limit_in_bytes(
+ hierarchy, TEST_CGROUPS_ROOT, Megabytes(64)));
// Listen on oom events for test cgroup.
Future<Nothing> future =