Add {Advise, UncheckedAdvice}::is_supported() #122
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some Linux-specific advices are supported only on recent kernels, e.g.
MADV_POPULATE_READ
is available starting from Linux 5.14. Some long-term supported distros (e.g. RHEL 8 and Ubuntu 20.04) still have older kernels. So it would be useful to provide a way to perform a runtime check to see whether the specified advice is supported.This PR adds two similar methods
Advise::is_supported()
andUncheckedAdvice::is_supported()
. They're marked as Linux-only as:madvise(2)
.Footnotes
Tho, as for not officially documented way, I've found this approach for BSDs: https://github.com/jart/cosmopolitan/blob/3.8.0/libc/calls/madvise.c#L38-L39 ↩