Skip to content

gpu-gates: retry nvread eviction over the whole shard - #356

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-nvread-folio-eviction
Oct 16, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-nvread-folio-eviction

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Closes #137.

What and why

probe_nvread stops on a DGX Spark with ext4 when its per-part page-cache eviction leaves pages resident. The probe drops each part with evict_rows and then checks with mincore. evict_rows only drops folios that lie wholly inside the requested range. On ext4 the page cache holds large folios, so a folio that crosses an expert or tensor boundary stays, and mincore reports its pages as resident. The instrument then fails with "after an eviction mincore finds 34 of 226 pages ... resident".

The fix adds SplitTable::evict_shard, which drops the whole shard mapping and asks the kernel to evict the file's page cache to its end. It reuses the existing page advice and fadvise code. probe_nvread calls it only when mincore still finds resident pages after the exact eviction, and it prints the retry to stderr (path, expert, resident and total pages). The retry runs before the timed arms, so it is not inside any measured time. The resident-is-zero requirement, the redraw bound and the MADV_NORMAL, cache, direct1, directN and drive arms are unchanged. Pages held by another process still force a redraw.

Release notes: Fixed: probe_nvread no longer fails its eviction check on ext4 when a large folio crosses a row boundary; it retries over the whole shard and says so.

What changes:

  • crates/engram/src/rows.rs: public SplitTable::evict_shard.
  • crates/engram/src/lib.rs: the SAFETY note of advise_pages also covers a whole-file mapping range. No unsafe block is added.
  • crates/gpu-gates/src/bin/probe_nvread.rs: the conditional retry and its stderr line.
  • crates/engram/tests/engram.rs: the existing eviction contract test now also checks that the whole expert and its neighbouring tensor leave the mapping.
  • docs/contrib/dgx-spark.md: the open item that called the cause unproven now states the current behaviour.

The retry also drops the other cached tensors of that shard, which the stderr line makes visible. No timed arm changed, so this PR claims no speed change. I found no safe NVMe read speedup that this fix could carry, so there is no speed commit.

What this PR does not do

  • It does not inject another process that maps or locks the pages. The zero-resident contract has no tolerance, as before.
  • It runs no default 64-batch measurement. The runs below use 16 batches and lease=false, so they check function and are not timings.

Code shape

  • No second copy. evict_shard reuses advise_pages and fadvise_dontneed. No other shard-wide eviction existed.
  • Model code holds only architecture facts. No model file is touched.
  • Dead code is gone. evict_shard has one caller, the probe's retry.
  • No silent failure. Errors propagate with ?; the retry prints a line each time it runs.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or lint moved.
  • cargo fmt was run on the changed files with the pinned nightly; git diff --check is clean. I did not run cargo clippy on this head.

Duplication found or removed (path:line), or "none": none.

What I ran

The head is 20bfbc90, one commit on ac66556d (upstream/main when I branched). The runs used the Qwen3.8-Flash-Next UD-Q4_K_XL split GGUF already on the machine.

Check Result
Before the fix, on ac66556d: probe_nvread --threads 3 --ks 49 --range-from 256, three runs all three rc 1 with after an eviction mincore finds 34 of 226 pages of ...-00003-of-00004.gguf expert 256 resident
After the fix: the same command, three runs each prints retrying eviction over whole shard ...: expert 256 kept 29 of 226 pages, passes the eviction and populate checks, and ends at the intended --ks 49: a batch draws from distinct layers, and the model has 48 rejection (rc 1 is expected there); the original error is gone
After the fix: probe_nvread --ks 1,3,16 --range-from 256 --batches 16 --warmup 1 --range-batches 2 at --threads 3 and --threads 8, two runs each 4 of 4 rc 0, every arm row redraws=0, final line REGRESSION-passed; 424 retry lines were printed across the instrument and probe runs, so the fallback was used
cargo test -p bloomery-engram --test engram hw_engram_expert_stack_evicts_and_reads_back -- --ignored --exact --nocapture 1 passed; 0 failed
cargo test -p bloomery-gpu-gates --bin probe_nvread 5 passed; 0 failed
cargo build --release -p bloomery-gpu-gates --bin probe_nvread finished
just mac-static, clippy, just affected, full contrib-check t0 Not run

To reproduce, build the probe and run the first command above against the split GGUF's first shard.

The first wrapper script for the post-fix runs exited rc 2 after the tests and build had passed, because its grep -q "--ks" read the pattern as an option. I reran only the runtime part with -- before the pattern; the passing tests and build are not repeated.

Hardware (if the change is for a machine)

One DGX Spark with an NVIDIA GB10, driver 595.84, Linux 6.17.0-1032-nvidia, ext4 for the model files, a CUDA 13.3.1 container and rustc 1.100.0-nightly (e457a7b0d 2026-08-27). probe_nvread reads files and does not launch a kernel, so the card only identifies the machine. The runs are not under the lease (lease=false), so the rates in the logs are not measurements and are not cited.

What I ran into

This does not block the PR. The retry line appears for the parts the instrument and probe runs touched, so on this machine the exact eviction alone did not clear them. I did not measure the folio sizes directly, and I ran no kernel other than 6.17.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added dgx-spark The DGX Spark (aarch64, GB10) port documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 16, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: CLEAN: The shard retry preserves the zero-resident requirement and propagates eviction errors.

Non-blocking

⚠ Test the probe's retry call: crates/gpu-gates/src/bin/probe_nvread.rs:561.
The extended hardware test:820 calls evict_shard directly. Deleting the probe's retry leaves those assertions unchanged; retained pages then make prove_instrument reject the run.
Add a probe-level regression with a retained edge folio that requires the retry to reach zero resident pages.

Checked

  • Duplicates: 1 new method checked; shard eviction reuses advise_pages and fadvise_dontneed. dryer reported 0 pairs.
  • Complexity: crapper flagged no changed function. drop_parts adds a conditional retry; evict_shard is linear orchestration.
  • Silent failure: 0 new default/error-discard sites; 7 added fallible calls followed. Errors reach the named probe exit. Remaining resident pages still cause rejection or bounded redraws.
  • Tests: static mutation analysis of crates/engram/src/rows.rs:225: omitting file-cache eviction leaves warmed pages resident and violates the added assertions. Limiting eviction to the stack violates the neighbour assertion. The hardware test remains hw_-prefixed and ignored.
  • Gates: no pin, tolerance, assertion or redraw bound relaxed. Retry and logging precede all arm timers; no engine hot path changed.
  • Escape catalog: C1–C4 do not match.

Notes

dryer did not scan gpu-gates; its changed code was checked manually. Tests were not executed during this review. The PR lacks the nvidia-smi line and just gate-* output required for GPU evidence.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/probe_nvread.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit fbf46e5 into midagedev:main Oct 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dgx-spark The DGX Spark (aarch64, GB10) port documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app gpu-verified host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tools, gpu-gates, gpu, engram, gguf, qdot, refset: problems found on the side of the DGX Spark work, by severity

2 participants