[1/3] kv: page ownership for prefix caching - #279
Merged
Merged
Conversation
2 tasks
Gaurav-Shah05
added this pull request to stack #282
September 21, 2026 05:58
Gaurav-Shah05
requested review from
NSagan271,
garv901,
merceod,
stephen-dwq and
vasilevklart
September 21, 2026 05:59
stephen-dwq
reviewed
Sep 22, 2026
| - ``0`` | ||
| - ``N > 0``: every N iterations log per-phase p50/p95/mean of the | ||
| worker main loop (speculate, await_gpu, submit_spec, ...). | ||
| * - ``MSTAR_KV_DEBUG_ASSERTS`` |
Collaborator
There was a problem hiding this comment.
Nit: not a fan of this flag existing but it doesn't hurt ability, although does disperse testing across a wider than already-is range
Collaborator
Author
There was a problem hiding this comment.
The tests don't need it beacuse they call assert_pages_conserved directly. I kept it for checking a live server. I'm currently stress testing #280 with shared prefixes, cancellations and eviction, and with the flag on, a page that leaks or gets freed while still in use raises at the op that caused it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Part of #210. First of three PRs for cross-request prefix KV reuse. This is groundwork only, w/o any observable changes.
Owner counts
PageArenakeeps one int per page:acquiresets it to one,retainincrements,releasedecrements and frees the page at zero, so a page goes back when its last owner frees it rather than at the allocating request's teardown. Nothing callsretainyet, so every page has one owner and the free rule ismain's.PageAllocatorand all call sites are untouched.Sealed pages
sealmarks a page as never written again, the precondition for a second owner to read it; freeing clears it. A stream that rewinds across a sealed page drops its pages. The only rewind today isreset_request(free=False)fromDummyRowPool.reset, and nothing seals yet. The rule is stated for any rewind so the next rewind entry point inherits it.The invariant
KVManager.assert_pages_conserved: every page free or owned, never both; an owner count equals the streams holding the page plus one for the sink; only sealed pages are shared; the page a stream is writing has one owner. Runs afteradmit,commit,reset_requestandremove_requestunderMSTAR_KV_DEBUG_ASSERTS=1(documented indocs/environment_variables.rst).Host pages are untouched;
CPUPagePoolkeeps no counts.How was it tested?
12 tests in
test/modular/test_kv_page_ownership.py.pytest test/modular -q:937 passed, 20 skipped, 1 failed, the failure pre-existing onmain. Bagel bit-identical tomainat424a112con two chats and an image, compared in the same allocation.Checklist
ruff check .passes