diff options
| author | Ankur Arora <ankur.a.arora@oracle.com> | 2025-09-17 08:24:07 -0700 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2025-09-19 12:43:12 -0300 |
| commit | fe0f3216dd8736afc1a6ddb0b79fd24f37418357 (patch) | |
| tree | 76c528d2c0a962a32f26798cd92f4c61768a3b2b /tools/perf/bench/mem-functions.c | |
| parent | perf bench mem: Pull out init/fini logic (diff) | |
| download | linux-fe0f3216dd8736afc1a6ddb0b79fd24f37418357.tar.gz linux-fe0f3216dd8736afc1a6ddb0b79fd24f37418357.zip | |
perf bench mem: Switch from zalloc() to mmap()
Using mmap() ensures that the buffer is always aligned at a fixed
boundary. Switch to that to remove one source of variability.
Since we always want to read/write from the allocated buffers map
with pagetables pre-populated.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Raghavendra K T <raghavendra.kt@amd.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/bench/mem-functions.c')
| -rw-r--r-- | tools/perf/bench/mem-functions.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c index 60ea20277507..e97962dd8f81 100644 --- a/tools/perf/bench/mem-functions.c +++ b/tools/perf/bench/mem-functions.c @@ -22,9 +22,9 @@ #include <string.h> #include <unistd.h> #include <sys/time.h> +#include <sys/mman.h> #include <errno.h> #include <linux/time64.h> -#include <linux/zalloc.h> #define K 1024 @@ -286,16 +286,33 @@ static int do_memcpy(const struct function *r, struct bench_params *p, return 0; } +static void *bench_mmap(size_t size, bool populate) +{ + void *p; + int extra = populate ? MAP_POPULATE : 0; + + p = mmap(NULL, size, PROT_READ|PROT_WRITE, + extra | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + + return p == MAP_FAILED ? NULL : p; +} + +static void bench_munmap(void *p, size_t size) +{ + if (p) + munmap(p, size); +} + static bool mem_alloc(struct bench_mem_info *info, struct bench_params *p, void **src, void **dst) { bool failed; - *dst = zalloc(p->size); + *dst = bench_mmap(p->size, true); failed = *dst == NULL; if (info->alloc_src) { - *src = zalloc(p->size); + *src = bench_mmap(p->size, true); failed = failed || *src == NULL; } @@ -306,8 +323,8 @@ static void mem_free(struct bench_mem_info *info __maybe_unused, struct bench_params *p __maybe_unused, void **src, void **dst) { - free(*dst); - free(*src); + bench_munmap(*dst, p->size); + bench_munmap(*src, p->size); *dst = *src = NULL; } |
