danburkert / memmap-rs

cross-platform Rust API for memory mapped IO
Apache License 2.0
540 stars 159 forks source link

Support madvise. #68

Open m-ou-se opened 6 years ago

m-ou-se commented 6 years ago

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?

KodrAus commented 6 years ago

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

dekellum commented 6 years ago

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

danburkert commented 6 years ago

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.

fogti commented 5 years ago

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