Repository: mesos Updated Branches: refs/heads/master 5d3093a39 -> 24cb10a2d
Set memory::limit_in_bytes first, even with limitSwap enabled. Review: https://reviews.apache.org/r/28305 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/24cb10a2 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/24cb10a2 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/24cb10a2 Branch: refs/heads/master Commit: 24cb10a2d68df48340ad8bc1bf148bae6e0b0171 Parents: 5d3093a Author: Ian Downes <[email protected]> Authored: Thu Nov 20 16:36:26 2014 -0800 Committer: Ian Downes <[email protected]> Committed: Fri Nov 21 11:20:44 2014 -0800 ---------------------------------------------------------------------- .../containerizer/isolators/cgroups/mem.cpp | 89 +++++++------------- 1 file changed, 29 insertions(+), 60 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/24cb10a2/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 3a3ac40..71f4b9b 100644 --- a/src/slave/containerizer/isolators/cgroups/mem.cpp +++ b/src/slave/containerizer/isolators/cgroups/mem.cpp @@ -324,32 +324,14 @@ Future<Nothing> CgroupsMemIsolatorProcess::update( << " for container " << containerId; // Read the existing limit. - Bytes currentLimit; + Try<Bytes> currentLimit = + cgroups::memory::limit_in_bytes(hierarchy, info->cgroup); - if (limitSwap) { - Result<Bytes> _currentLimit = - cgroups::memory::memsw_limit_in_bytes(hierarchy, info->cgroup); - - if (_currentLimit.isError()) { - return Failure( - "Failed to read 'memory.memsw.limit_in_bytes': " + - _currentLimit.error()); - } else if (_currentLimit.isNone()) { - return Failure("'memory.memsw.limit_in_bytes' is not available"); - } - - currentLimit = _currentLimit.get(); - } else { - Try<Bytes> _currentLimit = - cgroups::memory::limit_in_bytes(hierarchy, info->cgroup); - - if (_currentLimit.isError()) { - return Failure( - "Failed to read 'memory.limit_in_bytes': " + - _currentLimit.error()); - } - - currentLimit = _currentLimit.get(); + // NOTE: If limitSwap is (has been) used then both limit_in_bytes + // and memsw.limit_in_bytes will always be set to the same value. + if (currentLimit.isError()) { + return Failure( + "Failed to read 'memory.limit_in_bytes': " + currentLimit.error()); } // Determine whether to set the hard limit. If this is the first @@ -362,7 +344,20 @@ Future<Nothing> CgroupsMemIsolatorProcess::update( // TODO(benh): Introduce a MemoryWatcherProcess which monitors the // discrepancy between usage and soft limit and introduces a "manual // oom" if necessary. - if (info->pid.isNone() || limit > currentLimit) { + if (info->pid.isNone() || limit > currentLimit.get()) { + // We always set limit_in_bytes first and optionally set + // memsw.limit_in_bytes if limitSwap is true. + Try<Nothing> write = cgroups::memory::limit_in_bytes( + hierarchy, info->cgroup, limit); + + if (write.isError()) { + return Failure( + "Failed to set 'memory.limit_in_bytes': " + write.error()); + } + + LOG(INFO) << "Updated 'memory.limit_in_bytes' to " << limit + << " for container " << containerId; + if (limitSwap) { Try<bool> write = cgroups::memory::memsw_limit_in_bytes( hierarchy, info->cgroup, limit); @@ -370,23 +365,10 @@ Future<Nothing> CgroupsMemIsolatorProcess::update( if (write.isError()) { return Failure( "Failed to set 'memory.memsw.limit_in_bytes': " + write.error()); - } else if (!write.get()) { - return Failure("'memory.memsw.limit_in_bytes' is not available"); } LOG(INFO) << "Updated 'memory.memsw.limit_in_bytes' to " << limit << " for container " << containerId; - } else { - Try<Nothing> write = cgroups::memory::limit_in_bytes( - hierarchy, info->cgroup, limit); - - if (write.isError()) { - return Failure( - "Failed to set 'memory.limit_in_bytes': " + write.error()); - } - - LOG(INFO) << "Updated 'memory.limit_in_bytes' to " << limit - << " for container " << containerId; } } @@ -557,28 +539,15 @@ void CgroupsMemIsolatorProcess::oom(const ContainerID& containerId) message << "Memory limit exceeded: "; // Output the requested memory limit. - if (limitSwap) { - Result<Bytes> limit = - cgroups::memory::memsw_limit_in_bytes(hierarchy, info->cgroup); - - if (limit.isError()) { - LOG(ERROR) << "Failed to read 'memory.memsw.limit_in_bytes': " - << limit.error(); - } else if (limit.isNone()) { - LOG(ERROR) << "'memory.memsw.limit_in_bytes' is not available"; - } else { - message << "Requested: " << limit.get() << " "; - } + // NOTE: If limitSwap is (has been) used then both limit_in_bytes + // and memsw.limit_in_bytes will always be set to the same value. + Try<Bytes> limit = cgroups::memory::limit_in_bytes(hierarchy, info->cgroup); + + if (limit.isError()) { + LOG(ERROR) << "Failed to read 'memory.limit_in_bytes': " + << limit.error(); } else { - Try<Bytes> limit = - cgroups::memory::limit_in_bytes(hierarchy, info->cgroup); - - if (limit.isError()) { - LOG(ERROR) << "Failed to read 'memory.limit_in_bytes': " - << limit.error(); - } else { - message << "Requested: " << limit.get() << " "; - } + message << "Requested: " << limit.get() << " "; } // Output the maximum memory usage.
