Repository: mesos
Updated Branches:
  refs/heads/master 64cf98e02 -> f4d8dc345


Fixed cgroups oom killer and memory pressure tests on Ubuntu 14.04.

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


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

Branch: refs/heads/master
Commit: f4d8dc34580469116831943025dec7c69c0e0cc0
Parents: 64cf98e
Author: Artem Harutyunyan <[email protected]>
Authored: Sat Aug 1 15:58:54 2015 -0700
Committer: Benjamin Hindman <[email protected]>
Committed: Sat Aug 1 15:59:28 2015 -0700

----------------------------------------------------------------------
 src/tests/containerizer/cgroups_tests.cpp      | 25 ++++++++++++++++-----
 src/tests/containerizer/memory_test_helper.cpp | 19 +++++++++-------
 2 files changed, 31 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f4d8dc34/src/tests/containerizer/cgroups_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/cgroups_tests.cpp 
b/src/tests/containerizer/cgroups_tests.cpp
index ea54ab8..0b171ee 100644
--- a/src/tests/containerizer/cgroups_tests.cpp
+++ b/src/tests/containerizer/cgroups_tests.cpp
@@ -1070,7 +1070,7 @@ protected:
 };
 
 
-TEST_F(CgroupsAnyHierarchyMemoryPressureTest, ROOT_IncreaseUnlockedRSS)
+TEST_F(CgroupsAnyHierarchyMemoryPressureTest, ROOT_IncreaseRSS)
 {
   MemoryTestHelper helper;
   ASSERT_SOME(helper.spawn());
@@ -1096,10 +1096,13 @@ TEST_F(CgroupsAnyHierarchyMemoryPressureTest, 
ROOT_IncreaseUnlockedRSS)
 
   // Use a guard to error out if it's been too long.
   // TODO(chzhcn): Use a better way to set testing time limit.
-  uint64_t iterationLimit = limit.bytes() / getpagesize() * 10;
-
-  for (uint64_t i = 0; i < iterationLimit; i++) {
-    EXPECT_SOME(helper.increaseRSS(getpagesize()));
+  uint64_t iterationLimit = (limit.bytes() / getpagesize()) * 10;
+  uint64_t i = 0;
+  bool stable = true;
+  while (i < iterationLimit) {
+    if (stable) {
+      EXPECT_SOME(helper.increaseRSS(getpagesize()));
+    }
 
     Future<uint64_t> _low = counters[Level::LOW]->value();
     Future<uint64_t> _medium = counters[Level::MEDIUM]->value();
@@ -1131,6 +1134,18 @@ TEST_F(CgroupsAnyHierarchyMemoryPressureTest, 
ROOT_IncreaseUnlockedRSS)
         EXPECT_EQ(0u, medium);
         EXPECT_EQ(0u, critical);
       }
+
+      // Counters are stable. Increment iteration count.
+      ++i;
+      stable = true;
+    } else {
+      // Counters appear to be unstable. Set the flag to avoid
+      // increasing the loop counter and calling increaseRSS()
+      // because at this point it is likely to return a failure.
+      // The counters should stabilize once we read them again at the
+      // next iteratrion (see comment above), so this should never
+      // cause an infinite loop.
+      stable = false;
     }
 
     previousLow = low;

http://git-wip-us.apache.org/repos/asf/mesos/blob/f4d8dc34/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 48a3563..5e40b74 100644
--- a/src/tests/containerizer/memory_test_helper.cpp
+++ b/src/tests/containerizer/memory_test_helper.cpp
@@ -72,23 +72,26 @@ const char INCREASE_PAGE_CACHE[] = "INCREASE_PAGE_CACHE";
 
 
 // This helper allocates and locks specified anonymous memory (RSS).
-// It uses mlock and memset to make sure allocated memory is mapped.
-static Try<void*> allocateRSS(const Bytes& size, bool lock = true)
+// It uses mlockall() and memset() to make sure allocated memory is
+// mapped.
+static Try<void*> allocateRSS(const Bytes& size)
 {
   void* rss = NULL;
 
+  // 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.
+  if (mlockall(MCL_FUTURE) != 0) {
+    return ErrnoError("Failed to make pages to be mapped unevictable");
+  }
+
   if (posix_memalign(&rss, getpagesize(), size.bytes()) != 0) {
     return ErrnoError("Failed to increase RSS memory, posix_memalign");
   }
 
-  // Use memset to actually page in the memory in the kernel.
+  // Use memset to map pages into the memory space of this process.
   memset(rss, 1, size.bytes());
 
-  // Locking a page makes it unevictable in the kernel.
-  if (lock && mlock(rss, size.bytes()) != 0) {
-    return ErrnoError("Failed to lock memory, mlock");
-  }
-
   return rss;
 }
 

Reply via email to