Skip to content

Docker: Change memory allocator to jemalloc#785

Open
wanyvic wants to merge 1 commit intodevfrom
lrh/optimize-jemalloc
Open

Docker: Change memory allocator to jemalloc#785
wanyvic wants to merge 1 commit intodevfrom
lrh/optimize-jemalloc

Conversation

@wanyvic
Copy link
Copy Markdown
Collaborator

@wanyvic wanyvic commented Sep 24, 2025

Problem Statement

The current libmdbx implementation uses the default system malloc allocator, which frequently experiences 1-2 second delays during memory allocation operations. This performance bottleneck significantly impacts the overall system performance, especially during high-frequency database operations in the X Layer Erigon node.

Solution Overview

This PR implements jemalloc as the default memory allocator for libmdbx operations by leveraging LD_PRELOAD during Docker build time. This approach allows developers to configure jemalloc behavior through the MALLOC_CONF environment variable without modifying the application code.

Key Changes

Docker Configuration Updates

  • Dockerfile.local: Added jemalloc support with LD_PRELOAD configuration
    • Installed jemalloc-dev package in build stage
    • Set CGO_CFLAGS="-I/usr/include/jemalloc" and CGO_LDFLAGS="-ljemalloc"
    • Configured LD_PRELOAD="/usr/lib/libjemalloc.so.2" for runtime
    • Added jemalloc package to runtime stage

Configuration Options

Developers can configure jemalloc behavior using the MALLOC_CONF environment variable:

# Example configurations
export MALLOC_CONF="dirty_decay_ms:1000,muzzy_decay_ms:1000,background_thread:true"
export MALLOC_CONF="stats_print:true,prof:true"  # Enable statistics printing and profiling

@wanyvic wanyvic force-pushed the lrh/optimize-jemalloc branch from 34dc667 to 632ce74 Compare September 24, 2025 03:51
@wanyvic wanyvic force-pushed the lrh/optimize-jemalloc branch from 632ce74 to a566dce Compare September 29, 2025 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants