Repository navigation
[Refactor] mem_cache: Give unified request rows one lifecycle state and one reset - #48010
Merged
Merged
Conversation
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 4, 2026 06:18
5134760 to
7b372ac
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 4, 2026 06:18
a11a036 to
c148fe9
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 4, 2026 07:42
7b372ac to
64a142d
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
2 times, most recently
from
November 4, 2026 08:02
8c38f94 to
98ca05e
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
2 times, most recently
from
November 4, 2026 09:14
8650182 to
b620c98
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 4, 2026 09:14
98ca05e to
293a82f
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 4, 2026 09:31
b620c98 to
93db0fd
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 4, 2026 09:31
293a82f to
2891d73
Compare
This was referenced Nov 4, 2026
Merged
Merged
Merged
Merged
ch-wan
requested review from
ByronHsu,
Duyi-Wang,
HaiShaw,
ShangmingCai,
hebiao064,
sogalin and
yuan-luo
as code owners
November 5, 2026 11:24
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 5, 2026 11:24
0a7d0ca to
6454eae
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 5, 2026 22:15
ea0a16c to
35d4c63
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 5, 2026 22:15
6454eae to
dfe1b18
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 00:00
35d4c63 to
0185108
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 6, 2026 00:00
dfe1b18 to
4ce32c4
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 01:16
0185108 to
ed6c74d
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 6, 2026 01:16
4ce32c4 to
2482b08
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 03:37
ed6c74d to
965972b
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 6, 2026 03:37
2482b08 to
3aba5c2
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 06:34
965972b to
cc62158
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 6, 2026 06:34
3aba5c2 to
87cba28
Compare
This comment has been minimized.
This comment has been minimized.
4 of 5 tasks
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 10:43
cc62158 to
2c9b8ec
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 6, 2026 10:43
87cba28 to
6655400
Compare
This comment has been minimized.
This comment has been minimized.
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 12:31
2c9b8ec to
66fc9a0
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 6, 2026 12:31
6655400 to
d36d4fa
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 13:40
66fc9a0 to
5f68220
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-planner-reclaim
branch
from
November 6, 2026 13:40
d36d4fa to
9076fef
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 21:21
5f68220 to
9d0d417
Compare
This comment has been minimized.
This comment has been minimized.
…nd one reset The unified request table now keeps one state per row: free, active (a request's, running or waiting, PD decode preallocated rows included), parked (a streaming session between turns) or held (beam members, a retained Unlimited-OCR document window). Its methods are the only transitions, and a release of a row that is already free fails loudly. - A streaming session parks its row when a turn finishes and unparks it when the next turn is allocated; a match alone does not unpark it, since a rejected turn runs nothing on the row. Beam members take held rows. - `RequestTable.clear()` resets every row state and runs the storage's hook, which ends every recorded network transfer and receive hold. `flush_cache`, the PD role switch and the one-batch benchmark already clear the table, so nothing keyed by a row or a request outlives the reset. - `release_row` ends network transfers only for an active row. A session slot or a retained window is no request and has no request id; a parked or held row's request ended its transfers when the row passed on. - Unlimited-OCR document reuse moves a retained window's row to held and releases it through the storage instead of the table directly. - The idle invariant check asserts the state counts for a unified table: no active row, and parked plus held rows equal what sessions and retained windows own. A static request pool keeps its count check.
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.
This PR is part of a stack (oldest at bottom):
Motivation
Under
--enable-unified-memory, what holds a request row was spread over several structures: the request table's free list, the PD transfers and receive holds the storage keeps per request, and the scheduler's session slots. Nothing tied them to one row state, so each reader derived "who holds rows" on its own:flush_cache, the PD role switch, the one-batch benchmark) freed every row but left the per-request PD transfer and receive-hold records behind.This PR gives each unified request row one state, owned by the request table, and one reset.
Modifications
RowStateinmem_cache/kv/requests.py: FREE, ACTIVE (a request's, running or waiting; a PD decode node's preallocated receive row too), PARKED (a streaming session's between turns) and HELD (beam members, a retained document window). The table's methods are the only transitions (alloc_rows(state=),free_rows,park,unpark,hold,clear), it counts rows by state (count,state_of), and a release of a row that is already free fails loudly instead of handing it out twice.RequestTable.clear()resets every row state and then runs its clear hooks.KVStorageregisters one that ends every recorded network transfer and receive hold, so nothing keyed by a row or a request outlives a reset. The scheduler already clears the table on every reset; no scheduler change.KVStorage(mem_cache/kv/storage.py):release_rowends network transfers only for an ACTIVE row: a parked or held row's request ended them when the row passed on, and a session slot or a retained window has no request id.park_row,unpark_rowandhold_rowmove a row through the table;take_rowshands beam members HELD rows.session/streaming_session.py): a finished turn parks its slot's row; the next turn unparks it when its row is allocated (take), not when it matches, since a rejected turn runs nothing on the row.StaticKVStorageanswerspark_row,unpark_rowandhold_rowas no-ops.test/registered/unit/mem_cache/kv/test_request_rows.py(state counts, a flush with parked sessions, a role-switch reset ending transfers and receive holds, closing a parked session, the idle check, a double release failing);test_uocr_doc_reuse_unit.pyroutes its fakes through a storage and checks the hold.Behaviour changes
--enable-unified-memory: closing a streaming session releases its row by state; a reset ends every recorded PD transfer and receive hold; a double release of a request row raises.--enable-unified-memory: the static storage's new calls are no-ops, and a static request pool keeps its idle check.Accuracy Tests
This stack is validated at its top, on
maina4b8801197: the affected unit tests at the default and strict invariant levels, the CPU unit suite, the page-safety stress run and sweep, and serving accuracy and speed againstmain, all reported in #48014.Checklist
pre-commiton the changed files.CI States
Latest PR Test (Base): ❌ Run #42608653550
Latest PR Test (Extra): 🚫 Run #42608653432
Latest PR Test (AMD ROCm 10): ❌ Run #42608653389
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: