Apache Lucene open-source search software
Skip madvise calls on tiny inner files of compound files. (#13917)
Adrien Grandf69b196ef29f
diff --git a/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java b/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.javaindex db6d19b0a7f..70fc1eb9488 100644--- a/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java+++ b/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java@@ -570,12 +570,20 @@ abstract class MemorySegmentIndexInput extends IndexInputif (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;}