
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
jemalloc-tools
Advanced tools
Node module for controlling jemalloc - extremely useful for native memory leak tracking
jemalloc-tools is a TypeScript module providing a comprehensive interface to control and monitor memory allocation behavior in applications using jemalloc, a scalable concurrent malloc implementation. This module wraps the mallctl interface of jemalloc, offering a variety of functionalities including tuning, profiling, and retrieving detailed memory usage statistics.
See also this awesome use case on heap profiling.
jemalloc the memory usage stabilized.prof feature of jemalloc and use jeprof tools to analyze dumps.jemalloc parameters for optimal performance based on application needs.You first you need to have your Node app set up to use jemalloc.
To install jemalloc on Ubuntu, you can use the package manager:
sudo apt-get update
sudo apt-get install libjemalloc-dev
To use jemalloc in your application, you can preload it using the LD_PRELOAD environment variable. This can be done by setting the variable before running your application:
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 your_application
Replace /usr/lib/x86_64-linux-gnu/libjemalloc.so.2 with the actual path to the jemalloc shared library on your system.
Install the jemalloc-tools module using npm or yarn:
npm install jemalloc-tools
# or
yarn add jemalloc-tools
import { ctl, version, tuning, prof, decay, stats, arenas, flushThreadCache, getHeapUsage } from 'jemalloc-tools';
// Most functionity will either throw or return undefined/0 if jemalloc is not present.
const hasJemalloc = !!version;
// Retrieve the jemalloc version
console.log(`jemalloc version: ${version}`);
// Tuning example (can also be done via MALLOC_CONF and retrieved here)
tuning.backgroundThread = true; // collect free'd memory in background threads
tuning.dirtyDecayMs = 30000; // set higher to save CPU usage
tuning.muzzyDecayMs = 30000;
if (prof.enabled) { // it's useful to start the app with prof:true:prof_enabled:false
// Profiling example
prof.active = true;
prof.prefix = `my_node_app`;
prof.dump(); // will dump using the prefix above, or the default pefix
prof.dump('/tmp/profile_output'); // will dump a prof to this specified file
prof.gdump = true;
prof.reset();
}
// Get simple heap usage statistics
const heapUsage = getHeapUsage();
console.log(`Heap used: ${heapUsage.used}, Total: ${heapUsage.total}`);
// Flush thread cache (could be used along with process.gc() perhaps)
flushThreadCache();
// Get arena statistics
const arenaStats = arenas.getArenaStats(0);
console.log(`Arena 0 stats:`, arenaStats);
Look at Typescipt bindings and jemalloc mallctl docs.
versionRetrieves the current version of jemalloc and can be used to check if it's being used as the current allocator.
ctlDirect mapping to the mallctl interface of jemalloc. It can be used to implement any missing functionality from this module by hand. Of couse Pull Requests are welcome.
tuningAdjustable parameters for tuning jemalloc behavior, including background_thread, dirty_decay_ms, and muzzy_decay_ms.
profControls for memory allocation profiling, including enabling/disabling profiling, managing dump files, and resetting profiling statistics.
statsAccess various statistics such as the amount of memory allocated, active, resident, and more.
arenasInterface for working with jemalloc arenas, including retrieving arena statistics.
flushThreadCache()Flushes the thread-specific cache.
getHeapUsage()Progesses epoch & returns an object containing information about the heap usage.
progressEpoch()Progresses epoch, a pre-requisite to get fresh stats.
Contributions to jemalloc-tools are welcome. Please submit a MR.
This module is based on https://github.com/alxvasilev/malloc-tools
The license is BSD
FAQs
Node module for controlling jemalloc - extremely useful for native memory leak tracking
The npm package jemalloc-tools receives a total of 8 weekly downloads. As such, jemalloc-tools popularity was classified as not popular.
We found that jemalloc-tools demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.