Repository navigation
engram: verify prefetch advice independently of row reads - #670
Conversation
There was a problem hiding this comment.
Verdict: CLEAN: The advice test checks syscall arguments independently of row reads, and normal builds retain the direct syscall.
Checked
Duplicates: 3 new items checked; no existing recorder or equivalent syscall test found. Dryer reported 0 pairs.
Complexity: crapper flagged no functions.
Silent failure: 1 syscall-result path followed; failed advice still returns a named SiteIo error.
Tests: assertions cover missing calls, shifted addresses, wrong lengths or advice at crates/engram/src/lib.rs:700, and bypassing either prefetch entry. The PR reports seven red mutant runs and 22 passing unit tests; Rust tests were not rerun here.
Boundaries: empty and rejected requests emit no advice; exact page sets and strict run separation catch omissions, duplicates and unmerged runs. Thread-local logs isolate parallel tests.
Gates: the replaced test and increased unsafe counts have dated PIN reasons; no tolerance moved.
Performance: recording and allocation compile only in test builds.
Escape catalog: C1–C4 do not match this diff.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Filed outside this PR: #673
5a69a91 to
325d403
Compare
There was a problem hiding this comment.
Verdict: CLEAN: The new assertions check prefetch advice independently of row reads, and non-test builds preserve the existing syscall.
Checked
- Duplicates: 3 new items checked (recorder, thread-local storage, test), none duplicated. Dryer reported 0 pairs.
- Complexity: crapper flagged no functions. Growth is test setup and assertions; production control flow is unchanged.
- Silent failure: 2 return paths followed. The recorder preserves the syscall result and leaves errno untouched on failure; the caller returns
EngramError::SiteIo. - Tests: at crates/engram/src/lib.rs:700, skipping the call fails the nonempty assertion; shifting the address or extending the length by one page fails exact-page equality. Changing the advice at crates/engram/src/lib.rs:710 fails the WILLNEED assertion. Duplicate and unmerged runs fail equality or separation assertions. Empty and invalid requests assert no calls. Integration-test edits change comments only.
- Gates: the replaced test has a dated reason. The unsafe ratchet increases by one block and one function with a dated PIN and explanation. No tolerance moves.
- Adversarial checks: thread-local recording separates parallel tests; expected pages come from mapping coordinates without row reads; last-row ranges fit the mapping.
- Escape catalog: no C1–C4 patterns matched.
Notes
Rust tests and mutations were not run during validation. The mutation conclusions above follow from code inspection.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Filed outside this PR: #675
|
The review is done and the contribution check passed, so I'm merging this. |
engram의 prefetch가 실제로 어떤 페이지를 커널에 요청하는지 직접 검사하는 시험을 더해서, prefetch가 빠지거나 한 페이지 어긋나도 시험이 실패하게 했습니다.
What and why
Closes #662.
The engram byte-comparison test reads rows back and compares bytes, so it does not notice when
prefetchadvises the wrong pages or none at all. This change adds a test that checks themadvisecalls themselves: the page address, the length and the advice kind that reach the system call. It does not depend on row reads or on populate side effects.In test builds,
TableBytes::advise_pagescalls a small wrapper in place oflibc::madvise. The wrapper forwards its arguments to the real call and records them per thread when the call succeeds, so parallel tests stay apart. Skipping the call or changing the address, length or advice changes the record. A normal build callslibc::madvisedirectly and has no recording code and no storage. The new testprefetch_advises_the_requested_page_runsrunsSite::prefetchand theRowTableimplementation'sprefetchagainst a real file mapping. It computes the expected pages from the mapping address, a tensor base the test chooses and the row size, and does not callpage_runs,pagesorrowfor that.The cases are small rows, rows of exactly one page, rows larger than a page, a tensor that starts in the middle of a page, duplicate, reversed, adjacent and distant rows, and the last row. For each call the test checks
MADV_WILLNEED, page alignment of address and length, the exact page set, and that runs are merged with no duplicate page. An empty request and an out-of-range request must emit no call.The comment in
crates/engram/tests/engram.rsthat claimed the byte comparison catches wrong prefetch ranges now says what it covers. The test replacespage_runs_advise_each_requested_page_once, whose page-run checks, empty input and rejected rows it covers. Thehw_engram_copy_rows_matches_rowhardware test gets the same comment correction. The byte comparison and residency tests stay as they are. No public API, I/O path or gate changes. The test-only wrapper adds oneunsafeblock and oneunsafe fn, each with a safety comment, andtools/unsafe-ratchet.txtrecords the new count (engram 12 blocks, 1 fn) with a dated reason.Release notes: internal: engram's prefetch test checks the pages advised to the kernel, so the test catches a missing or shifted prefetch
Code shape
TableBytes. The test adds one test-only wrapper at the shared call and one test. The expected pages are computed from file coordinates, so the test does not repeat product logic.engram.rsdescribes only what the byte comparison proves.cargo fmtis clean on what I touched.cargo clippywas not run here.Duplication found or removed (
path:line): none.What I ran
The commit is
5a69a91don upstream maine53cabeb, run on a Linux host with no GPU.FAIL first. I planted seven mutants one at a time and ran the new test with
cargo test -p bloomery-engram --lib tests::prefetch_advises_the_requested_page_runs -- --exact --nocapture. Each one failed at the intended assertion, with rc 101 and one failed test:madvisecall is replaced bylet rc = 0;MADV_NORMALSite::prefetchreturnsOk(())without advisingRowTableimplementation'sprefetchreturnsOk(())without advisingTableBytes::advisepassesfirst + self.pagemadviseaddress inadvise_pagesisfirst + self.pagemadviselength inadvise_pagesislen + self.pageThe first row is the case the issue describes: a prefetch with no advice that the byte comparison cannot see. The fifth row's failure shows a page set off by one:
left: [33539142066],right: [33539142065].Each mutant is restored after its run, and
git diff --exit-codeis clean afterwards. On the unchanged code:The
engramintegration tests also compile and run; the 12 existing hardware tests stay ignored.cargo fmt -p bloomery-engramandgit diff --check upstream/main...HEADare clean. The checks ran on5a69a91d.The existing hardware tests need the original model checkpoint on disk and stay ignored. I did not use them as evidence for this change. The new test needs no model and no GPU.
What I ran into
This does not block this change.
The crate overview in
crates/engram/src/lib.rsdescribes the prefetch cost as one syscall per row, whileTableBytes::adviseandSite::prefetchissue one per distinct page run. I left the text as it is, since it is a cost description and not a test gap. To check it, read the overview next to the new test's page-run expectations.prefetchand thepopulatethat follows it for the same ids each sort the ids, build the runs and merge pages again. I did not measure whether that host work matters and changed nothing there.Hardware (if the change is for a machine)
A Linux host, CPU only. No GPU, model download or timing was involved, and this change touches no kernel, launch, device copy, sync or placement path. I made no speed claim.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.