Hive Hive
Sign in

fix(kura): exempt the final partial page from the mmap residency gate

GitHub issue · Closed

Metadata
Source
tuist/tuist #11431
Updated
Jun 24, 2026
Domains
Kura
Details

What

map_file_region gates mmap serving on mincore residency (mapping_is_resident). It required every page queried by mincore to be resident — including the file’s final partial page, the page that extends past EOF when the file size isn’t a multiple of the page size.

This change exempts that final partial page: only pages fully backed by file data must be resident. A small pure helper, fully_backed_pages_resident, makes the rule unit-testable.

Why

On virtio-fs, mincore reports the partial past-EOF page as non-resident even when its bytes are cached. So the gate needlessly returned Ok(None) and fell back to the streaming reader for any sub-page (or unaligned-tail) file. On a native filesystem (ext4) the partial page reports resident, so this was invisible — until Kura’s Bazel tests ran on the virtio-fs-backed Kata microVM tuist-linux runners, where three mmap tests (mapping 16-byte / 5-byte / 23-byte files) panicked on freshly written region should be page-cache resident.

Full investigation and reproduction: #11430.

Impact

  • Not a correctness change. The reader fallback was always correct; this only restores the mmap fast path for sub-page files where mincore under-reports residency.
  • The only behavioral change: the exempted partial page could fault once as a single small read if it were genuinely cold. Every fully-backed page still gates strictly, so large artifacts are essentially unaffected (only the ≤1-page tail is exempt).
  • Makes the residency gate correct on virtio-fs-backed data dirs, not just native filesystems.

Validation

  • cargo test --lib mmap::tests — all pass, including the existing maps_unaligned_file_regions (the 16-byte sub-page case) and two new deterministic tests for fully_backed_pages_resident (the virtio-fs partial-page case, plus the fully-backed-must-be-resident case).
  • cargo clippy --lib -- -D warnings and cargo fmt --check clean.

Refs #11430

🤖 Generated with Claude Code

Comments

No GitHub comments yet.