Skip to content

[HiCache] Storage Refactoring#9797

Merged
hnyls2002 merged 5 commits intomainfrom
xiezhq-hicache-storage-refactor
Aug 31, 2025
Merged

[HiCache] Storage Refactoring#9797
hnyls2002 merged 5 commits intomainfrom
xiezhq-hicache-storage-refactor

Conversation

@xiezhq-hermann
Copy link
Copy Markdown
Collaborator

@xiezhq-hermann xiezhq-hermann commented Aug 29, 2025

Motivation

This refactor uses a different sync mechanism across TP workers and simplifies sync logics. It also fix the problem mentioned in #9045, #9302 and #9643.

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @xiezhq-hermann, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the storage and caching mechanisms within HiCache, primarily focusing on improving the efficiency and simplicity of data synchronization and memory management in distributed environments. The changes aim to address existing issues and enhance the overall performance of storage operations by streamlining internal processes and optimizing resource handling.

Highlights

  • Simplified Synchronization Logic: The pull request refactors the synchronization mechanisms across Tensor Parallel (TP) workers by removing dedicated groups for prefetch I/O and backup, and streamlining the backup acknowledgment process. This simplifies the overall sync logic for HiCache storage operations.
  • Centralized Host Memory Release: A new host_mem_release_queue and append_host_mem_release method have been introduced to centralize and defer the release of host memory. This change aims to improve memory management efficiency by batching memory deallocation operations.
  • Optimized Storage Control Queue Processing: The hiradix_cache now combines the processing of prefetch revoke, backup acknowledgments, and host memory release into a single drain_storage_control_queues method. This reduces the overhead of inter-process communication and Python-level synchronization in distributed environments.
  • Refined Prefetching and Backup Batching: The logic for prefetching and backing up pages has been updated to consistently use a storage_batch_size (set to 128 pages), improving the granularity and efficiency of I/O operations. The storage hit query mechanism has also been enhanced for better batch processing.
  • Removed Redundant Storage State Tracking: The backuped_storage attribute has been removed from TreeNode in radix_cache.py, indicating a shift away from tracking storage backup status at the individual node level, likely in favor of a more centralized or implicit mechanism.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the storage synchronization mechanism in HiCache, simplifying the logic and reducing synchronization overhead between TP workers. The changes include removing dedicated process groups for I/O and backup, and introducing a new queue-based mechanism for releasing host memory. The logic for querying storage hits and handling backup acknowledgements has also been streamlined.

My review focuses on potential performance implications of the refactoring and opportunities for further simplification. I've identified a hardcoded batch size that might not be optimal for all backends, and an inefficient data handling pattern for the new memory release queue. Overall, the refactoring is a good step towards a cleaner and more efficient implementation.

Comment thread python/sglang/srt/managers/cache_controller.py
Comment thread python/sglang/srt/managers/cache_controller.py
@xiezhq-hermann
Copy link
Copy Markdown
Collaborator Author

adding @pansicheng as a co-author

@pansicheng
Copy link
Copy Markdown
Collaborator

LGTM

@xiezhq-hermann xiezhq-hermann added the ready-to-merge The PR is ready to merge after the CI is green. label Aug 31, 2025
@hnyls2002 hnyls2002 merged commit 8b6966d into main Aug 31, 2025
93 of 100 checks passed
@hnyls2002 hnyls2002 deleted the xiezhq-hicache-storage-refactor branch August 31, 2025 14:58
MahmoudAshraf97 pushed a commit to MahmoudAshraf97/sglang that referenced this pull request Sep 8, 2025
Co-authored-by: pansicheng <27603155+pansicheng@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

high priority ready-to-merge The PR is ready to merge after the CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants