Skip madvise calls on tiny inner files of compound files. (#13917)

This commit skips `madvise` calls on inner files of compound files that are
smaller than the page size.
This commit is contained in:
Adrien Grand 2024-10-15 16:17:51 +02:00 committed by GitHub
parent 5fd45254d3
commit f69b196ef2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 6 deletions

View File

@ -570,12 +570,20 @@ abstract class MemorySegmentIndexInput extends IndexInput
if (NATIVE_ACCESS.isPresent() && advice != ReadAdvice.NORMAL) {
// No need to madvise with a normal advice, since it's the OS' default.
final NativeAccess nativeAccess = NATIVE_ACCESS.get();
slice.advise(
0,
slice.length,
segment -> {
nativeAccess.madvise(segment, advice);
});
if (length >= nativeAccess.getPageSize()) {
// Only set the read advice if the inner file is large enough. Otherwise the cons are likely
// outweighing the pros as we're:
// - potentially overriding the advice of other files that share the same pages,
// - paying the cost of a madvise system call for little value.
// We could align inner files with the page size to avoid the first issue, but again the
// pros don't clearly overweigh the cons.
slice.advise(
0,
slice.length,
segment -> {
nativeAccess.madvise(segment, advice);
});
}
}
return slice;
}