You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/09/19 07:47:59 UTC

svn commit: r1387457 - in /incubator/mesos/trunk/src: examples/balloon_executor.cpp tests/cgroups_tests.cpp tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh

Author: benh
Date: Wed Sep 19 05:47:58 2012
New Revision: 1387457

URL: http://svn.apache.org/viewvc?rev=1387457&view=rev
Log:
Made some cgroups tests more robust (liberal) to account for modern
Linux kernels that make memory "blow up" harder to test (contributed
by Jie Yu, https://reviews.apache.org/r/6867).

Modified:
    incubator/mesos/trunk/src/examples/balloon_executor.cpp
    incubator/mesos/trunk/src/tests/cgroups_tests.cpp
    incubator/mesos/trunk/src/tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh

Modified: incubator/mesos/trunk/src/examples/balloon_executor.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/examples/balloon_executor.cpp?rev=1387457&r1=1387456&r2=1387457&view=diff
==============================================================================
--- incubator/mesos/trunk/src/examples/balloon_executor.cpp (original)
+++ incubator/mesos/trunk/src/examples/balloon_executor.cpp Wed Sep 19 05:47:58 2012
@@ -17,10 +17,14 @@
  */
 
 #include <assert.h>
+#include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
+#include <sys/mman.h>
+
 #include <iostream>
 #include <string>
 
@@ -45,17 +49,27 @@ static void balloon(size_t limit)
     std::cout << "Increasing memory footprint by "
               << BALLOON_STEP_MB << " MB" << std::endl;
 
-    // Allocate virtual memory.
-    char* buffer = (char *)malloc(chunk);
-
-    // We use memset here so that the memory actually gets paged in. However,
-    // the memory may get paged out again depending on the OS page replacement
-    // algorithm. Therefore, to ensure X MB of memory is actually used, we need
-    // to pass Y (Y > X) to this function.
-    ::memset(buffer, 1, chunk);
+    // Allocate page aligned virtual memory.
+    char* buffer = NULL;
+    if (posix_memalign((void**) &buffer, getpagesize(), chunk) != 0) {
+      perror("Failed to allocate page aligned memory, posix_memalign");
+      abort();
+    }
+
+    // We use mlock and memset here to make sure that the memory
+    // actually gets paged in and thus accounted for.
+    if (mlock(buffer, chunk) != 0) {
+      perror("Failed to lock memory, mlock");
+      abort();
+    }
+
+    if (memset(buffer, 1, chunk) != 0) {
+      perror("Failed to fill memory, memset");
+      abort();
+    }
 
     // Try not to increase the memory footprint too fast.
-    ::sleep(1);
+    sleep(1);
   }
 }
 

Modified: incubator/mesos/trunk/src/tests/cgroups_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/cgroups_tests.cpp?rev=1387457&r1=1387456&r2=1387457&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/cgroups_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/cgroups_tests.cpp Wed Sep 19 05:47:58 2012
@@ -17,10 +17,13 @@
  */
 
 #include <assert.h>
+#include <errno.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
+#include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
@@ -411,10 +414,21 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_ListenE
 
     // Blow up the memory.
     size_t limit = 1024 * 1024 * 512;
-    char* ptr = (char*) ::malloc(limit);
-    assert(ptr != NULL);
-    for (size_t i = 0; i < limit; i++) {
-      ptr[i] = '\1';
+    char* ptr = NULL;
+
+    if (posix_memalign((void**) &ptr, getpagesize(), limit) != 0) {
+      FAIL() << "Failed to allocate page-aligned memory, posix_memalign: "
+             << strerror(errno);
+    }
+
+    // We use mlock and memset here to make sure that the memory
+    // actually gets paged in and thus accounted for.
+    if (mlock(ptr, limit) != 0) {
+      FAIL() << "Failed to lock memory, mlock: " << strerror(errno);
+    }
+
+    if (memset(ptr, 1, limit) != 0) {
+      FAIL() << "Failed to fill memory, memset: " << strerror(errno);
     }
 
     // Should not reach here.

Modified: incubator/mesos/trunk/src/tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh?rev=1387457&r1=1387456&r2=1387457&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh (original)
+++ incubator/mesos/trunk/src/tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh Wed Sep 19 05:47:58 2012
@@ -59,8 +59,11 @@ kill $MASTER_PID
 sleep 2
 
 # Cleanup the cgroups hierarchy root
-rmdir /cgroups/*
-umount /cgroups
+find /cgroups/* -depth -type d | xargs rmdir
+NUM_CGROUPS=`find /cgroups/* -depth -type d | wc -l`
+if [[ $NUM_CGROUPS -eq 0 ]]; then
+  umount /cgroups
+fi
 
 echo "Exiting"
 # Check whether balloon framework returned the right code