Skip to content

Commit 8af1b0d

Browse files
committed
use MAP_POPULATE on Linux if -ql
1 parent af86e27 commit 8af1b0d

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

vmtouch.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ void vmtouch_file(char *path) {
504504
int i;
505505
int res;
506506
int open_flags;
507+
int mmap_flags = MAP_SHARED;
507508

508509
retry_open:
509510

@@ -572,13 +573,27 @@ void vmtouch_file(char *path) {
572573
len_of_range = len_of_file - offset;
573574
}
574575

575-
mem = mmap(NULL, len_of_range, PROT_READ, MAP_SHARED, fd, offset);
576+
#ifdef __linux__
577+
if (o_lock && o_quiet) {
578+
if (mlockall(MCL_FUTURE))
579+
fatal("mlockall: %s (%s)", path, strerror(errno));
580+
mmap_flags |= MAP_POPULATE;
581+
}
582+
#endif
583+
584+
mem = mmap(NULL, len_of_range, PROT_READ, mmap_flags, fd, offset);
576585

577586
if (mem == MAP_FAILED) {
578587
warning("unable to mmap file %s (%s), skipping", path, strerror(errno));
579588
goto bail;
580589
}
581590

591+
#ifdef __linux__
592+
if (o_lock && !o_quiet) {
593+
goto bail;
594+
}
595+
#endif
596+
582597
if (!aligned_p(mem)) fatal("mmap(%s) wasn't page aligned", path);
583598

584599
pages_in_range = bytes2pages(len_of_range);

0 commit comments

Comments
 (0)