From 8af1b0d81826ed29eecf087b347e71d8e3947c4b Mon Sep 17 00:00:00 2001 From: Dima Krasner Date: Mon, 23 Sep 2024 08:43:13 +0300 Subject: [PATCH] use MAP_POPULATE on Linux if -ql --- vmtouch.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/vmtouch.c b/vmtouch.c index dade9b7..fee4c2c 100644 --- a/vmtouch.c +++ b/vmtouch.c @@ -504,6 +504,7 @@ void vmtouch_file(char *path) { int i; int res; int open_flags; + int mmap_flags = MAP_SHARED; retry_open: @@ -572,13 +573,27 @@ void vmtouch_file(char *path) { len_of_range = len_of_file - offset; } - mem = mmap(NULL, len_of_range, PROT_READ, MAP_SHARED, fd, offset); +#ifdef __linux__ + if (o_lock && o_quiet) { + if (mlockall(MCL_FUTURE)) + fatal("mlockall: %s (%s)", path, strerror(errno)); + mmap_flags |= MAP_POPULATE; + } +#endif + + mem = mmap(NULL, len_of_range, PROT_READ, mmap_flags, fd, offset); if (mem == MAP_FAILED) { warning("unable to mmap file %s (%s), skipping", path, strerror(errno)); goto bail; } +#ifdef __linux__ + if (o_lock && !o_quiet) { + goto bail; + } +#endif + if (!aligned_p(mem)) fatal("mmap(%s) wasn't page aligned", path); pages_in_range = bytes2pages(len_of_range);