Skip to content

Fix: Fall back when O_NOATIME is denied opening memory-mapped files on Linux - #784

Merged
ashvardanian merged 1 commit into
unum-cloud:main-devfrom
mertcancam:fix/linux-open-noatime-fallback
Aug 29, 2026
Merged

Fix: Fall back when O_NOATIME is denied opening memory-mapped files on Linux#784
ashvardanian merged 1 commit into
unum-cloud:main-devfrom
mertcancam:fix/linux-open-noatime-fallback

Conversation

@mertcancam

Copy link
Copy Markdown
Contributor

Summary

Allow unprivileged Linux processes to memory-map readable USearch index files owned by another user.

On Linux, memory_mapped_file_t opens files with O_RDONLY | O_NOATIME. The open(2) documentation specifies that O_NOATIME requires either a matching effective UID or CAP_FOWNER; otherwise, open fails with EPERM, 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 in strace as:

openat(..., "x-vectors.usearch", O_RDONLY|O_NOATIME) = -1 EPERM (Operation not permitted)

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_RDONLY when the O_NOATIME attempt fails with EPERM. 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-EPERM fallback, or an equivalent approach, for the same reason:

Validation

  • Full C++ test suite passes.
  • cppcheck passes.

@ashvardanian
ashvardanian merged commit d532fb3 into unum-cloud:main-dev Aug 29, 2026
29 checks passed
ashvardanian pushed a commit that referenced this pull request Aug 31, 2026
### Patch

- Improve: Native enums and PEP 604 unions (a1ca7c3)
- Make: Ship a Python source distribution (d921aef)
- Fix: Retry Linux file mapping without `O_NOATIME` #784 (d532fb3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants