Skip to content

Add POSIX madvise support and a closeable MappableByteBuffer API to improve mmap-based blob cache access with explicit prefetching#140371

Merged
ChrisHegarty merged 38 commits intoelastic:mainfrom
jimczi:posix_madvise_access
Jan 15, 2026
Merged

Add POSIX madvise support and a closeable MappableByteBuffer API to improve mmap-based blob cache access with explicit prefetching#140371
ChrisHegarty merged 38 commits intoelastic:mainfrom
jimczi:posix_madvise_access

Conversation

@jimczi
Copy link
Contributor

@jimczi jimczi commented Jan 8, 2026

This PR enhances Elasticsearch’s native mmap handling by exposing the POSIX madvise syscall via the NativeAccess interface and integrating it into core I/O paths. It introduces a Closeable MappableByteBuffer API and plugs memory access advice and prefetch support into SharedBytes and frozen index inputs, enabling more efficient control over page cache behaviour.

Add a POSIX C library accessor to NativeAccess and expose the madvise
system call through the PosixCLibrary interface. This enables providing
memory access advice for blob cache directories in cases where the mmap
directory cannot be used.
@jimczi jimczi requested a review from ChrisHegarty January 8, 2026 14:59
@jimczi jimczi requested a review from a team as a code owner January 8, 2026 14:59
@jimczi jimczi added >non-issue :Core/Infra/Core Core issues without another label labels Jan 8, 2026
@elasticsearchmachine elasticsearchmachine added v9.4.0 Team:Core/Infra Meta label for core/infra team labels Jan 8, 2026
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@ChrisHegarty ChrisHegarty requested a review from rjernst January 14, 2026 17:01
Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor things

@ChrisHegarty ChrisHegarty requested a review from rjernst January 15, 2026 10:57
Copy link
Contributor

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ChrisHegarty ChrisHegarty changed the title Expose POSIX madvise via NativeAccess for blob cache usage Use POSIX madvise via NativeAccess for blob cache usage Jan 15, 2026
@ChrisHegarty ChrisHegarty added the test-windows Trigger CI checks on Windows label Jan 15, 2026
Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will work for now. The layout is a bit complex for how to handle different systems. I think we can simplify it by getting rid of the "jdk" intermediaries since we no longer have jna. We can use MemorySegment in those apis as long as the classes with those method signatures are not exported. I'll play around with that, but this PR looks fine for now.

@ChrisHegarty ChrisHegarty changed the title Use POSIX madvise via NativeAccess for blob cache usage Add POSIX madvise support and a closeable MappableByteBuffer API to improve mmap-based blob cache access with explicit prefetching Jan 15, 2026
@ChrisHegarty ChrisHegarty merged commit cb86fe6 into elastic:main Jan 15, 2026
37 of 41 checks passed
spinscale pushed a commit to spinscale/elasticsearch that referenced this pull request Jan 21, 2026
…mprove mmap-based blob cache access with explicit prefetching (elastic#140371)

This PR enhances Elasticsearch’s native mmap handling by exposing the POSIX madvise syscall via the NativeAccess interface and integrating it into core I/O paths. It introduces a Closeable MappableByteBuffer API and plugs memory access advice and prefetch support into SharedBytes and frozen index inputs, enabling more efficient control over page cache behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team test-windows Trigger CI checks on Windows v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants