Repository navigation
Conversation
Bucket membership is hash-ordered twice. The master's offload mailbox (LocalSsdTaskMailbox::pending_offloads_, an unordered_map) hands each store its tasks in hash order, and FileStorage::OffloadObjects copies them into another unordered_map that GroupOffloadingKeysByBucket packs in hash order. A bucket is therefore a random subset of what was queued for the store between two heartbeats: the blocks of one prefix spread over many buckets, a prefix read opens many bucket files, and with LRU bucket eviction one read refreshes many unrelated keys. Two settings, both off by default, keep the order: - Master: --offload_ordered_buckets (offload_ordered_buckets in the config file; takes effect with enable_offload). MasterService passes it to LocalSsdManager, which hands it to every client's mailbox. The mailbox records the order of accepted offload enqueues. SetOffloadingAndTakePending first computes the delivery order (enqueue order, or the map's iteration order when off) and then moves the tasks out in one loop. A key removed before the take is skipped; a key removed and enqueued again goes at its last position. Remove/enqueue churn between two takes compacts the order list to one entry per queued key once it outgrows 2x the queue limit; the threshold saturates for huge limits. - Store: MOONCAKE_OFFLOAD_ORDERED_BUCKETS (FileStorageConfig:: ordered_buckets). OffloadObjects passes the delivery order to AllocateOffloadingBuckets, which packs keys in that order. The ungrouped tail deferred by one call still opens the next call's first bucket, ahead of the new keys, so keys queued on either side of a heartbeat share a bucket. With MOONCAKE_OFFLOAD_FLUSH_PARTIAL_BUCKETS=1 the tail is flushed in order in the same call; a replayed tail (kvcache-ai#5287) is unchanged. Only bucket membership follows the order: the layout inside a bucket file does not change. Off, the mailbox delivers the same tasks in the same order as before (it collects pointers to them first), and the grouping walks the map as before without building an order list, so buckets are unchanged. When a setting is on, that side logs one line at startup that asks for the other one; with one side only, buckets stay hash-ordered. No on-disk format or RPC change. Tests: - local_ssd_test: enqueue order across removals, re-enqueue and duplicates; churn compaction; the manager applies the setting to every client and a cancelled mirror leaves no gap; off delivers the same set. - storage_backend_test: packing follows the key order (unknown and repeated entries ignored, unlisted keys last); a bucket closes on the size limit and oversized objects are skipped in order; persisted keys are skipped; a deferred tail opens the next call's first bucket ahead of its keys; a carried key delivered again takes its new place; without an order the buckets are consecutive runs of the map's iteration order. - master_service_ssd_test: OffloadObjectHeartbeat returns tasks in PutEnd order with the flag, the same set without it. - master_service_config_test: the flag reaches MasterServiceConfig from MasterConfig directly and through the supervisor config. - file_storage_test: end to end with an embedded master, two heartbeats of six puts into four-key buckets give buckets [0..3], [4..7], [8..11] of the put order; off, every put still lands exactly once. - file_storage_config_test: default, valid and invalid values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Zhewen Li <zhewenli@inferact.ai>
Add --offload_ordered_buckets to the master offload parameters and MOONCAKE_OFFLOAD_ORDERED_BUCKETS to the bucket backend settings of the SSD offload deployment guide, with a section on what they change and where to set them, and describe the ordered delivery and packing next to the grouping strategy in the design notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Zhewen Li <zhewenli@inferact.ai>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem
Which objects share an SSD bucket is decided by hash order, twice:
LocalSsdTaskMailbox::pending_offloads_, anunordered_map) hands the store its tasks in hash order on eachOffloadObjectHeartbeat.FileStorage::OffloadObjectscopies them into anotherunordered_map, andGroupOffloadingKeysByBucketpacks buckets by walking that map.So a bucket holds a random subset of what was queued for the store between two heartbeats. Objects written together, such as the KV blocks of one prompt prefix, are spread over many buckets. Reading a prefix back opens many bucket files, and with
lrubucket eviction every read refreshes the recency of all the unrelated objects that happen to share those buckets.Because bucket LRU is per bucket, this also lets cold objects survive (they ride on hot neighbours) and lets a cold-bucket eviction take hot or mid-prefix blocks with it; since prefix matching stops at the first miss, one lost middle block invalidates the rest of the prefix.
Design
Two settings, both off by default. Each follows the existing convention of its side: a master flag, and a store environment variable read by
FileStorageConfig::FromEnvironment.--offload_ordered_buckets(offload_ordered_bucketsin the master config file; takes effect with--enable_offload=true). It is aMasterConfigfield next to the other offload flags and reachesMasterServiceConfigthrough the supervisor and wrapped configs.MasterServicepasses it toLocalSsdManager, which hands it to every client's mailbox.EnqueueOffloadinserts into the map exactly as before. With the setting on, it also appends the task's scoped key to an order list.SetOffloadingAndTakePendingfirst computes the delivery order as a list of pointers to the map's entries: enqueue order when on, the map's iteration order when off. It then moves the tasks out in one loop over that list.RemoveOffload,CancelOffloadsIfAllPending) is skipped, and a key removed and queued again goes at its last position.2 * offloading_queue_limit + 64entries, it is compacted to one entry per queued key. Its memory stays bounded and the cost is amortized O(1) per enqueue. The threshold saturates instead of overflowing for very large limits.MOONCAKE_OFFLOAD_ORDERED_BUCKETS, read intoFileStorageConfig::ordered_buckets.OffloadObjectspasses the delivery order toBucketStorageBackend::AllocateOffloadingBuckets(new optionalkey_orderargument), andGroupOffloadingKeysByBucketpacks keys in that order. Keys the order does not list come after it, in the map's iteration order. Order entries that are not objects are ignored.MOONCAKE_OFFLOAD_FLUSH_PARTIAL_BUCKETS=0(default), the partial last bucket of one heartbeat is deferred as before and opens the next heartbeat's first bucket, ahead of the new keys. Objects queued on either side of a heartbeat boundary still share a bucket. A carried key that the next heartbeat delivers again (re-put while deferred) loses its pooled copy as before and takes its new place in the order. WithMOONCAKE_OFFLOAD_FLUSH_PARTIAL_BUCKETS=1([Store] Add opt-in same-cycle flush for partial SSD offload buckets #4673), the tail is flushed in order in the same cycle. A tail replayed without new tasks ([Store] Flush deferred bucket tails without new offload tasks #5287) is written as one bucket, as before.FileStoragehands each bucket toBatchOffloadas anunordered_map, andBuildBucketwrites it in that map's order.Read paths, the bucket file format and RPCs are unchanged.
Settings
--offload_ordered_buckets(offload_ordered_bucketsin the config file)falseMOONCAKE_OFFLOAD_ORDERED_BUCKETS0Each side logs one line at startup when its setting is on, naming the setting the other side needs. With only one side on, nothing breaks, but buckets stay hash-ordered. Both are documented in the SSD offload deployment guide: the flag in the "Master Offload Parameters" table, the variable in the bucket backend table, and a short "Ordered bucket packing" section.
Compatibility and cost
FileStoragebuilds no key list. Buckets are unchanged;BucketStorageBackend_UnorderedPackingKeepsHashOrderandUnorderedOffloadsDeliverTheSameSetpin this.OffloadObjectscall: a vector with a copy of each delivered storage key. In the grouping, a vector of entry pointers and a hash set of entry pointers, both sized to the call's objects. These are small next to the call's existing per-key maps (storage_object_sizes,task_by_storage_key).Interaction with other offload PRs
AllocateOffloadingBucketsreturnsbuckets_keys), and [Store] Add opt-in bounded parallel bucket offload writes #5339 parallelizes writing those buckets, so parallel workers write the same ordered buckets. There is no logical conflict. The textual conflicts are three places where both PRs append next to each other: the end ofFileStorageConfig::FromEnvironment(file_storage_config.cpp), the environment variable list infile_storage_config_test.cpp, and adjacentTEST_Fregistrations infile_storage_test.cpp. Keeping both sides resolves each.task_id,taken_offloads_). With this PR there is still exactly one take loop, over the delivery-order list, so the tagging goes into that loop (entry->firstis the scoped key,entry->secondthe task). Both PRs also add a second constructor parameter toLocalSsdTaskMailbox,ClientRecordandLocalSsdManager([Store] Keep keys removed during an in-flight offload removed #5712 a TTL, this PR the ordering flag) and edit thelocal_ssd_manager_initializer in theMasterServiceconstructor; the merge takes both parameters.OffloadManagerfromMasterService), if it lands: conflicts inmaster_config.h, theMasterServiceconstructor (thelocal_ssd_manager_initializer, and the offload block where this PR logs its startup line) andmaster_service_ssd_test.cpp, because [Store] Extract self-contained OffloadManager from MasterService #5760 moves the offload fields ofMasterServiceConfiginto anOffloadConfig. The merge movesoffload_ordered_bucketsintoOffloadConfigand buildsLocalSsdManagerfrom it.AllocateOffloadingBuckets/GroupOffloadingKeysByBucketsignatures (aflush_previous_carryoverargument) and the grouping loop. Whichever lands second rebases those hunks and the call inFileStorage::OffloadObjects; the order handling is independent of the carryover flush.file_storage_test.cpp([Store] Sub-batch scheduling for buffered SSD offload writes and parallel reads #5020 needs a rebase onmainby itself as well).Not included
MC_OFFLOAD_READ_KEY_ORDERin our fork) is not part of this PR. It orders the keys of a multi-keyLOCAL_DISKread before splitting them into bounded chunks. Upstream sends all keys for one owner in a singlebatch_get_offload_objectRPC, and the owner already groups that request by bucket (ReadBucketValues). Without read chunking, key order on the read side does not change how many buckets are read, so there is nothing meaningful to port on its own.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?
New tests:
local_ssd_testOrderedOffloadsAreDeliveredInEnqueueOrderlocal_ssd_testOrderedOffloadsSurviveChurnCompactionlocal_ssd_testOrderedOffloadsApplyToEveryClientLocalSsdManagerhands the setting to every client's mailbox, and a cancelled mirror leaves no gaplocal_ssd_testUnorderedOffloadsDeliverTheSameSetstorage_backend_testBucketStorageBackend_OrderedPackingFollowsKeyOrderstorage_backend_testBucketStorageBackend_OrderedPackingTruncatesBySizebucket_size_limitor when it is exactly full, and that key opens the next bucket. An object over the limit is skipped without breaking the orderstorage_backend_testBucketStorageBackend_OrderedPackingSkipsPersistedKeysstorage_backend_testBucketStorageBackend_OrderedPackingCarriesTailAcrossCallsstorage_backend_testBucketStorageBackend_OrderedPackingRedrainedCarriedKeyFileStoragedoes) takes its new place in the order, after the remaining carried keystorage_backend_testBucketStorageBackend_UnorderedPackingKeepsHashOrdermaster_service_ssd_testOrderedOffloadsReachTheStoreInPutOrderOffloadObjectHeartbeatreturns tasks inPutEndorder withoffload_ordered_buckets; off, the same setmaster_service_config_testOffloadOrderedBucketsPropagatesMasterServiceConfigfromMasterConfig, directly and through the supervisor configfile_storage_testOrderedBucketsPackPutsInOrderAcrossHeartbeatsFileStoragewith the variable): two heartbeats of 6 puts into 4-key buckets give buckets {0..3}, {4..7}, {8..11} of the put order, and every key gets aLOCAL_DISKreplicafile_storage_testUnorderedBucketsStillOffloadEveryPutfile_storage_config_test(extended)MOONCAKE_OFFLOAD_ORDERED_BUCKETS: default off,1on, an invalid value warns and stays offRevert check: with the grouping forced to ignore
key_orderand the mailbox take forced onto its unordered branch, all 10 ordered-mode tests above fail (3 inlocal_ssd_test, 5 instorage_backend_test, 1 inmaster_service_ssd_test, 1 infile_storage_test), and every off-mode test still passes.Test commands:
Test results:
Results on an aarch64 host (Ubuntu 24.04, GCC 13, kernel with 64 KiB pages, GPUs present),
USE_CUDA=OFF:local_ssd_teststorage_backend_testOffsetAllocatorReadPath_*tests were excluded (see below)file_storage_testUringStagingBufferUnpinnedOnDestruction, environment)file_storage_config_testmaster_service_ssd_testmaster_service_config_testmooncake-storectest (--parallel 8)The ctest failures:
storage_backend_test(environment): theOffsetAllocatorReadPath_*tests allocate guard pages withmprotectat 4 KiB granularity. On a 64 KiB-page kernel that returnsEINVAL, so the helper throwsstd::bad_alloc: 10 of them fail and_ConcurrentEviction_Uringaborts the binary. With those 12 filtered out, the other 147 tests pass.transfer_task_testBatchGetOffloadObjectCopiesPinnedHostToGpu(environment): the test is built because CMake finds the CUDA toolkit, and it runs because a GPU is present. The store itself is built withUSE_CUDA=OFF, soPinnedBufferPool::AllocatePinnedreturns no pinned buffer.pybind_client_testGetBufferRemoteReaderHealsOwnersDanglingLocalDiskReplica(flaky under load): it failed once in the parallel run, at its sanity read on the fixed ports 17813/17814 while other builds and tests ran on the host, and passed 3/3 when rerun alone. It passed in the same ctest on the previous revision of this branch and on the other branches tested alongside../scripts/code_format.sh --checkagainstmain(clang-format 20.1.8) andpre-commit run --files <changed files>pass. The docs build with Sphinx without warnings, and the new cross-references resolve.Data
End-to-end before/after numbers (bucket reads per prefix read, keys used per bucket read, SSD read throughput) on a real deployment with this exact patch are still being collected. They will be added here; until then this PR is a draft.
Checklist
Signed-off-bytrailer certifying the DCO./scripts/code_format.shAI Assistance Disclosure
Claude Code (Anthropic) was used to port the change from our fork onto current
main(adapting it to #5287 and to the existing master-flag and config-from-environment conventions), write the unit and end-to-end tests, run the test suites, and draft this description. The submitter is responsible for the change.🤖 Generated with Claude Code