Skip to content

Commit

Permalink
Skip madvise calls on tiny inner files of compound files. (apache#13917)
Browse files Browse the repository at this point in the history
This commit skips `madvise` calls on inner files of compound files that are
smaller than the page size.
  • Loading branch information
jpountz authored Oct 15, 2024
1 parent 5fd4525 commit f69b196
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,20 @@ public final MemorySegmentIndexInput slice(
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;
}
Expand Down

0 comments on commit f69b196

Please sign in to comment.