Skip to content

C API: Add rocksdb_memory_allocator_create_custom#14420

Open
edmanlog123 wants to merge 1 commit intofacebook:mainfrom
edmanlog123:feature/c-api-custom-allocator
Open

C API: Add rocksdb_memory_allocator_create_custom#14420
edmanlog123 wants to merge 1 commit intofacebook:mainfrom
edmanlog123:feature/c-api-custom-allocator

Conversation

@edmanlog123
Copy link

Summary
This PR adds rocksdb_memory_allocator_create_custom to the C API. This allows language bindings (Rust, Go, Python, etc.) to implement and plug in their own custom memory allocators. Currently, the C API only supports creating a jemalloc based allocator.

Motivation
This is a critical addition for improving RocksDB performance on Windows. The default Windows CRT allocator does not decommit memory to the OS, leading to unbounded memory growth in long-running processes (see #4112). By exposing this C-bridge, users can now plug in alternative allocators like mimalloc or tcmalloc via their respective language bindings to resolve these memory issues.

Changes
include/rocksdb/c.h: Added the rocksdb_memory_allocator_create_custom function signature and necessary callback typedefs.

db/c.cc: Implemented the CustomMemoryAllocator proxy class that inherits from rocksdb::MemoryAllocator and dispatches calls to the user-provided C function pointers.

db/c_test.c: Added a new test case CheckCustomAllocator to verify that the custom allocator is correctly called and that the DB opens/operates successfully with it.

Test Plan
Environment: macOS M2 (Apple Silicon).

Build: Verified with a static build using make c_test LIB_MODE=static.

Execution: Ran ./c_test and confirmed the CheckCustomAllocator test passed, ensuring the C-to-C++ bridge and lifecycle management (via shared_ptr) work as intended.

@meta-cla
Copy link

meta-cla bot commented Mar 3, 2026

Hi @edmanlog123!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla
Copy link

meta-cla bot commented Mar 4, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla bot added the CLA Signed label Mar 4, 2026
@meta-cla
Copy link

meta-cla bot commented Mar 4, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant