memmap-rs icon indicating copy to clipboard operation
memmap-rs copied to clipboard

Support madvise.

Open m-ou-se opened this issue 7 years ago • 4 comments

It might be useful to add support for POSIX madvise, and/or something like CreateFile with FILE_FLAG_SEQUENTIAL_SCAN on Windows.

Is this something within the scope of this crate? Or is this be something to be left to another crate?

m-ou-se avatar Jul 30 '18 06:07 m-ou-se

On Windows, you can also do something similar to POSIX's WILLNEED using the PrefetchVirtualMemory syscall.

KodrAus avatar Jul 30 '18 07:07 KodrAus

In some other cases the passive or infrequently-engaging maintainer(s) of this crate have suggested publishing new functionality elsewhere, in other crates. I've included support for a subset of libc::posix_madvise in the olio crate via olio::mem::MemHandle in a concurrent-access aware fashion. See unit tests in the source for examples wrapping an Mmap. Benchmarks show performance win of Sequential advice proceeding sequential access.

While this is currently limited to *nix, I would welcome a patch for Sequential advice on Windows. See https://github.com/dekellum/olio

dekellum avatar Aug 15 '18 22:08 dekellum

Right, my take in the past has been that madvise should probably be provided by a separate crate. The non-cross-platform aspects of it make it a tough API to wrap.

That being said if someone can make the case that madvise is only useful in combination with memory-mapped memory then I'm open to including it in memmap.

danburkert avatar Sep 20 '18 00:09 danburkert

madvise could be implemented as a no-op on all platforms where it isn't supported.

fogti avatar Jan 04 '19 22:01 fogti