Jemalloc is an alternative memory allocator that can be significantly more efficient than the default.
libjemalloc is installed by default on servers configured since October 10th, 2023. If your server was last configured before that date, you'll want to update your server to the latest configuration.
To enable Jemalloc, add the following environment variable on the environment page for the app you wish to enable jemalloc on:
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2
# For arm servers
LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libjemalloc.so.2
Using LD_PRELOAD
will specifically run jemalloc in such a way that Ruby would be unaware of it.
However, running the command MALLOC_CONF=stats_print:true ruby -e "exit"
will output statistics if LD_PRELOAD
was exported correctly.