perf(sql): reduce query latency from memory deallocation overhead on Linux x86_64#6477
perf(sql): reduce query latency from memory deallocation overhead on Linux x86_64#6477bluestreak01 merged 20 commits intomasterfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai: please review, pay attention to the CMake script setup, pull enough context to see the big picture |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 8477 🏁 Script executed: Length of output: 46649 🏁 Script executed: Length of output: 2317 🏁 Script executed: Length of output: 8860 @jerrinot: I've reviewed the jemalloc integration fix with attention to the CMake setup and overall architecture. Here's my comprehensive analysis: Overview - The Big PictureThis PR fixes a critical issue where jemalloc was built with symbol prefixing ( CMake ArchitectureBuild System Structure:
Configuration Management: set(JEMALLOC_CONFIG_MALLOC_CONF "percpu_arena:percpu,oversize_threshold:0,muzzy_decay_ms:0,dirty_decay_ms:5000,background_thread:true")This is templated into the binary at build time, and can be overridden via Key Changes1. Symbol Export Fix (Core Issue)In // BEFORE: #define je_malloc je_malloc
// AFTER: #define je_malloc mallocThis changes how jemalloc's internal 2. JEMALLOC_IS_MALLOC FlagIn Linux platform configs: // BEFORE: /* #define JEMALLOC_IS_MALLOC */
// AFTER: #define JEMALLOC_IS_MALLOCThis flag tells jemalloc to take ownership of standard allocator symbol names. Critically, this is only enabled for:
The Darwin exclusion makes sense because macOS uses zone allocators and has different dynamic linking semantics. 3. Background Thread EnhancementAdded 4. JEMALLOC_NO_PRIVATE_NAMESPACEThe CMake sets Architecture Strengths
Verification PointsThe binary changes are consistent:
Potential Considerations
SummaryThis is a well-architected fix. The CMake setup properly:
The changes correctly address the root cause: jemalloc now exports standard allocator symbols on Linux, making |
puzpuzpuz
left a comment
There was a problem hiding this comment.
Since JEMALLOC_IS_MALLOC is set only on Linux, we should change questdb.sh to something like:
function export_jemalloc() {
if [[ "$QDB_JEMALLOC" = "true" ]]; then
jemalloc_so=$(ls $BASE/libjemalloc*)
if [[ "$QDB_OS" != "FreeBSD" && "$QDB_OS" != "Darwin" && -r "${jemalloc_so}" ]]; then
export LD_PRELOAD=${jemalloc_so}
echo "Using jemalloc"
fi
fi
}|
@puzpuzpuz good point. I removed macos support entirely, and change questdb.sh to fail-fast when you attempt to enable JEMALLOC on an unsupported platform |
|
@puzpuzpuz thanks for your help with this PR! |
Thanks for finding that we lack the symbols in the binary and fixing it. |
|
@jerrinot how about adding a CI Linux runner that would use jemalloc? |
|
@jerrinot do you need some help with this one? I'm interested in getting it shipped in the next release. |
|
@puzpuzpuz thanks for the ping. I pushed changes. I added jemalloc to coverage tests. since these are the only tests running in hotspot@x86_64 |
Thanks! How about enabling jemalloc by default on Linux in |
|
@puzpuzpuz done! |
github runners are under-powered, this does not mix well with G1 GC. the glibc smoke tests occasionally fails with ``` [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.24/plexus-utils-3.0.24.jar (247 kB at 3.6 MB/s) [INFO] Building jar: /__w/questdb/questdb/core/target/questdb-9.2.3-SNAPSHOT.jar Warning: [32.181s][warning][gc,alloc] pool-10-thread-3: Retried waiting for GCLocker too often allocating 312502 words [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for QuestDB 9.2.3-SNAPSHOT: [INFO] [INFO] QuestDB ............................................ FAILURE [ 31.349 s] [INFO] Command line utils for QuestDB ..................... SKIPPED [INFO] Examples for QuestDB ............................... SKIPPED [INFO] Compatibility tests for QuestDB .................... SKIPPED [INFO] QuestDB ............................................ SKIPPED [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 31.452 s [INFO] Finished at: 2025-12-11T13:30:17Z [INFO] ------------------------------------------------------------------------ Error: Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:3.0.1:jar (default-jar) on project questdb: Error assembling JAR: Problem creating jar: Execution exception: Java heap space -> [Help 1] Error: Error: To see the full stack trace of the errors, re-run Maven with the -e switch. Error: Re-run Maven using the -X switch to enable full debug logging. ```
[PR Coverage check]😍 pass : 1 / 1 (100.00%) file detail
|
This change enables jemalloc by default in Linux x86_64 binary distributions. jemalloc provides a significant boost to allocation-heavy queries such as parallel SAMPLE BY/GROUP BY.
This PR also fixes jemalloc built-in binary - the library was built with the
je_prefix in the exported symbols. So,je_mallocinstead ofmalloc(),je_free()instead offree(), etc. The end result was that even whenLD_PREDLOADwas set to the jemalloc library, the database would still use the default system allocator from libc.From now on, the built-in jemalloc binary can only be used on Linux (previously, we also compiled it for MacOS). When
QDB_JEMALLOC=trueis set on other OSes,questdb.shwill return an error.Finally, jemalloc is now enabled for the
Run tests with CoverageCI runner. That's to find any potential regressions around the glibc to jemalloc switch.