Skip to content

[1/4] Bitmap for L2 storage in MP mode #2563

Merged
ApostaC merged 5 commits intoLMCache:devfrom
ApostaC:local-dev/l2-adapter-1
Feb 26, 2026
Merged

[1/4] Bitmap for L2 storage in MP mode #2563
ApostaC merged 5 commits intoLMCache:devfrom
ApostaC:local-dev/l2-adapter-1

Conversation

@ApostaC
Copy link
Copy Markdown
Contributor

@ApostaC ApostaC commented Feb 7, 2026

What this PR does / why we need it:

Part of #2562

Special notes for your reviewers:

If applicable:

  • this PR contains user facing changes - docs added
  • this PR contains unit tests

Signed-off-by: ApostaC <yihua98@uchicago.edu>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ApostaC, 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 introduces a fundamental C++ Bitmap utility class designed for efficient bit-level tracking, specifically intended for managing the state of L2 storage operations within a multi-process environment. The implementation includes methods for setting, clearing, testing individual bits, and performing advanced bit counting operations like popcount, clz, and clo, along with bitwise AND. To facilitate its use across the system, the Bitmap class is seamlessly integrated with Python through pybind11 bindings. The changes are accompanied by a thorough suite of unit tests to validate the correctness and robustness of the new bitmap functionality.

Highlights

  • New Bitmap Class: A new C++ Bitmap class has been introduced to efficiently track the state of L2 storage operation results, providing core bit manipulation functionalities.
  • Python Bindings: The new Bitmap class is exposed to Python via pybind11, allowing Python-based components to utilize its functionalities.
  • Comprehensive Unit Tests: Extensive unit tests have been added for the Bitmap class using pytest, covering various scenarios including bit setting, clearing, counting, and bitwise operations, especially for sizes not multiples of 8.
  • Build System Integration: The setup.py script has been updated to include the new bitmap.cpp source file in both CUDA and ROCm extensions, ensuring proper compilation and linking.

🧠 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
  • csrc/storage_manager/bitmap.cpp
    • Added a new C++ source file implementing the Bitmap class.
    • Implemented methods for set, clear, test, popcount, clz (count leading zeros), clo (count leading ones), bitwise AND (operator&), and to_string conversion.
  • csrc/storage_manager/bitmap.h
    • Added a new header file defining the Bitmap class interface with Doxygen-style comments for clarity.
  • csrc/storage_manager/pybind.cpp
    • Included the new bitmap.h header.
    • Added using lmcache::storage_manager::Bitmap;.
    • Exposed the Bitmap class and its methods to Python using pybind11, including constructor, set, clear, test, popcount, count_leading_zeros, count_leading_ones, __and__, and __repr__.
  • setup.py
    • Updated storage_manager_sources in both cuda_extension and rocm_extension functions to include csrc/storage_manager/bitmap.cpp for compilation.
  • tests/v1/multiprocess/test_bitmap.py
    • Added a new Python unit test file for the Bitmap class using pytest.
    • Included tests for set, clear, test operations across various bitmap sizes.
    • Added tests for popcount to verify correct counting of set bits.
    • Implemented tests for clz and clo functionalities.
    • Provided tests for bitwise AND operations, including scenarios with different bitmap sizes.
    • Added tests for the to_string representation of the bitmap.
    • Included specific tests to ensure correct behavior for bitmaps whose sizes are not multiples of 8.
Activity
  • This pull request is part of a larger effort tracked by issue Support L2 storage in MP mode #2562.
  • No human activity (comments, reviews, etc.) has been recorded yet for this pull request.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 introduces a Bitmap class to support L2 storage in multiprocess mode, complete with C++ implementation, pybind11 bindings, and unit tests. A critical integer overflow vulnerability was identified in the Bitmap constructor's memory allocation logic, which can lead to out-of-bounds memory access and denial-of-service conditions for large bitmap sizes. Additionally, the review suggests improvements for C++ maintainability and performance, including refactoring complex functions and optimizing a string conversion method, and strengthening assertions in the Python tests.

Comment thread csrc/storage_manager/bitmap.cpp Outdated
Comment thread csrc/storage_manager/bitmap.cpp
Comment thread csrc/storage_manager/bitmap.cpp Outdated
Comment thread csrc/storage_manager/bitmap.cpp Outdated
Comment thread csrc/storage_manager/bitmap.cpp
Comment thread csrc/storage_manager/bitmap.h
Comment thread tests/v1/native_storage_ops/test_bitmap.py
Comment thread tests/v1/native_storage_ops/test_bitmap.py
@ApostaC ApostaC mentioned this pull request Feb 7, 2026
8 tasks
@ApostaC ApostaC requested review from KuntaiDu and YaoJiayi February 9, 2026 01:02
@ApostaC ApostaC added the full Run comprehensive tests on this PR label Feb 9, 2026
Comment thread csrc/storage_manager/bitmap.cpp
Comment thread csrc/storage_manager/bitmap.cpp
Signed-off-by: Yihua Cheng <yihua98@uchicago.edu>
Signed-off-by: ApostaC <yihua98@uchicago.edu>
Copy link
Copy Markdown
Contributor

@KuntaiDu KuntaiDu left a comment

Choose a reason for hiding this comment

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

Code is straightforward for me.

@ApostaC
Copy link
Copy Markdown
Contributor Author

ApostaC commented Feb 26, 2026

Going to merge this as we discussed offline.

@ApostaC ApostaC merged commit 743c5a7 into LMCache:dev Feb 26, 2026
24 checks passed
sammshen pushed a commit to sammshen/LMCache that referenced this pull request Mar 1, 2026
* [add] bitmap module

Signed-off-by: ApostaC <yihua98@uchicago.edu>

* adjust the cpp implementation and add pyi tests

Signed-off-by: ApostaC <yihua98@uchicago.edu>
hlin99 pushed a commit to hlin99/LMCache that referenced this pull request Mar 2, 2026
* [add] bitmap module

Signed-off-by: ApostaC <yihua98@uchicago.edu>

* adjust the cpp implementation and add pyi tests

Signed-off-by: ApostaC <yihua98@uchicago.edu>
oferki pushed a commit to oferki/LMCache that referenced this pull request Mar 3, 2026
* [add] bitmap module

Signed-off-by: ApostaC <yihua98@uchicago.edu>

* adjust the cpp implementation and add pyi tests

Signed-off-by: ApostaC <yihua98@uchicago.edu>
Signed-off-by: Ofer Kiselov Nahman <ofer.kiselovnahman@weka.io>
oferki pushed a commit to oferki/LMCache that referenced this pull request Mar 3, 2026
* [add] bitmap module

Signed-off-by: ApostaC <yihua98@uchicago.edu>

* adjust the cpp implementation and add pyi tests

Signed-off-by: ApostaC <yihua98@uchicago.edu>
mauryaavinash95 pushed a commit to mauryaavinash95/LMCache that referenced this pull request Mar 7, 2026
* [add] bitmap module

Signed-off-by: ApostaC <yihua98@uchicago.edu>

* adjust the cpp implementation and add pyi tests

Signed-off-by: ApostaC <yihua98@uchicago.edu>
shaoxiawjc pushed a commit to shaoxiawjc/LMCache that referenced this pull request Mar 11, 2026
* [add] bitmap module

Signed-off-by: ApostaC <yihua98@uchicago.edu>

* adjust the cpp implementation and add pyi tests

Signed-off-by: ApostaC <yihua98@uchicago.edu>
Signed-off-by: shaoxiawjc <wjc2800@163.com>
realAaronWu pushed a commit to realAaronWu/LMCache that referenced this pull request Mar 20, 2026
* [add] bitmap module

Signed-off-by: ApostaC <yihua98@uchicago.edu>

* adjust the cpp implementation and add pyi tests

Signed-off-by: ApostaC <yihua98@uchicago.edu>
Signed-off-by: Aaron Wu <aaron.wu@dell.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full Run comprehensive tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants