vllm.v1.kv_offload.async_lookup
¶
AsyncLookupManager: per-tier async lookup manager for secondary tier existence checks.
Each secondary tier that wants non-blocking lookups composes its own AsyncLookupManager instance internally. The manager maintains lookup state and uses a background thread to execute batch_lookup() calls.
Locking design¶
There is no explicit lock. Thread safety is achieved by ownership:
-
_lookup_state and _lookup_batch are owned by whichever thread holds the OffloadingManager lock. lookup(), flush(), and cleanup() read and write them directly. That is usually the scheduler thread, but a tier reached through ParentManager -- a peer lookup fanning out from another tier, say -- can arrive on the tiering manager's tier-poll thread instead. Both hold the manager lock, so the accesses stay serialized.
-
_lookup_queue is written by the scheduler (flush → put_nowait, one item per step) and read by the background thread (get). queue.Queue is thread-safe.
-
_pending_results is written by the background thread (put) and read by the scheduler (get_nowait inside drain_results). queue.SimpleQueue is thread-safe by design.
lookup() accumulates new keys in _lookup_batch without touching the queue. flush() is called once per step from the tier's on_schedule_end(), posting the entire batch as a single queue item so the background thread sees one batch per step. Results are drained on the first lookup after each flush, at flush(), and after worker shutdown. In-flight lookups with no remaining request references are retained until their results are drained, allowing new requests to share the same probe; a successful store drops such an orphan instead (see mark_present()).
Classes:
-
AsyncLookupManager–Per-tier async lookup manager for secondary tier existence checks.
-
LookupPhase–Lifecycle phase of a lookup probe.
AsyncLookupManager
¶
Bases: ABC
Per-tier async lookup manager for secondary tier existence checks.
Each secondary tier that wants non-blocking lookups composes its own AsyncLookupManager instance internally. The manager maintains lookup state (cache, queue) and uses a background thread to execute the actual batch_lookup() calls.
Subclasses implement only batch_lookup() — all queue management, state tracking, and result delivery is provided by this base class.
The owning tier delegates its lookup(), on_schedule_end(), and on_request_finished() to this manager: - lookup() → drain_results() + lookup state check - on_schedule_end() → flush() - on_request_finished() → cleanup()
Methods:
-
batch_lookup–Check whether a batch of blocks exist in this tier.
-
cleanup–Release request references, retaining in-flight lookups.
-
drain_results–Apply pending worker results to _lookup_state.
-
flush–Post this step's accumulated keys to the worker thread.
-
lookup–Non-blocking lookup called from the scheduler thread.
-
mark_miss–Force the cached verdict for
keysto False after a failed load, so -
mark_present–Record that keys were successfully stored to this tier.
-
shutdown–Stop the worker thread and drain completed lookups.
batch_lookup(keys, req_context)
abstractmethod
¶
Check whether a batch of blocks exist in this tier.
Called from the worker thread — must be synchronous and must not touch the primary tier or scheduler state.
Returns a list parallel to keys: True if present, False if not.
cleanup(req_id)
¶
Release request references, retaining in-flight lookups.
Called from the tier's on_request_finished(). Uses the reverse index to visit only keys associated with this request.
drain_results()
¶
Apply pending worker results to _lookup_state.
Called from lookup(), flush(), and shutdown() on the scheduler thread.
flush()
¶
Post this step's accumulated keys to the worker thread.
Called once per step from on_schedule_end() after all lookup() calls are done. The worker receives the full batch and processes it during the model-execution window, maximising time available before the next step's drain_results(). Also drains completed lookups when there are no new keys to submit.
lookup(key, req_context)
¶
mark_miss(keys)
¶
Force the cached verdict for keys to False after a failed load, so
the scheduler stops re-issuing the doomed promotion (livelock, #49176).
Keys with no cached entry are skipped, and so are keys whose entry is
a newer probe still PENDING or IN_FLIGHT: its own result will land,
and forcing it to RESOLVED here would trip the phase asserts in
flush() / drain_results() on the scheduler thread.
mark_present(keys)
¶
Record that keys were successfully stored to this tier.
Unlike mark_miss(), which leaves a newer probe alone (#59096), a store completion is newer information than any probe started before it, so this supersedes them: advancing the generation makes a stale pending batch entry fail flush()'s generation check and a stale in-flight result fail drain_results()'s, before either phase assert is reached.
Keys with no cached entry are skipped, since a verdict with no owning request could never be reclaimed. An in-flight entry whose requests all finished is dropped; cleanup() already removed the reverse-index entries, so its late result is simply ignored.
shutdown()
¶
Stop the worker thread and drain completed lookups.