Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mlock2() instead of mlock() on Linux and use mlockall(MCL_FUTURE). #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ghuls
Copy link

@ghuls ghuls commented May 4, 2022

Use mlock2() instead of mlock() on Linux:

  • mlock2() allows a third argument MLOCK_ONFAULT, which allow to
    lock the pages in a range before touching them, so mlock2()
    can be called before touching all pages instead of after.
  • "vmtouch -t -l" some_file would not keep the pages in cache
    after touching them, so at the lock() step they needed to
    be read again from disk. After this patch files are cached
    twice as fast on this system.

Use mlockall(MCL_FUTURE) instead of mlockall(MCL_CURRENT):

  • Set mlockall(MCL_FUTURE) before touching pages to have similar
    behaviour as the mlock2() approach above.

vmtouch.c Outdated
@@ -169,7 +169,7 @@ 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");
printf(" -l lock pages in physical memory with mlock(2)\n");
printf(" -l lock pages in physical memory with mlock(2) or mlock2(2)\n");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using ifndef her too? that way the usage help would clearly show which one it is using.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dope really needed this!

Use mlock2() instead of mlock() on Linux:
  - mlock2() allows a third argument MLOCK_ONFAULT, which allow to
    lock the pages in a range before touching them, so mlock2()
    can be called before touching all pages instead of after.
  - "vmtouch -t -l" some_file would not keep the pages in cache
    after touching them, so at the lock() step they needed to
    be read again from disk. After this patch files are cached
    twice as fast on this system.

Use mlockall(MCL_FUTURE) instead of mlockall(MCL_CURRENT):
  - Set mlockall(MCL_FUTURE) before touching pages to have similar
    behaviour as the mlock2() approach above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants