Commit graph

3708 commits

Author SHA1 Message Date
Slobodan Predolac
6bf63a41bd Remove obsolete TSD nominal list 2026-05-13 08:49:03 -07:00
Slobodan Predolac
a303250906 Remove obsolete TSD recompute state 2026-05-13 08:49:00 -07:00
Slobodan Predolac
843327b9ec Remove generic experimental hooks 2026-05-12 15:34:09 -07:00
Slobodan Predolac
163c871d6c Add DSS allocation path unit tests 2026-05-12 13:14:39 -04:00
Slobodan Predolac
6e7c364e90 Hide methods from jemalloc_init.h that are not used in other units 2026-05-11 16:23:09 -07:00
Christoph Grüninger
a34a8c5e13 Unify semicolon after ph_proto and ph_structs
Fix extra semicolon after these macros.
Found by GCC 16 (pedantic).
2026-05-08 11:39:56 -07:00
Christoph Grüninger
548e233966 Fix wrong semicolon
Move into else branch, otherwise there are two semicolon in the
if branch.
Found by Clang 22 (pedantic).
2026-05-08 11:39:56 -07:00
Christoph Grüninger
5acdcee600 Remove extra semicolon after macros
There is no compatible way to consume the semicolon by the macro.
Found by GCC 16 (pedantic).
2026-05-08 11:39:56 -07:00
orbisai0security
1ffd5e96d6 Avoid strncpy in malloc_strcpy
Signed-off-by: orbisai0security <>
2026-05-05 11:14:36 -07:00
Bin Liu
be2de8ccd8 Introduce pinned extents to contain unpurgeable pages
Some pages (e.g., hugetlb pages) cannot be purged, and should be
prioritized for reuse.  A custom extent_alloc hook signals this by
OR'ing EXTENT_ALLOC_FLAG_PINNED into the low bits of the returned
pointer; jemalloc strips the flag bits and caches pinned extents in
a dedicated ecache_pinned, separate from the dirty/muzzy decay
pipeline.

Pinned extents do not coalesce eagerly, except for ones larger than
SC_LARGE_MINCLASS.  A prefer-small policy reuses the smallest fitting
pinned extent, to avoid unnecessary split/fragmentation.
2026-05-05 10:44:28 -07:00
Slobodan Predolac
7638093c73 Improve const correctness in the repo 2026-05-04 11:56:17 -07:00
Slobodan Predolac
86f058287f Restore errno save/restore in pages_purge_process_madvise_impl
TODO comment focused on free only, but this path is reachable via
other calls and it is safer to leave errno preservation here.
2026-05-01 15:07:25 -04:00
Slobodan Predolac
9ae0c1b6d3 Make huge_arena_ind static within the arena module (Follow up for PR #2904) 2026-05-01 13:24:45 -04:00
Slobodan Predolac
3a77966168 Preserve errno across free, free_sized, and free_aligned_sized 2026-04-30 18:07:35 -04:00
Slobodan Predolac
4cc497a4a7 Add configurable HPA opts, shard count override, and bump MAX_ALLOCATIONS
Three changes to make pa_microbench easier to drive for fragmentation
experiments:

- Replace HPA_SHARD_OPTS_DEFAULT use with a single editable g_hpa_opts
  global. The microbench does not consult MALLOC_CONF for HPA shard opts,
  so this is the place to set the baseline configuration (slab_max_alloc,
  hugification_threshold, dirty_mult, hugify_delay_ms, purge_threshold,
  hugify_style, etc.).

- Add -n/--nshards N to override the shard count derived from the trace.
  When set, each event is routed to (event->shard_ind % N), letting us
  study the impact of arena consolidation. Without the flag the behavior
  is unchanged (num_shards = max_shard_id + 1).

- Bump MAX_ALLOCATIONS from 10M to 200M so the full ~50M-event adfinder
  trace (and similar) fits in the in-memory event buffer.
2026-04-30 17:48:32 -04:00
Slobodan Predolac
6e0b8e6daa Improve unit test coverage for jemalloc_init, arenas_management, and jemalloc_fork modules 2026-04-30 15:17:18 -04:00
Slobodan Predolac
ba1e2fe4db Extract fork orchestration into jemalloc_fork module 2026-04-30 15:17:18 -04:00
Slobodan Predolac
ec07fc3c5f Extract initialization logic from jemalloc.c into jemalloc_init module 2026-04-30 15:17:18 -04:00
Slobodan Predolac
e0a8401533 Extract arena state and management from jemalloc.c into arenas_management module 2026-04-30 15:17:18 -04:00
guangli-dai
ee4d7b7f9a Update a0's oversize threshold regardless whether huge arena is enabled or not. 2026-04-29 13:25:29 -07:00
guangli-dai
70b228dece Fix assertion for cases where tiny classes do not exist 2026-04-29 13:25:29 -07:00
lexprfuncall
1a15fe33a4
Replace std::__throw_bad_alloc call with standard C++ (#2900)
* Replace std::__throw_bad_alloc call with standard C++

Since December of 2025, std::__throw_bad_alloc is no longer visible
through #include <new> causing jemalloc build failures with gcc 16.
As far as I can tell, all std::__throw_bad_alloc did was arrange to
raise a std::bad_alloc exception if exceptions are enabled.  I am not
sure whether its usage was truly meaningful in jemalloc since the call
is wrapped in a try catch and any usage of try catch is considered an
error when compiling with -fno-exceptions on gcc, at least.

This change adds a check to configure.ac that determines whether
exceptions are enabled by compiling a simple try catch that raises a
std::bad_alloc exception.  If that test succeeds, the macro
JEMALLOC_HAVE_CXX_EXCEPTIONS is defined, and jemalloc will raise an
exception.  Otherwise, we call std::terminate() to abort.

This was tested on FreeBSD with the gcc16 port with and without exceptions
enabled.

* Replace std::set_new_handler calls with std::get_new_handler

Previously, std::set_new_handler was used as a workaround for
compilers with only partial support for C++11.  Now that C++14 is a
requirement to enable C++ support, we can assume std::get_new_handler
is available.
2026-04-27 11:50:27 -07:00
guangli-dai
bb0a6aca10 Allow spaces in prefix. 2026-04-27 09:59:59 -07:00
Slobodan Predolac
76015f519f Fix bug in pa_microbench
pa_microbench was creating its own emap_t per shard on top of the
arena_emap_global that JET malloc initializes during jet_malloc(16)
at startup, breaking the production assumption of one rtree per
process. Fix it by reusing the existing JET emap.
2026-04-23 18:36:13 -04:00
guangli-dai
8072ccc5e9 Fix a link error in the doc 2026-04-23 14:40:13 -07:00
Slobodan Predolac
6cd31c0985 Fix several typos in the comments 2026-04-22 13:35:18 -04:00
guangli-dai
d7b283ed32 Update Github Actions generation script and upgrade freeBSD actions. 2026-04-21 13:16:44 -07:00
Christoph Grüninger
94977e823e [ci] Update GitHub Actions to their latest major release 2026-04-20 19:40:42 -07:00
guangli-dai
873d91033b Add conf.c into msvc and update INSTALL.md 2026-04-20 12:22:59 -07:00
guangli-dai
0edea8b1b0 Update msys to vs2022 for appveyor 2026-04-19 22:49:25 -07:00
Integral
1f44a8b11d
Change permission modes of static libraries to 644 (#2885)
Static libraries are archives and do not need the executable bit.
2026-04-19 14:13:02 -07:00
Guangli Dai
81034ce1f1
Update ChangeLog for release 5.3.1 2026-04-13 17:12:37 -07:00
Ian Ker-Seymer
b8646f4db3 Fix opt.max_background_threads default in docs 2026-04-13 14:46:53 -07:00
Guangli Dai
6515df8cec
Documentation updates (#2869)
* Document new mallctl interfaces added since 5.3.0

Add documentation for the following new mallctl entries:
- opt.debug_double_free_max_scan: double-free detection scan limit
- opt.prof_bt_max: max profiling backtrace depth
- opt.disable_large_size_classes: page-aligned large allocations
- opt.process_madvise_max_batch: batched process_madvise purging
- thread.tcache.max: per-thread tcache_max control
- thread.tcache.ncached_max.read_sizeclass: query ncached_max
- thread.tcache.ncached_max.write: set ncached_max per size range
- arena.<i>.name: get/set arena names
- arenas.hugepage: hugepage size
- approximate_stats.active: lightweight active bytes estimate

Remove config.prof_frameptr since it still needs more development
and is still experimental.

Co-authored-by: lexprfuncall <carl.shapiro@gmail.com>
2026-04-07 10:41:44 -07:00
Slobodan Predolac
f265645d02 Emit retained HPA slab stats in JSON 2026-04-01 23:15:19 -04:00
Slobodan Predolac
db7d99703d Add TODO to benchmark possibly better policy 2026-04-01 23:15:19 -04:00
Slobodan Predolac
6281482c39 Nest HPA SEC stats inside hpa_shard JSON 2026-04-01 23:15:19 -04:00
Slobodan Predolac
3cc56d325c Fix large alloc nrequests under-counting on cache misses 2026-04-01 23:15:19 -04:00
Slobodan Predolac
a47fa33b5a Run clang-format on test/unit/tcache_max.c 2026-04-01 23:15:19 -04:00
Slobodan Predolac
b507644cb0 Fix conf_handle_char_p zero-sized dest and remove unused conf_handle_unsigned 2026-04-01 23:15:19 -04:00
Slobodan Predolac
3ac9f96158 Run clang-format on test/unit/conf_parse.c 2026-04-01 23:15:19 -04:00
Slobodan Predolac
5904a42187 Fix memory leak of old curr_reg on san_bump_grow_locked failure
When san_bump_grow_locked fails, it sets sba->curr_reg to NULL.
The old curr_reg (saved in to_destroy) was never freed or restored,
leaking the virtual memory extent. Restore sba->curr_reg from
to_destroy on failure so the old region remains usable.
2026-04-01 23:15:19 -04:00
Slobodan Predolac
2fceece256 Fix extra size argument in edata_init call in extent_alloc_dss
An extra 'size' argument was passed where 'slab' (false) should be,
shifting all subsequent arguments: slab got size (nonzero=true),
szind got false (0), and sn got SC_NSIZES instead of a proper serial
number from extent_sn_next(). Match the correct pattern used by the
gap edata_init call above.
2026-04-01 23:15:19 -04:00
Slobodan Predolac
234404d324 Fix wrong loop variable for array index in sz_boot_pind2sz_tab
The sentinel fill loop used sz_pind2sz_tab[pind] (constant) instead
of sz_pind2sz_tab[i] (loop variable), writing only to the first
entry repeatedly and leaving subsequent entries uninitialized.
2026-04-01 23:15:19 -04:00
Slobodan Predolac
675ab079e7 Fix missing release of acquired neighbor edata in extent_try_coalesce_impl
When emap_try_acquire_edata_neighbor returned a non-NULL neighbor but
the size check failed, the neighbor was never released from
extent_state_merging, making it permanently invisible to future
allocation and coalescing operations.

Release the neighbor when it doesn't meet the size requirement,
matching the pattern used in extent_recycle_extract.
2026-04-01 23:15:19 -04:00
Slobodan Predolac
3f6e63e86a Fix wrong type for malloc_read_fd return value in prof_stack_range
Used size_t (unsigned) instead of ssize_t for the return value of
malloc_read_fd, which returns -1 on error. With size_t, -1 becomes
a huge positive value, bypassing the error check and corrupting the
remaining byte count.
2026-04-01 23:15:19 -04:00
Slobodan Predolac
dd30c91eaa Fix wrong fallback value in os_page_detect when sysconf fails
Returned LG_PAGE (log2 of page size, e.g. 12) instead of PAGE (actual
page size, e.g. 4096) when sysconf(_SC_PAGESIZE) failed. This would
cause os_page to be set to an absurdly small value, breaking all
page-aligned operations.
2026-04-01 23:15:19 -04:00
Slobodan Predolac
3a8bee81f1 Fix pac_mapped stats inflation on allocation failure
newly_mapped_size was set unconditionally in the ecache_alloc_grow
fallback path, even when the allocation returned NULL. This inflated
pac_mapped stats without a corresponding deallocation to correct them.

Guard the assignment with an edata != NULL check, matching the pattern
used in the batched allocation path above it.
2026-04-01 23:15:19 -04:00
Slobodan Predolac
c2d57040f0 Fix out-of-bounds write in malloc_vsnprintf when size is 0
When called with size==0, the else branch wrote to str[size-1] which
is str[(size_t)-1], a massive out-of-bounds write. Standard vsnprintf
allows size==0 to mean "compute length only, write nothing".

Add unit test for the size==0 case.
2026-04-01 23:15:19 -04:00
Slobodan Predolac
eab2b29736 Fix off-by-one in stats_arenas_i_bins_j and stats_arenas_i_lextents_j bounds checks
Same pattern as arenas_bin_i_index: used > instead of >= allowing
access one past the end of bstats[] and lstats[] arrays.

Add unit tests that verify boundary indices return ENOENT.
2026-04-01 23:15:19 -04:00