diff --git a/vmtouch.c b/vmtouch.c index 8accef3..55ae8fb 100644 --- a/vmtouch.c +++ b/vmtouch.c @@ -169,7 +169,11 @@ void usage() { printf("Usage: vmtouch [OPTIONS] ... FILES OR DIRECTORIES ...\n\nOptions:\n"); printf(" -t touch pages into memory\n"); printf(" -e evict pages from memory\n"); +#if defined(__linux__) + printf(" -l lock pages in physical memory with mlock2(2)\n"); +#else printf(" -l lock pages in physical memory with mlock(2)\n"); +#endif printf(" -L lock pages in physical memory with mlockall(2)\n"); printf(" -d daemon mode\n"); printf(" -m max file size to touch\n"); @@ -614,6 +618,13 @@ void vmtouch_file(char *path) { char *mincore_array = malloc(pages_in_range); if (mincore_array == NULL) fatal("Failed to allocate memory for mincore array (%s)", strerror(errno)); +#if defined(__linux__) + if (o_lock) { + if (mlock2(mem, len_of_range, MLOCK_ONFAULT)) + fatal("mlock2: %s (%s)", path, strerror(errno)); + } +#endif + // 3rd arg to mincore is char* on BSD and unsigned char* on linux if (mincore(mem, len_of_range, (void*)mincore_array)) fatal("mincore %s (%s)", path, strerror(errno)); for (i=0; i