mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-10-05 21:22:39 +02:00
(uring) Fall back to simple I/O planning behavior when buffered mode is selected in UringFileReader
This commit is contained in:
@@ -8,6 +8,7 @@ import nu.marginalia.ffi.LinuxSystemCalls;
|
||||
import java.io.IOException;
|
||||
import java.lang.foreign.Arena;
|
||||
import java.lang.foreign.MemorySegment;
|
||||
import java.lang.foreign.SegmentAllocator;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -71,6 +72,35 @@ public class UringFileReader implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
public List<MemorySegment> readUnaligned(Arena arena, long[] offsets, int[] sizes, int blockSize) {
|
||||
if (direct) {
|
||||
return readUnalignedInDirectMode(arena, offsets, sizes, blockSize);
|
||||
} else {
|
||||
return readUnalignedInBufferedMode(arena, offsets, sizes);
|
||||
}
|
||||
}
|
||||
|
||||
private List<MemorySegment> readUnalignedInBufferedMode(Arena arena, long[] offsets, int[] sizes) {
|
||||
int totalSize = 0;
|
||||
for (int size : sizes) {
|
||||
totalSize += size;
|
||||
}
|
||||
|
||||
var allocator = SegmentAllocator.slicingAllocator(arena.allocate(totalSize));
|
||||
|
||||
List<MemorySegment> segmentsList = new ArrayList<>(sizes.length);
|
||||
List<Long> offsetsList = new ArrayList<>(sizes.length);
|
||||
|
||||
for (int i = 0; i < sizes.length; i++) {
|
||||
segmentsList.add(allocator.allocate(sizes[i]));
|
||||
offsetsList.add(offsets[i]);
|
||||
}
|
||||
|
||||
read(segmentsList, offsetsList);
|
||||
|
||||
return segmentsList;
|
||||
}
|
||||
|
||||
/** This function takes a list of offsets and sizes, and translates them to a minium of blockSize'd O_DIRECT
|
||||
* reads. A single buffer will be allocated to hold all the data, to encourage HugePages allocation and
|
||||
* reduce TLB thrashing. It is still generally helpful for performance if the data is at least best-effort
|
||||
|
Reference in New Issue
Block a user