Skip to content

Add TdsKVBackend storage driver and wire TDS backend into KVCacheManagerBase and KVCacheStore. - #948

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_983561034
Open

copybara-service[bot] wants to merge 1 commit into
mainfrom
test_983561034

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Sep 18, 2026

Copy link
Copy Markdown

Add TdsKVBackend storage driver and wire TDS backend into KVCacheManagerBase and KVCacheStore.

Standard buffered POSIX file I/O copies KV cache blocks through the Linux kernel page cache, incurring CPU memcpy overhead and host RAM page-cache bloat on high-throughput storage tiers such as Lustre, NFS, and NVMe SSDs.

Implement tpu_raiden::kv_cache::backends::storage::TdsKVBackend (tkv::backends::storage::TdsKVBackend) inheriting from KVBackend, and wire "tds" backend creation and Host DRAM pool buffer registration (RegisterBuffer) into KVCacheManagerBase and KVCacheStore.

All registration and data movement is delegated to libtdsul rather than to a hand-rolled I/O engine. Host buffers are registered with tds_buffer_register_vaddr / tds_buffer_register_dmabuf using TDS_MEM_HOST, the target file is registered with tds_storage_handle_register through an fd://<fd> URI, and transfers are issued via tds_read / tds_write / tds_readv / tds_writev.

TdsKVBackend opens the storage file with O_DIRECT and hands that descriptor to libtdsul. Because O_DIRECT is a property of the open file description, the underlying pread / pwrite inherit it and bypass the kernel page cache. For 4KB-aligned, registered slices this is a zero-bounce transfer (direct_ops). Unaligned buffer addresses, slice lengths, or file offsets are staged through a 4KB-aligned bounce buffer owned by TdsKVBackend (bounced_ops), which performs a read-modify-write to preserve surrounding bytes and an ftruncate to preserve exact logical file sizes. Per go/tdsul-api, bounce staging belongs in the framework adapter and never inside libtdsul. A separate o_direct_ops counter measures whether the page-cache bypass was actually retained, because both the open path and the I/O path can silently fall back to buffered mode.

Vendor libtdsul under third_party/tpu_raiden/tpu_sync/tpudirect_storage/ so that non-experimental tpu_raiden targets do not depend on an //experimental/... package. This copy is an interim measure; see the TODO in its BUILD file. It also carries three fixes to ThreadPoolConductor that upstream does not have: worker CPU affinity is applied only when an explicit core range is configured, pthread_create failures retry unpinned instead of leaving a silently dead worker, and Stop() drains the pending task queue instead of leaking queued requests.

@google-cla

google-cla Bot commented Sep 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@copybara-service
copybara-service Bot force-pushed the test_983561034 branch 2 times, most recently from 0d5aa8a to 1f26b1e Compare September 22, 2026 18:26
@copybara-service copybara-service Bot changed the title Add TdsKVBackend storage driver with zero-copy O_DIRECT and 4KB bounce-buffering. Add TdsKVBackend storage driver and wire TDS backend into KVCacheManagerBase and KVCacheStore. Sep 22, 2026
@copybara-service
copybara-service Bot force-pushed the test_983561034 branch 3 times, most recently from 5bc6bcc to 77da526 Compare September 23, 2026 20:03
…gerBase and KVCacheStore.

Standard buffered POSIX file I/O copies KV cache blocks through the Linux kernel page cache, incurring CPU `memcpy` overhead and host RAM page-cache bloat on high-throughput storage tiers such as Lustre, NFS, and NVMe SSDs.

Implement `tpu_raiden::kv_cache::backends::storage::TdsKVBackend` (`tkv::backends::storage::TdsKVBackend`) inheriting from `KVBackend`, and wire `"tds"` backend creation and Host DRAM pool buffer registration (`RegisterBuffer`) into `KVCacheManagerBase` and `KVCacheStore`.

All registration and data movement is delegated to `libtdsul` rather than to a hand-rolled I/O engine. Host buffers are registered with `tds_buffer_register_vaddr` / `tds_buffer_register_dmabuf` using `TDS_MEM_HOST`, the target file is registered with `tds_storage_handle_register` through an `fd://<fd>` URI, and transfers are issued via `tds_read` / `tds_write` / `tds_readv` / `tds_writev`.

`TdsKVBackend` opens the storage file with `O_DIRECT` and hands that descriptor to `libtdsul`. Because `O_DIRECT` is a property of the open file description, the underlying `pread` / `pwrite` inherit it and bypass the kernel page cache. For 4KB-aligned, registered slices this is a zero-bounce transfer (`direct_ops`). Unaligned buffer addresses, slice lengths, or file offsets are staged through a 4KB-aligned bounce buffer owned by `TdsKVBackend` (`bounced_ops`), which performs a read-modify-write to preserve surrounding bytes and an `ftruncate` to preserve exact logical file sizes. Per `go/tdsul-api`, bounce staging belongs in the framework adapter and never inside `libtdsul`. A separate `o_direct_ops` counter measures whether the page-cache bypass was actually retained, because both the open path and the I/O path can silently fall back to buffered mode.

Vendor `libtdsul` under `third_party/tpu_raiden/tpu_sync/tpudirect_storage/` so that non-experimental `tpu_raiden` targets do not depend on an `//experimental/...` package. This copy is an interim measure; see the TODO in its BUILD file. It also carries three fixes to `ThreadPoolConductor` that upstream does not have: worker CPU affinity is applied only when an explicit core range is configured, `pthread_create` failures retry unpinned instead of leaving a silently dead worker, and `Stop()` drains the pending task queue instead of leaking queued requests.

PiperOrigin-RevId: 983561034
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants