Using shm to reduce memory copy while using remote connector#2601
Using shm to reduce memory copy while using remote connector#2601maobaolong merged 8 commits intoLMCache:devfrom
Conversation
Summary of ChangesHello @maobaolong, 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 LMCache's memory management by integrating POSIX shared memory (SHM) for CPU-pinned memory allocations. This integration aims to optimize data transfer by reducing memory copy overhead, especially when using remote connectors. The changes include C++ implementations for SHM-backed pinned memory, their exposure to Python, and their seamless integration into the existing memory allocation framework. A new 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: a remote connector that leverages POSIX shared memory for inter-process communication, implemented with C++ allocation functions, a C++ worker process for file I/O, and a Python connector. However, a critical security vulnerability has been identified in the shm_file_worker process, allowing remote arbitrary file read/write (path traversal) and arbitrary memory access via integer overflows. This is compounded by the worker binding to all network interfaces without authentication, potentially leading to full host system compromise. Beyond these critical security concerns, further improvements are needed for robustness in error handling, memory access, and adherence to Python style conventions.
|
small comment LGTM! |
|
@sammshen Thanks for the review, abstracted a helper method, PTAL. |
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
- Fix integer overflow vulnerabilities in shm_file_worker by adding robust boundary checks - Change default network binding from 0.0.0.0 to 127.0.0.1 for better security - Add GIL release for free_shm_pinned_ptr to prevent blocking Python interpreter - Move all imports to the top of test files for better code organization Signed-off-by: baoloongmao <baoloongmao@tencent.com>
Signed-off-by: baoloongmao <baoloongmao@tencent.com>
…#2601) * Shm and demo Signed-off-by: baoloongmao <baoloongmao@tencent.com> * support set worker addr to verify in container env Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add missing file Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix unit Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add a shm memory example Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Move to right folder Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix security vulnerabilities based on Gemini code review - Fix integer overflow vulnerabilities in shm_file_worker by adding robust boundary checks - Change default network binding from 0.0.0.0 to 127.0.0.1 for better security - Add GIL release for free_shm_pinned_ptr to prevent blocking Python interpreter - Move all imports to the top of test files for better code organization Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Address comment Signed-off-by: baoloongmao <baoloongmao@tencent.com> --------- Signed-off-by: baoloongmao <baoloongmao@tencent.com>
…#2601) * Shm and demo Signed-off-by: baoloongmao <baoloongmao@tencent.com> * support set worker addr to verify in container env Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add missing file Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix unit Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add a shm memory example Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Move to right folder Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix security vulnerabilities based on Gemini code review - Fix integer overflow vulnerabilities in shm_file_worker by adding robust boundary checks - Change default network binding from 0.0.0.0 to 127.0.0.1 for better security - Add GIL release for free_shm_pinned_ptr to prevent blocking Python interpreter - Move all imports to the top of test files for better code organization Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Address comment Signed-off-by: baoloongmao <baoloongmao@tencent.com> --------- Signed-off-by: baoloongmao <baoloongmao@tencent.com>
…#2601) * Shm and demo Signed-off-by: baoloongmao <baoloongmao@tencent.com> * support set worker addr to verify in container env Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add missing file Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix unit Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add a shm memory example Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Move to right folder Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix security vulnerabilities based on Gemini code review - Fix integer overflow vulnerabilities in shm_file_worker by adding robust boundary checks - Change default network binding from 0.0.0.0 to 127.0.0.1 for better security - Add GIL release for free_shm_pinned_ptr to prevent blocking Python interpreter - Move all imports to the top of test files for better code organization Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Address comment Signed-off-by: baoloongmao <baoloongmao@tencent.com> --------- Signed-off-by: baoloongmao <baoloongmao@tencent.com>
…#2601) * Shm and demo Signed-off-by: baoloongmao <baoloongmao@tencent.com> * support set worker addr to verify in container env Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add missing file Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix unit Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add a shm memory example Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Move to right folder Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix security vulnerabilities based on Gemini code review - Fix integer overflow vulnerabilities in shm_file_worker by adding robust boundary checks - Change default network binding from 0.0.0.0 to 127.0.0.1 for better security - Add GIL release for free_shm_pinned_ptr to prevent blocking Python interpreter - Move all imports to the top of test files for better code organization Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Address comment Signed-off-by: baoloongmao <baoloongmao@tencent.com> --------- Signed-off-by: baoloongmao <baoloongmao@tencent.com> Signed-off-by: shaoxiawjc <wjc2800@163.com>
…#2601) * Shm and demo Signed-off-by: baoloongmao <baoloongmao@tencent.com> * support set worker addr to verify in container env Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add missing file Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix unit Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Add a shm memory example Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Move to right folder Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Fix security vulnerabilities based on Gemini code review - Fix integer overflow vulnerabilities in shm_file_worker by adding robust boundary checks - Change default network binding from 0.0.0.0 to 127.0.0.1 for better security - Add GIL release for free_shm_pinned_ptr to prevent blocking Python interpreter - Move all imports to the top of test files for better code organization Signed-off-by: baoloongmao <baoloongmao@tencent.com> * Address comment Signed-off-by: baoloongmao <baoloongmao@tencent.com> --------- Signed-off-by: baoloongmao <baoloongmao@tencent.com> Signed-off-by: Aaron Wu <aaron.wu@dell.com>
What this PR does / why we need it:
This pull request introduced POSIX shared memory (SHM) for CPU-pinned memory allocations. This integration aims to optimize data transfer by reducing memory copy overhead, especially when using remote connectors. The changes include C++ implementations for SHM-backed pinned memory.
This PR also introduced a new demonstrate ShmFileConnector leverages this SHM capability, allowing a C++ worker process to perform file I/O directly on shared memory regions, thereby streamlining data movement between LMCache and external storage.
Special notes for your reviewers:
If applicable: