Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Kernel Samepage Merging support (Linux)
authorGabriel Corona <gabriel.corona@loria.fr>
Thu, 27 Mar 2014 15:53:27 +0000 (16:53 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 28 Mar 2014 09:32:30 +0000 (10:32 +0100)
Add MADV_MERGEABLE advice (madvise) for KSM in the heaps and
read/write segments: mark these regions of memory as candidate for
KSM. As the stacks are stored on the heap, they are candidate for KSM
as well.

In order to work, KSM must be enabled on the system (by root):

    # Enable:
    echo 1 > /sys/kernel/mm/ksm/run
    # Do some real work:
    echo 10000 > /sys/kernel/mm/ksm/pages_to_scan

See Documentation/vm/ksm.txt:

  https://www.kernel.org/doc/Documentation/vm/ksm.txt

We would like to only mark the .data+.bss and not the other sections
of the segment.

src/mc/mc_global.c
src/xbt/mmalloc/mmorecore.c

index 0457aa9..55cf908 100644 (file)
@@ -8,6 +8,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/time.h>
+#include <sys/mman.h>
 #include <libgen.h>
 
 #include "simgrid/sg_config.h"
@@ -799,6 +800,14 @@ static void MC_init_debug_info(void) {
   mc_libsimgrid_info = MC_find_object_info(maps, libsimgrid_path, 0);
   mc_object_infos[1] = mc_libsimgrid_info;
 
+#ifdef MADV_MERGEABLE
+  for(int i=0; i!=mc_object_infos_size; ++i) {
+    void* start = mc_object_infos[i]->start_rw;
+    void* end = mc_object_infos[i]->end_rw;
+    madvise(start, (char*)end - (char*)start, MADV_MERGEABLE);
+  }
+#endif
+
   // Use information of the other objects:
   MC_post_process_object_info(mc_binary_info);
   MC_post_process_object_info(mc_libsimgrid_info);
index 014b8b8..74ed341 100644 (file)
@@ -123,6 +123,10 @@ void *mmorecore(struct mdesc *mdp, ssize_t size)
         abort();
       }
 
+#ifdef MADV_MERGEABLE
+      madvise(mapto, mapbytes, MADV_MERGEABLE);
+#endif
+
       if (mdp->top == 0)
         mdp->base = mdp->breakval = mapto;