Skip to content

Add fragmentation-aware allocation strategy for Mooncake Store#2797

Open
Lorry1024 wants to merge 4 commits into
kvcache-ai:mainfrom
Lorry1024:ccf-fragmentation-aware-allocation
Open

Add fragmentation-aware allocation strategy for Mooncake Store#2797
Lorry1024 wants to merge 4 commits into
kvcache-ai:mainfrom
Lorry1024:ccf-fragmentation-aware-allocation

Conversation

@Lorry1024

Copy link
Copy Markdown

Summary

This PR adds an opt-in Mooncake Store allocation strategy named fragmentation_aware for mixed-size KVCache workloads. The strategy keeps bounded candidate sampling, but ranks sampled segments by whether their largest contiguous free region can satisfy the current request before considering aggregate free ratio.

Why

In long-running Store pools, aggregate free space can be split into fragmented holes. A segment may report a higher total free ratio while failing a large allocation because no contiguous region is large enough. This creates avoidable allocation attempts and fallback pressure.

Changes

  • Add AllocationStrategyType::FRAGMENTATION_AWARE.
  • Add FragmentationAwareAllocationStrategy.
  • Wire --allocation_strategy=fragmentation_aware.
  • Add deterministic fragmentation and preferred-segment tests.
  • Add the strategy to allocation_strategy_bench.
  • Document design and deployment usage.

Validation

  • git diff --check
  • git apply --check against current upstream
  • deterministic fragmentation simulation
  • extended ranking and boundary simulation
  • topic-aligned Store scalability simulation

Boundaries

The default allocation strategy remains unchanged. This PR does not redesign SGLang HiCache, RDMA transport, or Mooncake HA. Full upstream CI, RDMA validation, and real SGLang HiCache benchmark should still be run in a production-like environment before claiming end-to-end throughput gains.

@github-actions github-actions Bot added documentation Improvements or additions to documentation run-ci Store labels Jul 8, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@yokinoshitayoki

Copy link
Copy Markdown
Collaborator

Thanks for the proposal. One concern is that production workloads usually have only one or two object sizes, so the object-size distribution is much narrower than the mixed-size workload assumed here.

Given that, fragmentation pressure may be limited in practice, so maybe it's not necessary to add and maintain a separate fragmentation_aware allocation strategy for now.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 92.48555% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mooncake-store/include/allocation_strategy.h 91.45% 10 Missing ⚠️
...ake-store/benchmarks/allocation_strategy_bench.cpp 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Lorry1024 Lorry1024 marked this pull request as ready for review July 10, 2026 13:45
Copilot AI review requested due to automatic review settings July 10, 2026 13:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in Mooncake Store allocation strategy (fragmentation_aware) that favors segments with a fit-capable largest contiguous free region (to reduce allocation failures under fragmentation), while preserving the existing bounded sampling + fallback behavior.

Changes:

  • Introduces AllocationStrategyType::FRAGMENTATION_AWARE and FragmentationAwareAllocationStrategy, and wires it through config/CLI and strategy factory.
  • Adds unit tests and benchmark coverage for the new strategy.
  • Documents the strategy’s intended use cases, ranking logic, and deployment flag.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
mooncake-store/include/allocation_strategy.h Implements FragmentationAwareAllocationStrategy and registers it in CreateAllocationStrategy.
mooncake-store/include/types.h Adds AllocationStrategyType::FRAGMENTATION_AWARE.
mooncake-store/include/master_config.h Parses allocation_strategy=fragmentation_aware and updates validation messaging.
mooncake-store/src/master.cpp Updates --allocation_strategy flag help text to include fragmentation_aware.
mooncake-store/tests/allocation_strategy_test.cpp Expands parameterized coverage and adds targeted fragmentation/preferred-segment tests.
mooncake-store/benchmarks/allocation_strategy_bench.cpp Adds the new strategy to benchmark naming and benchmark matrices.
docs/source/design/mooncake-store.md Documents the new strategy’s design and selection guidance.
docs/source/deployment/mooncake-store-deployment-guide.md Documents the deployment flag usage for fragmentation_aware.
.github/workflows/ci.yml Adds a disk-reclaim step before Go store binding integration tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 501 to 504
SSD_FREE_RATIO_FIRST, // SSD free-ratio-first allocation
LOCAL_FIRST // Prefer local host before ordered remote fallback
LOCAL_FIRST, // Prefer local host before ordered remote fallback
FRAGMENTATION_AWARE // Fragmentation-aware allocation
};
A fragmentation-aware variant for mixed-size KV cache workloads. It uses the same bounded candidate sampling shape as `free_ratio_first`, but adds a contiguous-fit signal before ranking by score:

1. **Preferred segment phase**: Same as `random` and `free_ratio_first`; explicit preferred segments are tried before sampled candidates.
2. **Sampling phase**: Randomly picks a starting index and takes `min(6*remaining_replicas, total_segments)` consecutive segments as candidates.

@yokinoshitayoki yokinoshitayoki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for continuing to work on this, but I don’t think we should merge this PR as-is.

My main concern from the previous comment still stands: our production workloads typically use only one or two object sizes, so the mixed-size fragmentation scenario targeted by fragmentation_aware does not match our current production workload well.

Also, the CI disk cleanup change seems unrelated to the allocation strategy itself and should not be bundled into this PR.

Given the current evidence, I’d prefer not to add another allocation strategy. If we want to revisit this later, I think we may need to first provide representative production traces or benchmarks showing a concrete fragmentation problem under our workload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/Build documentation Improvements or additions to documentation run-ci Store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants