Support multiple advice
Closed this issue · 2 comments
A common pattern with mmap is to provide multiple advice at once:
madvise(addr, size, MADV_WILLNEED | MADV_SEQUENTIAL);
This is not currently possible with the Advice
implementation. Would you accept a PR overloading the Or
operator to provide equivalent functionality?
IIRC, we discussed this when the API was added and concluded that this is not backed by the API description and hence would have to use two calls to madvise
to be correct.
In this particular case, I suspect that the above is not doing what you think it does as on Linux, MADV_WILLNEED == 3
and MADV_SEQUENTIAL == 2
, so that
MADV_WILLNEED | MADV_SEQUENTIAL == MADV_WILLNEED
and the call does not actually confer the MADV_SEQUENTIAL
hint to the kernel.
Interesting. I had done a GitHub Search and assumed it was possible to combine the flags, since there were quite a few results. Apparently, this is a common misconception, but the values make it clear that the flags are not meant to be combined.
Thanks for clarifying!