vmtouch icon indicating copy to clipboard operation
vmtouch copied to clipboard

consider using madvise

Open vladak opened this issue 9 years ago • 3 comments

I wonder if using madvise() sycall (where supported) might be beneficial, especially with the MADV_WILLNEED flag to trigger read-ahead/prefetch.

vladak avatar Jul 04 '16 13:07 vladak

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!

hoytech avatar Jul 10 '16 14:07 hoytech

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().

vladak avatar Jul 10 '16 14:07 vladak

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"

hoytech avatar Jul 10 '16 17:07 hoytech