Fix: Fall back when O_NOATIME is denied opening memory-mapped files on Linux - #784
Merged
ashvardanian merged 1 commit intoAug 29, 2026
Conversation
ashvardanian
pushed a commit
that referenced
this pull request
Aug 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Allow unprivileged Linux processes to memory-map readable USearch index files owned by another user.
On Linux,
memory_mapped_file_topens files withO_RDONLY | O_NOATIME. Theopen(2)documentation specifies thatO_NOATIMErequires either a matching effective UID orCAP_FOWNER; otherwise,openfails withEPERM, even when the file’s normal permissions allow it to be read.We encountered this issue when an unprivileged process attempted to read a world-readable index owned by
root. The failure appeared instraceas:There was no subsequent attempt to open the file without
O_NOATIME, so USearch could not map the index.This change retries the open with
O_RDONLYwhen theO_NOATIMEattempt fails withEPERM. This preserves the no-atime optimization where permitted while falling back to normal read permissions otherwise. Other errors and non-Linux platforms remain unaffected.Similar fixes in other projects
Other projects use the same retry-on-
EPERMfallback, or an equivalent approach, for the same reason:[hw/9pfs/9p-util.h#L176](https://github.com/qemu/qemu/blob/master/hw/9pfs/9p-util.h#L176)[fs/overlayfs/util.c#L681](https://github.com/torvalds/linux/blob/master/fs/overlayfs/util.c#L681)[vmtouch.c#L518](https://github.com/hoytech/vmtouch/blob/master/vmtouch.c#L518)Validation
cppcheckpasses.