Repository navigation
[Fix] hicache: Continue eviction after a failed file unlink - #42488
apex-mochen wants to merge 3 commits into
Conversation
|
@ispobock Could you review this small HiCache file eviction fix? One oldest page with a failing unlink currently stops all eviction, even when later pages are reclaimable. The change keeps its bytes charged and uses the existing bounded skip loop to try other victims. Two regressions fail before the fix; the complete file-cache CPU suite passes (36 tests). Coverage includes all candidates failing and successful retry after the error clears. No GPU serving or performance claims. This is independent of the pending-write ownership fix in #42482. |
45563c5 to
4456e45
Compare
|
The run for the |
|
@xiezhq-hermann Thanks for reviewing #42077. This is another small HiCache file-backend correctness fix, so I wanted to ask if you’d be willing to take a look when convenient. #42488 fixes eviction stopping after one failed file unlink. The failed page remains charged, while eviction continues through the existing bounded victim loop so other reclaimable pages are still considered. Focused regressions cover both:
The complete CPU file-cache suite passes locally. If someone else owns this path more directly, happy to route it there instead. Thanks! |
Signed-off-by: apex-mochen <[email protected]>
4456e45 to
803e448
Compare
fix(hicache): continue eviction after a failed unlink One undeletable oldest page pinned the LRU head and every later capacity write refused. A failed unlink is now a bounded skip (accounting retained, entry re-inserted at MRU) so the eviction loop keeps trying other victims. (cherry picked from commit 803e448)
…he-file (entries 250-251)
xiezhq-hermann
left a comment
There was a problem hiding this comment.
Thanks for the fix and the regression tests, and sorry for the slow review. I checked it against current main (a478cd21e0):
- Both new tests fail on main.
set("new")is refused with "no evictable space ... not caching", andremoveis called once instead of twice. - Both pass with your change, and the whole file passes (45 tests).
- The PR still merges cleanly.
#31485 reported the same wedge earlier with the same approach, but the idle-PR bot closed it before anyone reviewed it, so thanks for picking this up.
A few asks:
- Please drop
TestEnvDefaultsfrom the test file. #43503 removed that class on purpose, and the rebase brought it back. - Please bound failed unlinks per eviction pass. When the whole cache directory stops allowing unlink (read-only remount, lost permission, dead FUSE/NFS mount), main gives up after one failed unlink. This version tries every tracked file and logs a warning for each, all while holding the evictor lock, which also blocks
touch()on reads.- Measured with 20,000 tracked files and the directory chmod 0555 (as a non-root user): one refused
reservegoes from 1 unlink attempt (about 0.1 ms) to 20,000 attempts and 20,000 warnings (about 170 ms). The cost grows with the cap. - A fix: add a separate
"failed"outcome that stops_evict_whileafter a small constant number of failures in one pass (I tried 8). That brings the case back to 8 attempts and about 0.1 ms, and all 45 tests (including both of yours) stay green. Because the bad entry is re-pinned at MRU, later passes still rotate it out of the LRU head.
- Measured with 20,000 tracked files and the directory chmod 0555 (as a non-root user): one refused
- Optional: the
fast_filebackend has the same stop-at-LRU-head behavior instorage/fast_file/lru_file_evictor.py(_evict_one_lru_locked, theexcept OSErrorbranch). Mirroring the fix there would be welcome, but it is also fine to keep this PR scoped tofile.
Once these are in, I'm happy to add run-ci.
Review asks on sgl-project#42488: - Drop TestEnvDefaults; sgl-project#43503 removed it and the rebase brought it back. - Add a distinct failed outcome for a refused unlink and stop _evict_while after 8 consecutive failures. The failed entry is re-inserted at MRU, so later passes rotate other victims in; bytes stay charged. - Add a regression with 12 tracked files and every unlink failing: 8 attempts, accounting unchanged. Signed-off-by: apex-mochen <[email protected]>
|
Thanks @xiezhq-hermann — all three asks are addressed in
Verification: Head |
|
Thanks for the approval. The remaining red checks ( |
|
I checked the current merge conflict and prepared a sync commit, b754ee2, on main I reran 29 backend-local cases with real CPU tensors and files in an isolated Windows runner. All 29 passed. This is local evidence and the upstream CI run is still pending. GitHub has the sync commit, but the branch update did not go through, so this PR still points to Update: the branch is now at be21d7e and GitHub reports it merges cleanly. The new commit only relocates the existing regression cases, and all 29 scoped backend cases passed on the locally merged source. GitHub still reports the previous review as approved. Could a maintainer enable the required CI for this head? I also fetched the storage implementation, evictor, and registered unit file directly from GitHub's test merge Additional failure-path check on 422fb59: I exercised both the byte cap and the free-space watermark with eight undeletable files followed by one reclaimable file. The first admission stopped after eight attempts. The next admission evicted only the reclaimable file and completed the write. I also let unlink succeed while the modeled free-space probe remained unchanged; the watermark still refused the write until the probe reported enough space. These new cases failed on main 54c7614 and the 31 scoped cases passed on the test merge. The Windows harness used real files and a controlled free-space probe. |
Keep the original regression cases in a separate test class so this branch merges with main's updated test layout.
Motivation
With a bounded HiCache file backend, one undeletable oldest cache page prevents eviction of every later page.
_evict_one_lru_lockedrestores that entry at the LRU head and returnsstopon OSError. Every later capacity-constrained write retries the same head and is refused, even when another page can be reclaimed.Reproduction on official main 29bcb74: fill a 128-byte cap with two real 64-byte files, inject PermissionError only for the oldest file's unlink, then cache another 64-byte page. The new write returns False and the second, deletable file is never tried.
Modifications
Retain the failed entry and its charged bytes at the end of the eviction queue, returning
skippedso the existing bounded skip loop can try other victims. A failed unlink contributes zero reclaimed bytes and does not invalidate positive metadata. Update the helper's outcome documentation.Two CPU regressions check:
This changes eviction ordering after an unlink failure. It does not retry forever or assume the failed file was removed. It shares the existing skip budget with pending writes. Scope is one file-backend evictor, not cross-process coordination.
Accuracy Tests
Python 3.12, PyTorch 2.13.0+cu130, CUDA hidden; normal SGLang imports with isolated test dependencies. Real CPU tensors/files; unlink failures injected, not a claim that a physical filesystem failure was reproduced.
No full GPU server, distributed restore or model-accuracy test was run.
Speed Tests and Profiling
No benchmark or throughput claim. This repairs admission progress under an unlink error, leaving the successful eviction path unchanged.
Checklist
Review and Merge Process
Ready for KV Cache review and authorized CI. AI assistance used for investigation, implementation, tests and this description. Distinct from #42482 (pending write ownership), #41686 (free-space reservations) and #39269 (file read errors).
CI States
Latest PR Test (Base): ⊘ Skipped -- a maintainer comments⚠️ Run #47288275693
/tag-and-rerun-cito run CI tests.Latest PR Test (Extra): ⊘ Skipped -- a maintainer comments
/tag-and-rerun-cito run CI tests.Latest PR Test (AMD ROCm 10):
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent:Latest-main validation (2026-10-06)
Rebased onto upstream main
bb4d0a13c128400fcbed97096e3d823f33563084, which includes the maintenance gate's required basefea3c088a141. Production/test patch IDs match the previous head; no behavior or scope change. Current head:4456e4562473fc3db2a24e8ff901b4f49faa7eeb.The existing registered CPU file-cache suite was run on an isolated latest-main tree with this exact patch: 36 passed, 3 warnings in 22.48s.
git diff --checkpassed. Command:The first attempt with an empty CUDA_VISIBLE_DEVICES failed at test collection because test_utils indexes its first character; it ran no tests. The retry above passed. No GPU serving, performance benchmark, or model-accuracy claim. GitHub CI must complete separately; previous red summaries came from a required-base maintenance check before tests ran.