Pass in Custom Memory Allocator

40 views
Skip to first unread message

Eric Marnadi

unread,
Mar 20, 2025, 3:25:13 PMMar 20
to rocksdb
Hey folks,

We use embedded RocksDB in one of our services, and want to wire in RocksDB allocations into our memory manager. One of the ways we thought to do this is to pass in a custom allocator which first tries to reserve memory with our memory manager and then allocates if/when this is approved. I don't currently see a feasible way to pass in an allocator that's not pre-defined.

Thanks,
Eric

MARK CALLAGHAN

unread,
Mar 20, 2025, 3:57:13 PMMar 20
to Eric Marnadi, rocksdb
I am not sure what you mean by "pass in".

I usually run it with jemalloc, but sometimes try tcmalloc or glibc malloc and that can be done implicitly (via LD_LIBRARY_PATH) or explicitly by linking tcmalloc or jemalloc libraries (you get glibc malloc by default).

--
You received this message because you are subscribed to the Google Groups "rocksdb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rocksdb+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/rocksdb/55e55f48-722d-4907-9a7a-bae3bafa7d22n%40googlegroups.com.


--
Mark Callaghan
mdca...@gmail.com

Eric Marnadi

unread,
Mar 20, 2025, 3:59:32 PMMar 20
to MARK CALLAGHAN, rocksdb
Ah sure - what I meant was, if I wrote my own custom allocator, is there any way I could get our instance of RocksDB to use that instead of jemalloc or any of the pre-defined allocator options?

MARK CALLAGHAN

unread,
Mar 20, 2025, 4:06:03 PMMar 20
to Eric Marnadi, rocksdb
I get it now. I assume someone who works on RocksDB full time might have a better answer. I would just be waving my hands.
--
Mark Callaghan
mdca...@gmail.com

Eric Marnadi

unread,
Mar 20, 2025, 5:05:32 PMMar 20
to MARK CALLAGHAN, rocksdb
No worries, thanks for the reply Mark.

Luca Giacchino

unread,
Mar 20, 2025, 5:37:45 PMMar 20
to Eric Marnadi, MARK CALLAGHAN, rocksdb
Hi Eric,

It should be possible to implement a new memory allocator as a plugin using the MemoryAllocator class.
However, I'm not sure this covers all allocations (for example, I think it is used for block cache allocations, but not memtables). I hope someone with more experience on this topic can clarify.

More information about extending RocksDB: https://github.com/facebook/rocksdb/wiki/RocksDB-Extensions
Existing plugins can be a useful reference. Several are listed in https://github.com/facebook/rocksdb/blob/main/PLUGINS.md.

Best regards,

Luca Giacchino

malik hou

unread,
Apr 18, 2025, 6:40:40 AMApr 18
to rocksdb
Hi Eric,
As others have said, MemoryAllocator is a good choice.
but I know from the context that "RocksDB to use that instead of jemalloc or any of the pre-defined allocator options". 
Here I have to remind you that if tc/jemalloc is used by default, it will hook the new/delete interface, and you can't bypass it unless you manage memory through mmap anonymous mapping. 
So I boldly guess that your request is actually to pass in a memory management object similar to arena

Reply all
Reply to author
Forward
0 new messages