From: Gabriel Corona Date: Thu, 27 Mar 2014 15:53:27 +0000 (+0100) Subject: [mc] Kernel Samepage Merging support (Linux) X-Git-Tag: v3_11~189^2~16 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0d1dd360cb78fd7553037145656807a7e6d2274a [mc] Kernel Samepage Merging support (Linux) 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. --- diff --git a/src/mc/mc_global.c b/src/mc/mc_global.c index 0457aa97c7..55cf9088ca 100644 --- a/src/mc/mc_global.c +++ b/src/mc/mc_global.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #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); diff --git a/src/xbt/mmalloc/mmorecore.c b/src/xbt/mmalloc/mmorecore.c index 014b8b81c2..74ed341050 100644 --- a/src/xbt/mmalloc/mmorecore.c +++ b/src/xbt/mmalloc/mmorecore.c @@ -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;