Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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