[Add] L2 Prefetch Controller and StorageManager integration#2667
[Add] L2 Prefetch Controller and StorageManager integration#2667ApostaC merged 2 commits intoLMCache:devfrom
Conversation
Signed-off-by: ApostaC <yihua98@uchicago.edu>
Summary of ChangesHello, 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 enhances the caching system by introducing an L2 Prefetch Controller, enabling asynchronous prefetching of KV cache data from L2 storage into L1 memory. This integration with the StorageManager aims to improve performance by proactively loading data, reducing latency for subsequent requests. The changes include a new event-driven controller, a flexible prefetch policy, and critical updates to L1 and L2 management to ensure data consistency and efficient resource utilization during prefetch operations. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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 by creating a comment using either
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant new feature, the PrefetchController, for asynchronously loading data from L2 cache into L1. The implementation is comprehensive, including a detailed design document, robust controller logic with a state machine, and thorough integration with the existing StorageManager. The addition of extensive unit and integration tests is excellent and covers many edge cases. My feedback includes a few suggestions to improve the robustness of the tests by replacing fixed-time sleeps with condition polling, and a minor refactoring for code clarity. Overall, this is a high-quality contribution.
| if handle.request_id != -1: | ||
| l2_r = self._prefetch_controller.query_prefetch_result(handle.request_id) | ||
|
|
||
| if l2_r is None: | ||
| return None | ||
| l2_result = l2_r # Just to make linter happy |
There was a problem hiding this comment.
The comment # Just to make linter happy suggests a potential code smell or a workaround for a linter issue. This part of the code can be refactored for better clarity and to remove the need for such a comment.
| if handle.request_id != -1: | |
| l2_r = self._prefetch_controller.query_prefetch_result(handle.request_id) | |
| if l2_r is None: | |
| return None | |
| l2_result = l2_r # Just to make linter happy | |
| if handle.request_id != -1: | |
| l2_hits = self._prefetch_controller.query_prefetch_result(handle.request_id) | |
| if l2_hits is None: | |
| return None | |
| l2_result = l2_hits |
| # Brief sleep to let StoreController release read locks | ||
| # after L2 store completion, then clear L1 | ||
| time.sleep(0.05) |
There was a problem hiding this comment.
Using time.sleep() in tests can introduce flakiness. It's more robust to poll for the specific condition you're waiting for. In this case, you're waiting for the StoreController to release L1 read locks so that sm.clear() can successfully remove the objects. You can use the existing wait_for_condition helper to poll the lock state of the keys.
| # Brief sleep to let StoreController release read locks | |
| # after L2 store completion, then clear L1 | |
| time.sleep(0.05) | |
| # Wait for StoreController to release read locks after L2 store completion. | |
| ok = wait_for_condition( | |
| lambda: all( | |
| not sm._l1_manager.get_object_state(k).read_lock.is_locked() | |
| for k in keys | |
| if sm._l1_manager.get_object_state(k) is not None | |
| ), | |
| timeout=5.0, | |
| ) | |
| assert ok, "StoreController should have released L1 read locks" |
| # Brief sleep to let StoreController release read locks | ||
| # after L2 store completion, then clear L1 | ||
| time.sleep(0.05) |
There was a problem hiding this comment.
Similar to the other test, using time.sleep() can make the test flaky. It's more robust to poll for the condition that the StoreController has released the L1 read locks on the written keys before clearing L1.
| # Brief sleep to let StoreController release read locks | |
| # after L2 store completion, then clear L1 | |
| time.sleep(0.05) | |
| # Wait for StoreController to release read locks after L2 store completion. | |
| ok = wait_for_condition( | |
| lambda: all( | |
| not sm._l1_manager.get_object_state(k).read_lock.is_locked() | |
| for k in keys_to_write | |
| if sm._l1_manager.get_object_state(k) is not None | |
| ), | |
| timeout=5.0, | |
| ) | |
| assert ok, "StoreController should have released L1 read locks" |
Signed-off-by: ApostaC <yihua98@uchicago.edu>
…2667) * finish L2 prefetch controller Signed-off-by: ApostaC <yihua98@uchicago.edu> Signed-off-by: Ofer Kiselov Nahman <ofer.kiselovnahman@weka.io>
…2667) * finish L2 prefetch controller Signed-off-by: ApostaC <yihua98@uchicago.edu>
…2667) * finish L2 prefetch controller Signed-off-by: ApostaC <yihua98@uchicago.edu>
…2667) * finish L2 prefetch controller Signed-off-by: ApostaC <yihua98@uchicago.edu> Signed-off-by: shaoxiawjc <wjc2800@163.com>
…2667) * finish L2 prefetch controller Signed-off-by: ApostaC <yihua98@uchicago.edu> Signed-off-by: Aaron Wu <aaron.wu@dell.com>
…2667) * finish L2 prefetch controller Signed-off-by: ApostaC <yihua98@uchicago.edu>
…2667) * finish L2 prefetch controller Signed-off-by: ApostaC <yihua98@uchicago.edu>
Summary
select.poll()on adapter eventfds, max-in-flight request limiting, and comprehensive L1/L2 lock management.submit_prefetch_tasknow checks L1 for prefix hits first, then delegates remaining keys to PrefetchController for L2 prefetch.query_prefetch_statuscombines L1 + L2 results with latency logging.L1Manager.finish_write_and_reserve_read(): Atomic write-to-read lock transition, preventing eviction between L2 load completion and read lock acquisition.L1Manager.clear(force=False): Safe clear that skips locked objects by default, protecting in-flight store/prefetch operations.l2_adapters/DESIGN.mddocumenting the full store/prefetch controller architecture, data flows, lock invariants, and assumptions.Key Design Decisions
trim_load_plan_to_prefix().is_temporary=Trueto allow eviction controller reclaim if needed.submit_unlockis never retried by the controller — the adapter must guarantee eventual success internally.Files Changed
storage_controllers/prefetch_controller.pystorage_controllers/prefetch_policy.pystorage_controllers/__init__.pystorage_manager.pyl1_manager.pyfinish_write_and_reserve_read(), safeclear(force)l2_adapters/base.pyl2_adapters/DESIGN.mdtests/.../test_prefetch_controller.pytests/.../test_distributed_storage_manager.pyTest Plan
pytest -xvs tests/v1/distributed/test_prefetch_controller.py— 18 tests covering lifecycle, single/multi adapter prefetch, overlap dedup, no-hits, max-in-flight queuing, partial load failure, query result pop semanticspytest -xvs tests/v1/distributed/test_distributed_storage_manager.py— 5 new integration tests: L2 round-trip, mixed L1/L2 hits, no L2 hits, partial prefix, L1+L2 continuationpytest -xvs tests/v1/distributed/— all 208 tests pass