ChrisHegarty commented on code in PR #13196: URL: https://github.com/apache/lucene/pull/13196#discussion_r1534598790
########## lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInputProvider.java: ########## @@ -92,10 +110,19 @@ private final MemorySegment[] map( } if (preload) { segment.load(); + } else if (segSize > 0L && advice.isPresent()) { // not when preloading! + nativeAccess.madvise(segment, advice.getAsInt()); } segments[segNr] = segment; startOffset += segSize; } return segments; } + + private OptionalInt mapContextToMadvise(IOContext context) { + if (context.readOnce || context.context == Context.MERGE) { + return OptionalInt.of(NativeAccess.POSIX_MADV_SEQUENTIAL); + } Review Comment: I'd like to plumb `POSIX_MADV_RANDOM`, for use when reading from flat vector data. Any objection do doing it in this PR, or you wanna wait to get this in first? ########## lucene/core/src/java21/org/apache/lucene/store/PosixNativeAccess.java: ########## @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.store; + +import java.io.IOException; +import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Linker; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SymbolLookup; +import java.lang.foreign.ValueLayout; +import java.lang.invoke.MethodHandle; +import java.util.Locale; +import java.util.logging.Logger; + +@SuppressWarnings("preview") +final class PosixNativeAccess extends NativeAccess { + + private static final Logger LOG = Logger.getLogger(PosixNativeAccess.class.getName()); + + private final MethodHandle mh$posix_madvise; Review Comment: we should probably make this MethodHandle `static final`. In which case the whole instance construction can be cleaned up a bit. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org