mirror of
https://github.com/hanzoai/datastore.git
synced 2026-09-26 13:55:07 +00:00
Simplify jemalloc integration by replacing the three-mechanism approach (`JEMALLOC_IS_MALLOC` + `JEMALLOC_OVERRIDE___LIBC_*` + linker `--wrap`) with a cleaner two-step design: 1. Compile jemalloc with `je_` prefix so it only exports `je_malloc`, `je_free`, etc. (matching what Darwin already does). 2. Define our own `malloc`/`free` in `malloc.cpp` that perform memory tracking and delegate to `je_malloc`/`je_free`. Provide `__libc_*` aliases on glibc to intercept internal calls. Changes: - Enable `JEMALLOC_PREFIX "je_"` in all non-Darwin `jemalloc_internal_defs.h.in` - Undef `JEMALLOC_IS_MALLOC` and all `JEMALLOC_OVERRIDE___LIBC_*` defines - Remove `JEMALLOC_OVERRIDE_MEMALIGN`/`VALLOC`/`PVALLOC` from `jemalloc_defs.h` - Add `JEMALLOC_NO_RENAME` interface define so consumer code sees `je_*` names - Prefix all jemalloc API calls (`mallctl` -> `je_mallctl`, etc.) in ClickHouse - Rewrite `memory.h` to call `je_malloc`/`je_free` directly instead of `__real_*` - Rewrite `malloc.cpp` with tracking wrappers calling `je_*` underneath - Rewrite `AllocationInterceptors.h` to map `__real_*` -> `je_*` or `::*` - Remove `__wrap_*` functions from `AllocationInterceptors.cpp` - Remove `--wrap` linker flags from `CMakeLists.txt` - Add jemalloc + clickhouse_common_io deps to `clickhouse_malloc` OBJECT library - And also fix JEMALLOC_CPREFIX for Darwin, that was the only platform that uses JE_MALLOC_CONF (over MALLOC_CONF) Co-Authored-By: Claude <[email protected]>
35 lines
1.3 KiB
C++
35 lines
1.3 KiB
C++
/*
|
|
* Name mangling for public symbols is controlled by --with-mangling and
|
|
* --with-jemalloc-prefix. With default settings the je_ prefix is stripped by
|
|
* these macro definitions.
|
|
*
|
|
* When JEMALLOC_PREFIX is defined (i.e. jemalloc is built with je_ prefix),
|
|
* no renaming is needed — je_malloc IS the canonical symbol name.
|
|
*/
|
|
#if !defined(JEMALLOC_NO_RENAME) && !defined(JEMALLOC_PREFIX)
|
|
# define je_aligned_alloc aligned_alloc
|
|
# define je_calloc calloc
|
|
# define je_dallocx dallocx
|
|
# define je_free free
|
|
# define je_mallctl mallctl
|
|
# define je_mallctlbymib mallctlbymib
|
|
# define je_mallctlnametomib mallctlnametomib
|
|
# define je_malloc malloc
|
|
# define je_malloc_conf malloc_conf
|
|
# define je_malloc_conf_2_conf_harder malloc_conf_2_conf_harder
|
|
# define je_malloc_message malloc_message
|
|
# define je_malloc_stats_print malloc_stats_print
|
|
# define je_malloc_usable_size malloc_usable_size
|
|
# define je_mallocx mallocx
|
|
# define je_smallocx_ca709c3139f77f4c00a903cdee46d71e9028f6c6 smallocx_ca709c3139f77f4c00a903cdee46d71e9028f6c6
|
|
# define je_nallocx nallocx
|
|
# define je_posix_memalign posix_memalign
|
|
# define je_rallocx rallocx
|
|
# define je_realloc realloc
|
|
# define je_sallocx sallocx
|
|
# define je_sdallocx sdallocx
|
|
# define je_xallocx xallocx
|
|
# define je_memalign memalign
|
|
# define je_valloc valloc
|
|
#endif
|