Repository: mesos Updated Branches: refs/heads/master 7f352ef88 -> 348fabbbf
Fixed MemIsolatorTest failures on OS X. Review: https://reviews.apache.org/r/37065 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/348fabbb Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/348fabbb Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/348fabbb Branch: refs/heads/master Commit: 348fabbbfcf5dee0720959833cbf6db6290bfc7e Parents: 7f352ef Author: Artem Harutyunyan <[email protected]> Authored: Thu Aug 6 14:33:27 2015 -0700 Committer: Michael Park <[email protected]> Committed: Thu Aug 6 15:54:46 2015 -0700 ---------------------------------------------------------------------- src/tests/containerizer/memory_test_helper.cpp | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/348fabbb/src/tests/containerizer/memory_test_helper.cpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/memory_test_helper.cpp b/src/tests/containerizer/memory_test_helper.cpp index 5e40b74..04dcc4b 100644 --- a/src/tests/containerizer/memory_test_helper.cpp +++ b/src/tests/containerizer/memory_test_helper.cpp @@ -71,20 +71,20 @@ const char INCREASE_RSS[] = "INCREASE_RSS"; const char INCREASE_PAGE_CACHE[] = "INCREASE_PAGE_CACHE"; -// This helper allocates and locks specified anonymous memory (RSS). -// It uses mlockall() and memset() to make sure allocated memory is -// mapped. +// This helper allocates memory and prevents the compiler from +// optimizing that allocation away by locking the allocated pages. static Try<void*> allocateRSS(const Bytes& size) { - void* rss = NULL; - +#ifndef __APPLE__ // Make sure that all pages that are going to be mapped into the // address space of this process become unevictable. This is needed - // for testing cgroup oom killer. + // for testing cgroups OOM killer. if (mlockall(MCL_FUTURE) != 0) { return ErrnoError("Failed to make pages to be mapped unevictable"); } +#endif + void* rss = NULL; if (posix_memalign(&rss, getpagesize(), size.bytes()) != 0) { return ErrnoError("Failed to increase RSS memory, posix_memalign"); } @@ -92,6 +92,16 @@ static Try<void*> allocateRSS(const Bytes& size) // Use memset to map pages into the memory space of this process. memset(rss, 1, size.bytes()); +#ifdef __APPLE__ + // Locking a page makes it unevictable in the kernel. This is needed + // for testing cgroups OOM killer. + // NOTE: We use 'mlock' here because 'mlockall' is left + // unimplemented on OS X. + if (mlock(rss, size.bytes()) != 0) { + return ErrnoError("Failed to make mapped pages unevictable"); + } +#endif + return rss; }
