Skip to content

Commit

Permalink
use MAP_POPULATE on Linux if -ql
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Sep 23, 2024
1 parent af86e27 commit 8af1b0d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion vmtouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ void vmtouch_file(char *path) {
int i;
int res;
int open_flags;
int mmap_flags = MAP_SHARED;

retry_open:

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8af1b0d

Please sign in to comment.