### GET /arena..initialized Source: https://jemalloc.net/jemalloc.3.html Queries whether the specified arena's statistics are initialized. ```APIDOC ## GET /arena..initialized ### Description Get whether the specified arena's statistics are initialized. ### Method GET ### Endpoint arena..initialized ### Parameters #### Path Parameters - **i** (integer) - Required - The index of the arena to query. ### Response #### Success Response (200) - **initialized** (bool) - True if initialized, false otherwise. ``` -------------------------------- ### GET stats.arenas..bins. Source: https://jemalloc.net/jemalloc.3.html Retrieves bin-specific statistics for a given arena and bin index. ```APIDOC ## GET stats.arenas..bins..* ### Description Provides detailed statistics for a specific bin within arena , including allocation counts, slab usage, and mutex statistics. ### Method GET ### Endpoint stats.arenas..bins..* ### Parameters #### Path Parameters - **i** (uint) - Required - Arena index. - **j** (uint) - Required - Bin index. ### Response #### Success Response (200) - **nmalloc** (uint64_t) - Cumulative number of allocations. - **ndalloc** (uint64_t) - Cumulative number of deallocations. - **curregs** (size_t) - Current number of regions. - **nslabs** (uint64_t) - Cumulative number of slabs created. - **mutex** (object) - Statistics on the arena bin mutex. ### Response Example { "nmalloc": 5000, "ndalloc": 4950, "curregs": 50, "nslabs": 5 } ``` -------------------------------- ### Example of using STRINGIFY macro with mallctl Source: https://jemalloc.net/jemalloc.3.html Demonstrates how to use the STRINGIFY macro to dynamically construct mallctl names, specifically for operating on arenas. This is useful for accessing or modifying arena-specific configurations. ```c #define STRINGIFY_HELPER(x) #x #define STRINGIFY(x) STRINGIFY_HELPER(x) mallctl("arena." STRINGIFY(MALLCTL_ARENAS_ALL) ".decay", NULL, NULL, NULL, 0); ``` -------------------------------- ### GET stats.arenas. Source: https://jemalloc.net/jemalloc.3.html Retrieves detailed statistics for a specific arena, including muzzy page metrics and object allocation data. ```APIDOC ## GET stats.arenas..* ### Description Retrieves various memory allocation statistics for a specific arena index . Requires `--enable-stats` build configuration. ### Method GET ### Endpoint stats.arenas..* ### Parameters #### Path Parameters - **i** (uint) - Required - The index of the arena. ### Response #### Success Response (200) - **muzzy_npurge** (uint64_t) - Number of muzzy page purge sweeps performed. - **muzzy_nmadvise** (uint64_t) - Number of madvise() calls made to purge muzzy pages. - **muzzy_purged** (uint64_t) - Number of muzzy pages purged. - **small.allocated** (size_t) - Bytes currently allocated by small objects. - **large.allocated** (size_t) - Bytes currently allocated by large objects. ### Response Example { "muzzy_npurge": 120, "small": { "allocated": 1024 }, "large": { "allocated": 4096 } } ``` -------------------------------- ### Arena Extent Hooks Configuration Source: https://jemalloc.net/jemalloc.3.html Get or set the extent management hook functions for a specific arena, allowing custom control over memory allocation and deallocation. ```APIDOC ## GET /arena//extent_hooks ### Description Retrieves the current extent management hook functions for a specific arena. ### Method GET ### Endpoint `/arena//extent_hooks` ### Parameters #### Path Parameters - **i** (integer) - Required - The arena index. ### Response #### Success Response (200) - **extent_hooks** (extent_hooks_t *) - The structure containing extent management hook functions (`alloc`, `dalloc`, `destroy`, `commit`, `decommit`, `purge_lazy`, `purge_forced`, `split`, `merge`). #### Response Example ```json { "extent_hooks": { "alloc": "", "dalloc": "", "destroy": "", "commit": "", "decommit": "", "purge_lazy": "", "purge_forced": "", "split": "", "merge": "" } } ``` ## PUT /arena//extent_hooks ### Description Sets the extent management hook functions for a specific arena. These functions manage memory allocation and deallocation for the arena. Custom hooks can provide fine-grained control, especially for arenas created via `arenas.create`. ### Method PUT ### Endpoint `/arena//extent_hooks` ### Parameters #### Path Parameters - **i** (integer) - Required - The arena index. #### Request Body - **extent_hooks** (extent_hooks_t) - Required - The structure containing the extent management hook functions to set. ### Request Example ```json { "extent_hooks": { "alloc": "my_alloc_hook", "dalloc": "my_dalloc_hook", "destroy": "my_destroy_hook", "commit": "my_commit_hook", "decommit": "my_decommit_hook", "purge_lazy": "my_purge_lazy_hook", "purge_forced": "my_purge_forced_hook", "split": "my_split_hook", "merge": "my_merge_hook" } } ``` ### Response #### Success Response (200) (No specific response body, operation is acknowledged) ``` -------------------------------- ### GET /thread.peak.read Source: https://jemalloc.net/jemalloc.3.html Returns an approximation of the maximum net bytes allocated by the calling thread since the last reset. ```APIDOC ## GET /thread.peak.read ### Description Get an approximation of the maximum value of the difference between the number of bytes allocated and the number of bytes deallocated by the calling thread. ### Method GET ### Endpoint thread.peak.read ### Response #### Success Response (200) - **value** (uint64_t) - Approximation of peak net bytes allocated. ``` -------------------------------- ### Configure Jemalloc Extent Hooks Source: https://jemalloc.net/jemalloc.3.html Allows getting or setting custom extent management hook functions for a specific arena. These hooks control how memory extents are allocated, deallocated, committed, and decommitted. Custom hooks can be used to integrate with application-supplied memory allocators, especially for arenas created via `arenas.create`. For automatically created arenas, hooks may operate on a best-effort basis. ```c typedef void extent_alloc_t(extent_t *, void *, size_t, size_t, unsigned, int *); typedef bool extent_dalloc_t(extent_t *, void *, size_t, bool); typedef bool extent_destroy_t(extent_t *, void *, size_t, bool); typedef bool extent_commit_t(extent_t *, void *, size_t, bool); typedef bool extent_decommit_t(extent_t *, void *, size_t, bool); typedef bool extent_purge_t(extent_t *, void *, size_t, bool); typedef bool extent_split_t(extent_t *, void *, size_t, size_t, bool); typedef bool extent_merge_t(extent_t *, void *, size_t, void *, size_t, bool); struct extent_hooks_s { extent_alloc_t *alloc; extent_dalloc_t *dalloc; extent_destroy_t *destroy; extent_commit_t *commit; extent_decommit_t *decommit; extent_purge_t *purge_lazy; extent_purge_t *purge_forced; extent_split_t *split; extent_merge_t *merge; }; typedef struct extent_hooks_s extent_hooks_t; // Example: Setting custom extent hooks for arena 0 // extern extent_hooks_t my_custom_hooks; // mallctl("arena.0.extent_hooks", NULL, NULL, &my_custom_hooks, sizeof(my_custom_hooks)); // Example: Getting current extent hooks for arena 0 // extent_hooks_t current_hooks; // size_t sz = sizeof(current_hooks); // mallctl("arena.0.extent_hooks", ¤t_hooks, &sz, NULL, 0); ``` -------------------------------- ### GET /thread.deallocatedp Source: https://jemalloc.net/jemalloc.3.html Retrieves a pointer to the value returned by thread.deallocated, allowing for efficient monitoring of deallocated bytes without repeated mallctl calls. ```APIDOC ## GET /thread.deallocatedp ### Description Get a pointer to the value that is returned by the thread.deallocated mallctl. This is useful for avoiding the overhead of repeated mallctl() calls. ### Method GET ### Endpoint thread.deallocatedp ### Parameters #### Query Parameters - **--enable-stats** (flag) - Required - Must be compiled with stats enabled. ### Response #### Success Response (200) - **pointer** (uint64_t *) - Pointer to the deallocated bytes counter. ``` -------------------------------- ### Querying jemalloc namespace using MIB Source: https://jemalloc.net/jemalloc.3.html Demonstrates how to translate a namespace string to a Management Information Base (MIB) array to efficiently query jemalloc settings in a loop, avoiding repeated string lookups. ```C unsigned nbins, i; size_t mib[4]; size_t len, miblen; len = sizeof(nbins); mallctl("arenas.nbins", &nbins, &len, NULL, 0); miblen = 4; mallctlnametomib("arenas.bin.0.size", mib, &miblen); for (i = 0; i < nbins; i++) { size_t bin_size; mib[2] = i; len = sizeof(bin_size); mallctlbymib(mib, miblen, (void *)&bin_size, &len, NULL, 0); /* Do something with bin_size... */ } ``` -------------------------------- ### Heap Profiling Configuration Source: https://jemalloc.net/jemalloc.3.html Endpoints and configuration options for managing memory profiling, leak detection, and dump intervals. ```APIDOC ## GET/SET opt.prof_* ### Description Configures heap profiling behavior, including cumulative reporting, interval-based dumping, and leak detection. ### Parameters #### Request Body - **opt.prof_accum** (bool) - Optional - Reporting of cumulative object/byte counts. - **opt.lg_prof_interval** (ssize_t) - Optional - Log base 2 interval between profile dumps. - **opt.prof_gdump** (bool) - Optional - Trigger dump when virtual memory exceeds maximum. - **opt.prof_final** (bool) - Optional - Dump final memory usage at exit. - **opt.prof_leak** (bool) - Optional - Enable memory leak reporting. - **opt.prof_leak_error** (bool) - Optional - Enable leak reporting and exit with error code 1 if leaks found. ### Response #### Success Response (200) - **status** (string) - Configuration update status. ``` -------------------------------- ### POST /tcache.create Source: https://jemalloc.net/jemalloc.3.html Creates an explicit thread-specific cache and returns an identifier for manual cache management. ```APIDOC ## POST /tcache.create ### Description Create an explicit thread-specific cache (tcache) and return an identifier that can be passed to the MALLOCX_TCACHE macro. ### Method POST ### Endpoint tcache.create ### Response #### Success Response (200) - **id** (unsigned) - Identifier for the created tcache. ``` -------------------------------- ### Arena DSS and Retention Configuration Source: https://jemalloc.net/jemalloc.3.html Configure the DSS allocation precedence and the maximum size for growing retained regions. ```APIDOC ## PUT /arena//dss ### Description Sets the precedence of dss allocation relative to mmap allocation for a specific arena or all arenas. Supported settings are defined by `opt.dss`. ### Method PUT ### Endpoint `/arena//dss` or `/arena/MALLCTL_ARENAS_ALL/dss` ### Parameters #### Path Parameters - **i** (integer) - Required - The arena index. Use `MALLCTL_ARENAS_ALL` for all arenas. #### Request Body - **dss** (const char *) - Required - The DSS allocation setting (e.g., "primary", "secondary"). ### Request Example ```json { "dss": "secondary" } ``` ### Response #### Success Response (200) (No specific response body, operation is acknowledged) ## PUT /arena//retain_grow_limit ### Description Sets the maximum size to which the retained region can grow for a specific arena. This is relevant when `opt.retain` is enabled and controls the maximum increment for virtual memory expansion or extent hook allocations. ### Method PUT ### Endpoint `/arena//retain_grow_limit` ### Parameters #### Path Parameters - **i** (integer) - Required - The arena index. #### Request Body - **retain_grow_limit** (size_t) - Required - The maximum size in bytes for the retained region growth. No limit if not set. ### Request Example ```json { "retain_grow_limit": 1073741824 } ``` ### Response #### Success Response (200) (No specific response body, operation is acknowledged) ``` -------------------------------- ### Interval Statistics Output Options Source: https://jemalloc.net/jemalloc.3.html Specifies options to pass to `malloc_stats_print()` for interval-based statistics printing. Has no effect if `opt.stats_interval` is disabled. ```APIDOC ## GET /opt/stats_interval_opts ### Description Options (the _`opts`_string) to pass to the`malloc_stats_print()` for interval based statistics printing (enabled through `opt.stats_interval`). See available options in `malloc_stats_print()`. Has no effect unless `opt.stats_interval` is enabled. The default is “”. ### Method GET ### Endpoint /opt/stats_interval_opts ### Parameters #### Query Parameters - **value** (const char *) - Required - A string containing options for `malloc_stats_print()`. ``` -------------------------------- ### C: Jemalloc prof.dump mallctl for memory profile dumping Source: https://jemalloc.net/jemalloc.3.html Dumps a memory profile to a specified file. If a NULL pointer is provided, the dump file is generated based on a pattern including prefix, PID, and sequence numbers. This option requires jemalloc to be compiled with profiling support. ```c void prof_dump(const char *filename); // Usage via mallctl: // mallctl("prof.dump", NULL, NULL, "/path/to/profile.heap", sizeof("/path/to/profile.heap")); // mallctl("prof.dump", NULL, NULL, NULL, 0); // Dump to default pattern file ``` -------------------------------- ### Configure Abort-on-out-of-memory in jemalloc Source: https://jemalloc.net/jemalloc.3.html Enables the xmalloc behavior where the application aborts instead of returning NULL on allocation failure. This is configured by setting the global malloc_conf variable in the source code. ```C malloc_conf = "xmalloc:true"; ``` -------------------------------- ### Standard Memory Allocation API Source: https://jemalloc.net/jemalloc.3.html Standard C library-compatible functions for allocating, reallocating, and freeing memory. These functions provide the base interface for dynamic memory management. ```c void *malloc(size_t size); void *calloc(size_t number, size_t size); int posix_memalign(void **ptr, size_t alignment, size_t size); void *aligned_alloc(size_t alignment, size_t size); void *realloc(void *ptr, size_t size); void free(void *ptr); ``` -------------------------------- ### Arena Decay and Purge Control Source: https://jemalloc.net/jemalloc.3.html Control the decay-based purging of unused pages for specific arenas or all arenas. This includes triggering decay and setting decay times. ```APIDOC ## POST /arena//decay ### Description Triggers decay-based purging of unused dirty/muzzy pages for a specific arena or all arenas. The proportion of purged pages depends on the current time and decay settings. ### Method POST ### Endpoint `/arena//decay` or `/arena/MALLCTL_ARENAS_ALL/decay` ### Parameters #### Path Parameters - **i** (integer) - Required - The arena index. Use `MALLCTL_ARENAS_ALL` for all arenas. ### Request Body (No request body required for this operation) ### Response #### Success Response (200) (No specific response body, operation is acknowledged) ## POST /arena//purge ### Description Purges all unused dirty pages for a specific arena or all arenas. ### Method POST ### Endpoint `/arena//purge` or `/arena/MALLCTL_ARENAS_ALL/purge` ### Parameters #### Path Parameters - **i** (integer) - Required - The arena index. Use `MALLCTL_ARENAS_ALL` for all arenas. ### Request Body (No request body required for this operation) ### Response #### Success Response (200) (No specific response body, operation is acknowledged) ## PUT /arena//dirty_decay_ms ### Description Sets the approximate time in milliseconds for purging unused dirty pages in an arena. Setting this value triggers immediate purging of currently unused dirty pages unless disabled. ### Method PUT ### Endpoint `/arena//dirty_decay_ms` ### Parameters #### Path Parameters - **i** (integer) - Required - The arena index. #### Request Body - **dirty_decay_ms** (ssize_t) - Required - The decay time in milliseconds. Use -1 to disable purging. ### Request Example ```json { "dirty_decay_ms": 60000 } ``` ### Response #### Success Response (200) (No specific response body, operation is acknowledged) ## PUT /arena//muzzy_decay_ms ### Description Sets the approximate time in milliseconds for purging unused muzzy pages in an arena. Setting this value triggers immediate purging of currently unused muzzy pages unless disabled. ### Method PUT ### Endpoint `/arena//muzzy_decay_ms` ### Parameters #### Path Parameters - **i** (integer) - Required - The arena index. #### Request Body - **muzzy_decay_ms** (ssize_t) - Required - The decay time in milliseconds. Use -1 to disable purging. ### Request Example ```json { "muzzy_decay_ms": 30000 } ``` ### Response #### Success Response (200) (No specific response body, operation is acknowledged) ``` -------------------------------- ### Junk Fill Option Source: https://jemalloc.net/jemalloc.3.html Enables or configures the filling of memory with 'junk' data, often used for debugging. This option is related to the `--enable-fill` configuration flag. ```APIDOC ## GET /opt/junk ### Description Enables or configures the filling of memory with 'junk' data, often used for debugging. This option is related to the `--enable-fill` configuration flag. ### Method GET ### Endpoint /opt/junk ### Parameters #### Query Parameters - **value** (const char *) - Required - Configuration string for junk filling. ``` -------------------------------- ### Thread Allocation Statistics Source: https://jemalloc.net/jemalloc.3.html Endpoints for retrieving and managing thread-specific memory allocation data. ```APIDOC ## GET/SET thread.* ### Description Retrieves or modifies thread-specific memory management settings and statistics. ### Parameters #### Path Parameters - **thread.arena** (unsigned) - Required - Get or set the arena associated with the calling thread. - **thread.allocated** (uint64_t) - Required - Get total bytes allocated by the thread. - **thread.allocatedp** (uint64_t*) - Required - Get pointer to the allocated counter. - **thread.deallocated** (uint64_t) - Required - Get total bytes deallocated by the thread. ### Response #### Success Response (200) - **value** (mixed) - The requested statistic or configuration value. ``` -------------------------------- ### Include jemalloc header Source: https://jemalloc.net/jemalloc.3.html The primary header file required to access the jemalloc memory allocation functions in C applications. ```c #include ``` -------------------------------- ### Memory Reallocation Behavior Source: https://jemalloc.net/jemalloc.3.html Configures the behavior of realloc() when a size of zero is requested. ```APIDOC ## SET opt.zero_realloc ### Description Determines how realloc() handles zero-size requests: 'alloc', 'free', or 'abort'. ### Parameters #### Request Body - **opt.zero_realloc** (const char*) - Required - One of: "alloc", "free", "abort". ### Response #### Success Response (200) - **status** (string) - Configuration update status. ``` -------------------------------- ### Muzzy Page Purge Decay Time Source: https://jemalloc.net/jemalloc.3.html Configures the approximate time in milliseconds for unused muzzy pages to be purged or reused. Muzzy pages are previously purged dirty pages in an indeterminate state. A value of 0 purges immediately, -1 disables purging, and the default is 10 seconds. ```APIDOC ## GET /opt/muzzy_decay_ms ### Description Approximate time in milliseconds from the creation of a set of unused muzzy pages until an equivalent set of unused muzzy pages is purged (i.e. converted to clean) and/or reused. Muzzy pages are defined as previously having been unused dirty pages that were subsequently purged in a manner that left them subject to the reclamation whims of the operating system (e.g. `madvise(_`...`__``MADV_FREE``_)`), and therefore in an indeterminate state. The pages are incrementally purged according to a sigmoidal decay curve that starts and ends with zero purge rate. A decay time of 0 causes all unused muzzy pages to be purged immediately upon creation. A decay time of -1 disables purging. The default decay time is 10 seconds. See `arenas.muzzy_decay_ms` and `arena..muzzy_decay_ms` for related dynamic control options. ### Method GET ### Endpoint /opt/muzzy_decay_ms ### Parameters #### Query Parameters - **value** (ssize_t) - Required - The decay time in milliseconds. Use 0 for immediate purge, -1 to disable. ``` -------------------------------- ### Statistics Printing Options at Exit Source: https://jemalloc.net/jemalloc.3.html Specifies options to pass to `malloc_stats_print()` when statistics are printed at program exit. Has no effect if `opt.stats_print` is disabled. ```APIDOC ## GET /opt/stats_print_opts ### Description Options (the _`opts`_string) to pass to the`malloc_stats_print()` at exit (enabled through `opt.stats_print`). See available options in `malloc_stats_print()`. Has no effect unless `opt.stats_print` is enabled. The default is “”. ### Method GET ### Endpoint /opt/stats_print_opts ### Parameters #### Query Parameters - **value** (const char *) - Required - A string containing options for `malloc_stats_print()`. ``` -------------------------------- ### Dirty Page Purge Decay Time Source: https://jemalloc.net/jemalloc.3.html Configures the approximate time in milliseconds for unused dirty pages to be purged or reused. A value of 0 purges immediately, -1 disables purging, and the default is 10 seconds. ```APIDOC ## GET /opt/dirty_decay_ms ### Description Approximate time in milliseconds from the creation of a set of unused dirty pages until an equivalent set of unused dirty pages is purged (i.e. converted to muzzy via e.g. `madvise(_`...`__``MADV_FREE``_)` if supported by the operating system, or converted to clean otherwise) and/or reused. Dirty pages are defined as previously having been potentially written to by the application, and therefore consuming physical memory, yet having no current use. The pages are incrementally purged according to a sigmoidal decay curve that starts and ends with zero purge rate. A decay time of 0 causes all unused dirty pages to be purged immediately upon creation. A decay time of -1 disables purging. The default decay time is 10 seconds. See `arenas.dirty_decay_ms` and `arena..dirty_decay_ms` for related dynamic control options. See `opt.muzzy_decay_ms` for a description of muzzy pages.for a description of muzzy pages. Note that when the `oversize_threshold` feature is enabled, the arenas reserved for oversize requests may have its own default decay settings. ### Method GET ### Endpoint /opt/dirty_decay_ms ### Parameters #### Query Parameters - **value** (ssize_t) - Required - The decay time in milliseconds. Use 0 for immediate purge, -1 to disable. ``` -------------------------------- ### Arena Reset and Destroy Source: https://jemalloc.net/jemalloc.3.html Operations to reset or destroy arenas, including discarding allocations and cleaning up associated metadata. ```APIDOC ## POST /arena//reset ### Description Discards all existing allocations for a specific arena. This operation requires flushing thread caches associated with the arena beforehand and can only be used with explicitly created arenas. ### Method POST ### Endpoint `/arena//reset` ### Parameters #### Path Parameters - **i** (integer) - Required - The arena index. ### Request Body (No request body required for this operation) ### Response #### Success Response (200) (No specific response body, operation is acknowledged) ## POST /arena//destroy ### Description Destroys an arena, discarding its allocations, merging its statistics, and freeing its metadata. Destruction fails if any threads are currently associated with the arena. Subsequent calls to `arenas.create` may reuse the arena index. ### Method POST ### Endpoint `/arena//destroy` ### Parameters #### Path Parameters - **i** (integer) - Required - The arena index. ### Request Body (No request body required for this operation) ### Response #### Success Response (200) (No specific response body, operation is acknowledged) ``` -------------------------------- ### Trigger Purging of Unused Pages in Jemalloc Arenas Source: https://jemalloc.net/jemalloc.3.html Allows triggering decay-based purging of unused dirty/muzzy pages for a specific arena or all arenas. The proportion of purged pages is influenced by decay times. This operation is non-blocking and does not require specific inputs beyond the arena index. ```c #define MALLCTL_ARENAS_ALL -1 // Trigger decay-based purging for a specific arena or all arenas. // Example: purge for arena 0 // mallctl("arena.0.decay", NULL, NULL, NULL, 0); // Example: purge for all arenas // mallctl("arena.MALLCTL_ARENAS_ALL.decay", NULL, NULL, NULL, 0); ``` -------------------------------- ### Enable Statistics Printing at Exit Source: https://jemalloc.net/jemalloc.3.html Enables or disables the printing of statistics when the program exits. If enabled, `malloc_stats_print()` is called. Use with caution in multi-threaded applications. ```APIDOC ## GET /opt/stats_print ### Description Enable/disable statistics printing at exit. If enabled, the `malloc_stats_print()` function is called at program exit via an atexit(3) function. `opt.stats_print_opts` can be combined to specify output options. If `--enable-stats` is specified during configuration, this has the potential to cause deadlock for a multi-threaded process that exits while one or more threads are executing in the memory allocation functions. Furthermore, `atexit()` may allocate memory during application initialization and then deadlock internally when jemalloc in turn calls `atexit()`, so this option is not universally usable (though the application can register its own `atexit()` function with equivalent functionality). Therefore, this option should only be used with care; it is primarily intended as a performance tuning aid during application development. This option is disabled by default. ### Method GET ### Endpoint /opt/stats_print ### Parameters #### Query Parameters - **value** (bool) - Required - `true` to enable, `false` to disable. ``` -------------------------------- ### Configure Jemalloc Muzzy Page Decay Time Source: https://jemalloc.net/jemalloc.3.html Sets the approximate time in milliseconds for unused muzzy pages to decay before being purged or reused. Similar to dirty pages, setting this value triggers immediate purging of currently unused muzzy pages unless decay is disabled (-1). This affects the reclamation of muzzy pages. ```c // Set the decay time in milliseconds for unused muzzy pages. // A value of -1 disables purging. // Example: set decay time for arena 1 to 30000 ms (30 seconds) // ssize_t decay_time = 30000; // mallctl("arena.1.muzzy_decay_ms", &decay_time, NULL, NULL, 0); // Example: disable purging for arena 1 // ssize_t disable_purge = -1; // mallctl("arena.1.muzzy_decay_ms", &disable_purge, NULL, NULL, 0); ``` -------------------------------- ### jemalloc Non-standard Extension API Source: https://jemalloc.net/jemalloc.3.html Advanced functions provided by jemalloc for specialized memory management, including flag-based allocation, mallctl interfaces for runtime configuration, and memory usage statistics. ```c void *mallocx(size_t size, int flags); void *rallocx(void *ptr, size_t size, int flags); size_t xallocx(void *ptr, size_t size, size_t extra, int flags); size_t sallocx(void *ptr, int flags); void dallocx(void *ptr, int flags); void sdallocx(void *ptr, size_t size, int flags); size_t nallocx(size_t size, int flags); int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen); int mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp); int mallctlbymib(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen); void malloc_stats_print(void(*write_cb)(void *, const char *), void *cbopaque, const char *opts); size_t malloc_usable_size(const void *ptr); ``` -------------------------------- ### Interval Statistics Output Interval Source: https://jemalloc.net/jemalloc.3.html Sets the average interval, in bytes of allocation activity, between statistics outputs. The default is -1, which disables interval-triggered output. ```APIDOC ## GET /opt/stats_interval ### Description Average interval between statistics outputs, as measured in bytes of allocation activity. The actual interval may be sporadic because decentralized event counters are used to avoid synchronization bottlenecks. The output may be triggered on any thread, which then calls `malloc_stats_print()`. `opt.stats_interval_opts` can be combined to specify output options. By default, interval-triggered stats output is disabled (encoded as -1). ### Method GET ### Endpoint /opt/stats_interval ### Parameters #### Query Parameters - **value** (int64_t) - Required - The interval in bytes. Use -1 to disable. ``` -------------------------------- ### Configure Jemalloc Retained Region Grow Limit Source: https://jemalloc.net/jemalloc.3.html Sets the maximum size to which the retained region can grow, relevant only when `opt.retain` is enabled. This controls the maximum virtual memory increment or allocation size via `arena..extent_hooks`. It's particularly useful when extent hooks reserve large memory chunks like huge pages. The default is no limit. ```c // Set the maximum size (in bytes) for the retained region to grow. // Example: limit retained region growth for arena 0 to 1GB (1024*1024*1024 bytes) // size_t limit = 1024 * 1024 * 1024; // mallctl("arena.0.retain_grow_limit", &limit, NULL, NULL, 0); // Example: remove limit for arena 0 (set to 0 or use a very large value if needed) // size_t no_limit = 0; // mallctl("arena.0.retain_grow_limit", &no_limit, NULL, NULL, 0); ``` -------------------------------- ### C: Jemalloc arenas.create mallctl for explicit arena creation Source: https://jemalloc.net/jemalloc.3.html Allows explicit creation of a new arena outside the automatically managed range. It takes the arena index and optionally extent hooks. If the provided space for the index is insufficient, no arena is created. ```c unsigned arenas_create(unsigned *oldp, extent_hooks_t *extent_hooks); // Usage via mallctl: // unsigned new_arena_idx; // unsigned long long old_arena_idx = 0; // extent_hooks_t *my_hooks = NULL; // or a pointer to your custom hooks // mallctl("arenas.create", &new_arena_idx, &sizeof(unsigned), &old_arena_idx, sizeof(unsigned long long)); // mallctl("arenas.create", &new_arena_idx, &sizeof(unsigned), &my_hooks, sizeof(extent_hooks_t *)); ``` -------------------------------- ### Configure Jemalloc Dirty Page Decay Time Source: https://jemalloc.net/jemalloc.3.html Sets the approximate time in milliseconds for unused dirty pages to decay before being purged or reused. Setting this value causes currently unused dirty pages to be considered fully decayed, triggering immediate purging unless disabled (-1). This impacts memory reclamation frequency. ```c // Set the decay time in milliseconds for unused dirty pages. // A value of -1 disables purging. // Example: set decay time for arena 0 to 60000 ms (1 minute) // ssize_t decay_time = 60000; // mallctl("arena.0.dirty_decay_ms", &decay_time, NULL, NULL, 0); // Example: disable purging for all arenas // ssize_t disable_purge = -1; // mallctl("arena.MALLCTL_ARENAS_ALL.dirty_decay_ms", &disable_purge, NULL, NULL, 0); ``` -------------------------------- ### Maximum Active Extent Fit Ratio Source: https://jemalloc.net/jemalloc.3.html Determines the maximum ratio (log base 2) between the size of an active extent and the requested allocation size when reusing dirty extents. This helps reduce fragmentation. The default is 6 (ratio of 64). ```APIDOC ## GET /opt/lg_extent_max_active_fit ### Description When reusing dirty extents, this determines the (log base 2 of the) maximum ratio between the size of the active extent selected (to split off from) and the size of the requested allocation. This prevents the splitting of large active extents for smaller allocations, which can reduce fragmentation over the long run (especially for non-active extents). Lower value may reduce fragmentation, at the cost of extra active extents. The default value is 6, which gives a maximum ratio of 64 (2^6). ### Method GET ### Endpoint /opt/lg_extent_max_active_fit ### Parameters #### Query Parameters - **value** (size_t) - Required - The log base 2 of the maximum ratio. ``` -------------------------------- ### C: Define extent_purge_t function type for memory extent purging Source: https://jemalloc.net/jemalloc.3.html Defines the extent_purge_t function pointer type used for discarding physical pages within a virtual memory mapping. It takes arguments for extent hooks, address, size, offset, length, and arena index. Returning true indicates a purge failure. ```c typedef bool (*extent_purge_t)( extent_hooks_t *extent_hooks, void *addr, size_t size, size_t offset, size_t length, unsigned arena_ind ); ``` -------------------------------- ### POST /thread.tcache.flush Source: https://jemalloc.net/jemalloc.3.html Flushes the calling thread's thread-specific cache (tcache), releasing cached objects. ```APIDOC ## POST /thread.tcache.flush ### Description Flush calling thread's thread-specific cache (tcache). This interface releases all cached objects and internal data structures associated with the calling thread's tcache. ### Method POST ### Endpoint thread.tcache.flush ``` -------------------------------- ### Configure DSS Allocation Precedence in Jemalloc Source: https://jemalloc.net/jemalloc.3.html Sets the precedence of DSS (Data Segment Split) allocation relative to mmap allocation for a specified arena or all arenas. Supported settings are defined by `opt.dss`. This allows control over how memory is initially requested from the operating system. ```c #define MALLCTL_ARENAS_ALL -1 // Set the DSS allocation precedence for a specific arena or all arenas. // Supported settings depend on `opt.dss` configuration. // Example: set DSS precedence for arena 0 to "primary" // size_t size = sizeof("primary"); // mallctl("arena.0.dss", "primary", &size, NULL, 0); // Example: set DSS precedence for all arenas // size_t size_all = sizeof("secondary"); // mallctl("arena.MALLCTL_ARENAS_ALL.dss", "secondary", &size_all, NULL, 0); ```