diff options
author | Satish Patel <satish.patel@linaro.org> | 2016-04-11 16:22:33 +0530 |
---|---|---|
committer | Satish Patel <satish.patel@linaro.org> | 2016-04-11 16:29:04 +0530 |
commit | 16808397f70b6123358a3040562d829140ca31d8 (patch) | |
tree | 1197bc9859c1f09074d6eeb628e4792b50e52943 | |
parent | 4588a53dee669952c52fade3f356aa824db1e067 (diff) | |
download | gperftools-16808397f70b6123358a3040562d829140ca31d8.tar.gz |
malloc benchmark: add touch mem
By default memory in linux will not be allocated unless it is accessed/touched.
So to run the test effectively, after every malloc code is added to touch
allocated space
Note:
We are trying to touch all pages, it might make a difference to final score,
but should be ok, when we run the same test with other implementations and
compare
Signed-off-by: Satish Patel <satish.patel@linaro.org>
-rw-r--r-- | benchmark/malloc_bench.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/benchmark/malloc_bench.cc b/benchmark/malloc_bench.cc index 0d9dc4c..7a11c87 100644 --- a/benchmark/malloc_bench.cc +++ b/benchmark/malloc_bench.cc @@ -31,6 +31,26 @@ #include "run_benchmark.h" +#if defined(__linux__) +/** + * From: http://linux.die.net/man/3/malloc + * By default, Linux follows an optimistic memory allocation strategy. This + * means that when malloc() returns non-NULL there is no guarantee that the + * memory really is available. In case it turns out that the system is out of + * memory, one or more processes will be killed by the OOM killer + * + * So, actually page will be assigned when use tries to access the same using + * allocated pointer. We are trying to touch all pages, it might make a + * difference to final score, but should be ok, when we run the same test with + * other implementations and compare. + */ +void touch_mem(char *p, int size) { + volatile char *mem=(volatile char *)p; + volatile char *end=mem+size; + for(; mem<end; mem+=4096) *mem; +} +#endif //__linux__ + static void bench_fastpath_throughput(long iterations, uintptr_t param) { @@ -40,6 +60,10 @@ static void bench_fastpath_throughput(long iterations, if (!p) { abort(); } +#if defined(__linux__) + touch_mem((char *)p, sz); +#endif //__linux__ + free(p); // this makes next iteration use different free list. So // subsequent iterations may actually overlap in time. @@ -56,6 +80,9 @@ static void bench_fastpath_dependent(long iterations, if (!p) { abort(); } +#if defined(__linux__) + touch_mem((char *)p, sz); +#endif //__linux__ free(p); // this makes next iteration depend on current iteration. But this // iteration's free may still overlap with next iteration's malloc @@ -72,6 +99,9 @@ static void bench_fastpath_simple(long iterations, if (!p) { abort(); } +#if defined(__linux__) + touch_mem((char *)p, sz); +#endif //__linux__ free(p); // next iteration will use same free list as this iteration. So it // should be prevent next iterations malloc to go too far before @@ -97,6 +127,9 @@ static void bench_fastpath_stack(long iterations, if (!p) { abort(); } +#if defined(__linux__) + touch_mem((char *)p, sz); +#endif //__linux__ stack[k] = p; // this makes next iteration depend on result of this iteration sz = ((sz | reinterpret_cast<size_t>(p)) & 511) + 16; @@ -122,6 +155,9 @@ static void bench_fastpath_stack_simple(long iterations, if (!p) { abort(); } +#if defined(__linux__) + touch_mem((char *)p, sz); +#endif //__linux__ stack[k] = p; } for (long k = 0; k < param; k++) { @@ -152,6 +188,9 @@ static void bench_fastpath_rnd_dependent(long iterations, if (!p) { abort(); } +#if defined(__linux__) + touch_mem((char *)p, sz); +#endif //__linux__ ptrs[k] = p; sz = ((sz | reinterpret_cast<size_t>(p)) & 511) + 16; } |