Repository navigation
Conversation
…cache-ai#5458) Implements Track 2 cold-read reuse for kvcache-ai#5458: - Add opt-in FileStorageConfig::enable_foreground_read_promotion_reuse (default false, MOONCAKE_OFFLOAD_REUSE_FOREGROUND_READ_FOR_PROMOTION) and bounded byte cap promotion_reuse_max_bytes (default 64 MiB, MOONCAKE_OFFLOAD_PROMOTION_REUSE_MAX_BYTES). - Publish whole-object foreground BatchGet / BatchGetLocal staging payloads (only when allocated from the TE-registered client_buffer_allocator_) into an epoch-stamped FIFO handoff cache; partial BatchGetRanges never publish. - Consume matching staging payload in PromoteOneKeyFromLocalDisk (re-verifying object size) to skip the redundant second SSD read, holding shared_ptr ownership until PromotionWrite finishes. - Use selective key invalidation on BatchOffload and evict-only invalidation in RunDiskWatermarkEviction so no-op heartbeat checks do not clear reuse. Signed-off-by: dhx98 <haox.dai@gmail.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ed6325aac
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ColdReadInvalidation invalidate(*this, | ||
| /*invalidate_reuse=*/false); | ||
| InvalidatePromotionReuseKeys(offload_storage_keys); |
There was a problem hiding this comment.
Invalidate read generations when offloading a written key
With reuse enabled, a BatchGet can finish loading an old value and pause before publication while a non-evicting kFilePerKey offload overwrites that key. Both per-key invalidations only erase existing entries and leave promotion_reuse_epoch_ unchanged, allowing the delayed reader to republish old bytes with a still-current epoch. A subsequent promotion of the same-sized replacement then reuses those bytes and commits stale data into MEMORY. Advance/check a generation for written keys as well as erasing existing entries, so pre-write reads cannot refill the cache after invalidation.
Useful? React with 👍 / 👎.
| .epoch = read_epoch, | ||
| .retained_bytes = entry_bytes, | ||
| .expires_at = expires_at}); | ||
| promotion_reuse_fifo_.push_back(keys[i]); |
There was a problem hiding this comment.
Bound FIFO metadata when replacing cached keys
With reuse enabled, repeated reads of the same key replace its map entry but append another FIFO record without removing the previous one. If reads refresh the entry before its TTL and no full invalidation occurs—for example, on a restarted holder where reclamation is disabled—the byte count stays below the cap and GC never empties the map, so the deque grows indefinitely despite retaining only one payload. This can exhaust process memory independently of promotion_reuse_max_bytes. Remove or compact stale FIFO records when entries are replaced, consumed, or expired.
Useful? React with 👍 / 👎.
| const uint64_t entry_bytes = static_cast<uint64_t>(sizes[i]); | ||
| if (entry_bytes > max_bytes) { | ||
| continue; |
There was a problem hiding this comment.
Account for all buffers retained by each cached batch
With reuse enabled and a 64 MiB limit, a foreground batch containing a 128 MiB value and a 1-byte value skips caching the large key but still creates a 1-byte entry holding a shared_ptr to the entire AllocatedBatch. All of that batch's buffer handles therefore remain alive after the foreground alias is released, while the counter reports only one retained byte. Consuming or evicting part of a multi-key batch causes the same undercount, allowing the cache to retain far more staging memory than configured. Account for each retained batch/handle once, or retain only the individual key's allocation.
Useful? React with 👍 / 👎.
Description
Addresses #5458 Track 2 ("Use the foreground read payload for promotion") with an opt-in (
default: false), bounded-memory handoff between foregroundLOCAL_DISKreads and background promotion, with zero RPC changes.Problem
When a cold
LOCAL_DISKkey is read in the foreground and subsequently promoted toMEMORY(e.g., via--promotion_on_hit=trueor prefetch), the holder reads the exact same object from SSD twice: once inFileStorage::BatchGet/BatchGetLocalfor the foreground reader, and a second time inFileStorage::PromoteOneKeyFromLocalDisk.Design
FileStorageConfig::enable_foreground_read_promotion_reuse(MOONCAKE_OFFLOAD_REUSE_FOREGROUND_READ_FOR_PROMOTION, defaultfalse).FileStorageConfig::promotion_reuse_max_bytes(MOONCAKE_OFFLOAD_PROMOTION_REUSE_MAX_BYTES, default64 MiB) bounds total staging bytes retained in the FIFO handoff map;AllocateBatchalso evicts idle handoff entries before returningBUFFER_OVERFLOW.AllocatedBatch::registered_for_transfertracks whether staging memory came from the TE-registeredclient_buffer_allocator_(vs. an unregistered pinned restore arena); only TE-registered whole-objectBatchGet/BatchGetLocalreads publish into the handoff map. PartialBatchGetRangesnever publish.PromoteOneKeyFromLocalDisk()consumes matching entries (re-verifyingGetObjectDataSize()+ epoch) and holdsstd::shared_ptr<AllocatedBatch>untilPromotionWritecompletes (release-by-completion, independent of foreground alias release).LoadBatchShared.RemoveAll,UnmapKeys, andRemoveDeadBuckets.BatchOffloadinvalidates only written/overwritten keys (plus full invalidation ifeviction_handlerevicts keys), andRunDiskWatermarkEvictioninvalidates only when eviction actually removes keys (avoiding no-op per-heartbeat cache wipes).Shutdown()drains the handoff map before unregistering the staging arena.mooncake_ssd_promotion_payload_reused{_bytes}_totalinSsdMetric.Suggested Merge Priority
Module
mooncake-transfer-engine)mooncake-store)mooncake-conductor)mooncake-reshard)mooncake-ep)mooncake-pg)mooncake-integration)mooncake-p2p-store)mooncake-wheel)mooncake-common)mooncake-rl)Type of Change
How Has This Been Tested?
1. Unit Tests (CPU/TCP +
-DUSE_ASCEND_DIRECT=ON)file_storage_promotion_test— added 6 tests covering whole-objectBatchGetreuse with mid-write foreground alias release, feature-off control,BatchGetRangesnon-publication, source replacement invalidation + failure isolation,BatchGetLocalreuse, and no-op watermark check preservation — ALL PASSfile_storage_config_test,ssd_metrics_test,prefetch_teardown_test— ALL PASS2. Matched Alternating A/B Benchmark on Physical Enterprise NVMe
Host:
aarch64, 4× 3.5T Enterprise NVMe (HWE72P453T8L007N), livemooncake_master(--promotion_on_hit=true --promotion_admission_threshold=2 --promotion_max_per_heartbeat=64) +mooncake_client(MOONCAKE_OFFLOAD_PROMOTION_REUSE_MAX_BYTES=128 MiB).Workload: 3 alternating matched pairs (
OFF -> ON × 3) per I/O mode; each run seeds100 × 2 MiB, evicts40 × 2 MiB = 80 MiBcoldLOCAL_DISK-only keys, runssync && drop_caches=3, reads & promotes all 40 keys, and verifies 40/40 foreground + 40/40 post-promotion byte-exact equality.Mode A — Default Buffered I/O (mean of 3 alternating pairs)
OFF)ON)ssd_read_ops_totalssd_read_bytes_totalssd_promotion_payload_reused/proc/<pid>/iorchar/proc/<pid>/iosyscrget()p50 / p95Mode B —
MOONCAKE_OFFLOAD_USE_URING=true(io_uring + O_DIRECT, bypassing OS page cache; mean of 3 alternating pairs)OFF)ON)/proc/<pid>/ioread_bytes(NVMe DMA)ssd_read_ops_totalssd_read_bytes_totalssd_promotion_payload_reusedget()p50 / p99(All 12 runs achieved 40/40 promoted and 100% byte-exact verification.)
Test commands:
ctest --test-dir build --output-on-failure -R "^(file_storage_promotion_test|file_storage_config_test|ssd_metrics_test|prefetch_teardown_test)$" ./scripts/code_format.sh --check --changed-lines --base origin/mainTest results:
io_uring + O_DIRECTmodes)Checklist
Signed-off-bytrailer certifying the DCO./scripts/code_format.shAI Assistance Disclosure