vmtouch
vmtouch copied to clipboard
consider using madvise
I wonder if using madvise() sycall (where supported) might be beneficial, especially with the MADV_WILLNEED flag to trigger read-ahead/prefetch.
Really good question... I believe that WILLNEED doesn't actually read in the whole range, it just triggers the normal readahead mechanism. That said, it wouldn't surprise me if there is some benefit especially if combined with MADV_SEQUENTIAL to increase the readahead amount.
Definitely worth experimenting with, thanks for the suggestion!
MADV_SEQUENTIAL could be counter-productive as it might free the pages as they are accessed, at least this is what Linux claims in the man page:
Expect page references in sequential order. (Hence, pages in
the given range can be aggressively read ahead, and may be freed
soon after they are accessed.)
Hard to tell what will happen if MADV_SEQUENTIAL is used together with mlockall().
Yes that's a good point.. I've been thinking about an interface for madvise that lets the user decide, maybe something like "vmtouch -a sequential,willneed my-file.dat"