vllm.v1.kv_offload.tiering.p2p.data.nixl
¶
NixlTransport: Data-plane transport for RDMA-based KV block transfers via NIXL.
Threading: the agent is reached from the scheduler thread and, when the tiering manager runs one, from its tier-poll thread. The manager's lock serializes them strictly -- one Python thread inside any agent call at a time, with a full memory barrier between.
That lock is the only protection, not a belt over NIXL's own. nixl_agent picks
NIXL_THREAD_SYNC_STRICT only when enable_listen is set, which this transport
does not set, so the agent runs with NIXL_THREAD_SYNC_NONE -- under which NIXL's
internal agent lock compiles down to no-ops, leaving every agent entry point
unguarded. So the manager lock must cover all of them, and the lifetime of every
handle passed between calls. The exception is peer registration moved onto a
worker thread, as NixlConnector's handshake executor does: it runs outside the
lock and relies, like that connector, on NIXL tolerating it beside transfers.
Serialized use from a second thread is supported (checked against NIXL 1.4.1
sources): NIXL never creates its UCX worker in UCS_THREAD_MODE_SINGLE, the only
creator-thread-affine mode. The weakest mode it ever requests is
UCS_THREAD_MODE_SERIALIZED, documented as "multiple threads can access, but only
one at a time", and because enable_prog_thread defaults on here it actually
requests UCS_THREAD_MODE_MULTI and fails construction if the UCX build cannot
provide it.
Two caveats. NIXL binds a shared UCX worker per calling thread
(tlsSharedWorkerMap), which is harmless only while there is exactly one
shared worker -- true here, but it would stop being true if a num_workers
UCX backend param were ever set. And NIXL 1.4.1 does accept an explicit
sync_mode (including NIXL_THREAD_SYNC_RW), which would make its own locking
real; that parameter does not exist before 1.x, so passing it would need a
version gate, the way capture_telemetry does.
Classes:
-
NixlTransport–Manages a NIXL agent, memory registration, and block transfers.
NixlTransport
¶
Bases: DataTransport
Manages a NIXL agent, memory registration, and block transfers.
Wraps the NIXL C library behind a Python interface so the rest of the P2P tier code never touches NIXL types directly. Tracks inflight handles internally and returns completed/failed tags on poll.
Methods:
-
cancel–Cancel inflight transfers by their IDs.
-
force_release_retired–Release retired transfers that never stopped (bounded hold).
-
poll–Poll inflight transfers.
-
poll_retired–Release retired transfers that have stopped; return their ids.
-
write_blocks–Submit a WRITE transfer to peer_id.
_begin_registration(peer_id)
¶
Claim the next registration generation for peer_id.
_build_peer_handles(peer_id, agent_metadata, base_addr, num_blocks, block_len)
¶
The expensive half: agent wireup plus one descriptor per block.
Holding the peer lock across native registration would stall the scheduler thread for exactly as long as the registration it is meant to move off that thread.
_publish_peer(peer_id, gen, nixl_name, remote_dlist)
¶
Install freshly built handles, unless gen is stale.
Returns False when the peer was removed or re-registered while the handles were being built; the handles are released here since nothing else ever saw them.
_record_failure(peer_id, exc)
¶
Classify a NIXL exception: a peer fault, or one strike.
_record_state_check_failure(peer_id, exc)
¶
Fault peer_id for a check_xfer_state that raised.
The bindings raise for every NIXL error status (only success and in-progress are returned), so a raise is a failure NIXL reported, not a flaky check. A peer whose transfer state can't be trusted is torn down rather than given strikes: with strikes, successes to the same peer could keep resetting them while the transfer stays inflight, holding its pins, for good.
_release_remote_handles(peer_id, dlist, nixl_name)
¶
Release a peer's descriptor list and remote agent independently.
The two teardown operations are independent: NIXL may reject one
after a transport failure, and a release_dlist_handle that
raises must not skip remove_remote_agent. Skipping it would
leave a stale remote registration behind after the peer is gone
(peer removal) or after its registration was superseded.
cancel(transfer_ids, mode='immediate')
¶
Cancel inflight transfers by their IDs.
See DataTransport.cancel for the contract. In "wait" mode, a
transfer is released only once NIXL reports it terminal. Releasing
a PROC/PEND handle does not stop the WRITE: the UCX backend frees
the request without cancelling RMA, and the bytes keep landing. So
PROC/PEND transfers, and those whose state check or
release_xfer_handle raises, stay in self._inflight for a
later poll() to observe. A state check that raises faults the
peer; only a remote disconnect also counts as terminal (see
_is_terminal_state_error).
force_release_retired(transfer_ids)
¶
Release retired transfers that never stopped (bounded hold).
poll(peer_id=None)
¶
Poll inflight transfers.
When peer_id is given, only transfers submitted for that peer_id are checked and drained — the transport is shared across peer sessions, so an unscoped poll by one session would consume and discard siblings' completions. peer_id None polls every peer (shutdown drain only).
Returns PollResult(done=..., failed=..., peer_fault=...) with
transfer IDs. Completed handles are released automatically.
peer_fault is set on a scoped poll once peer_id is faulted.
poll_retired()
¶
Release retired transfers that have stopped; return their ids.
A transfer stopped once NIXL reports it terminal, by the same rule
as cancel(mode="wait"), but without charging its peer: the
peer is gone, and a reconnected one under the same id is not at
fault. A removed peer's remote handles are released once none of
its retired transfers remain.
write_blocks(peer_id, local_idxs, remote_idxs)
¶
Submit a WRITE transfer to peer_id.
Returns a transfer ID, or None if the peer is not registered or submission fails. The ID is returned via poll() when the transfer completes or fails.
_Inflight
¶
Bases: NamedTuple
A submitted-but-not-yet-drained transfer.
peer_id lets poll() scope to a single owning session, since the
transport is shared across all peer sessions of the engine.
struck is set once the transfer has counted against its peer, so a
state check that keeps raising charges it once, not once per poll.
retired is set once its peer is removed while it still runs; only
poll_retired() sees it from then on.
_is_terminal_state_error(exc)
¶
True if a failed NIXL state check ends the transfer.
Only nixlRemoteDisconnectError does: NIXL raises it once the target
endpoint is gone, so nothing more can land. Any other raise says nothing
about the WRITE itself; #59790 measured a WRITE that kept landing after
remove_remote_agent while its handle raised nixlNotFoundError.
Such a transfer stays inflight, so its pins and the peer's destination
blocks are not reused under it. The raise still faults its peer (see
_record_state_check_failure), which bounds how long it stays.
_peer_fault_status(exc)
¶
The NIXL status of exc if it is a peer-scope failure, else None.
Matched by name and status string so the bindings need not be imported.