Skip to content

vllm.v1.kv_offload.tiering.fs.io

Functions:

  • batch_load_block –

    Load a batch of KV blocks from disk into a shared buffer in one call.

  • batch_store_block –

    Store a batch of KV blocks from a shared buffer to disk in one call.

  • probe_o_direct –

    Return whether O_DIRECT I/O works in directory.

_ensure_dirs(path)

Create parent directories of path if they don't exist.

_get_tmp_suffix()

Generate a thread-local unique suffix for temporary files.

_load_block(source_path, view, offset, block_size, use_o_direct=True)

Read one KV block from disk; remove the file only on a provable short read (a too-short file is genuine corruption) and leave it untouched on any other error.

_store_block(dest_path, buffer, offset, block_size, use_o_direct=True)

Write to a temp file then atomically replace the target.

Returns False, writing nothing, if the target already exists. A block another writer publishes during the rename still returns True: its bytes were written, so it counts for bandwidth accounting.

_validate_offsets(view, offsets, block_size)

Raise if any block would read/write past the bounds of view.

Without this, an out-of-range offset silently clips to a shorter (or empty) slice instead of failing, since memoryview slicing follows Python's slice-clamping semantics rather than raising.

batch_load_block(paths, view, offsets, block_size, use_o_direct=True)

Load a batch of KV blocks from disk into a shared buffer in one call.

Block i is read from source_paths[i] into view[offsets[i] : offsets[i]+block_size]. Raises on first error (see _load_block for the delete-on-short-read policy). On failure the raised OSError carries num_succeeded = the number of blocks loaded before the failing one, so the tier can keep them.

batch_store_block(paths, view, offsets, block_size, use_o_direct=True)

Store a batch of KV blocks from a shared buffer to disk in one call.

Each block buffer[offsets[i] : offsets[i]+block_size] is written atomically to paths[i] via a temp-file rename. Blocks whose file already exists are skipped. Raises on first error.

Returns:

  • int –

    The number of blocks transferred, including blocks another writer

  • int –

    published during the call (written, then dropped).

probe_o_direct(directory)

Return whether O_DIRECT I/O works in directory.

O_DIRECT is unsupported on some filesystems (e.g. the overlayfs backing a container /tmp, older tmpfs, or some NFS mounts), where opening or writing a file with it fails with EINVAL. Probe once with an aligned single-page write so callers can fall back to buffered I/O instead of failing on every block.