From 6f610a1df1aea14e81e1268c1471fd612e5e0ccb Mon Sep 17 00:00:00 2001 From: Slobodan Predolac Date: Thu, 12 Feb 2026 11:49:28 -0800 Subject: [PATCH] Remove prof_threshold built-in event. It is trivial to implement it as user event if needed --- Makefile.in | 3 - include/jemalloc/internal/prof_externs.h | 5 - include/jemalloc/internal/prof_hook.h | 6 - include/jemalloc/internal/prof_threshold.h | 8 -- .../jemalloc/internal/thread_event_registry.h | 1 - .../projects/vc2015/jemalloc/jemalloc.vcxproj | 1 - .../vc2015/jemalloc/jemalloc.vcxproj.filters | 3 - .../projects/vc2017/jemalloc/jemalloc.vcxproj | 1 - .../vc2017/jemalloc/jemalloc.vcxproj.filters | 3 - .../projects/vc2019/jemalloc/jemalloc.vcxproj | 1 - .../vc2019/jemalloc/jemalloc.vcxproj.filters | 3 - .../projects/vc2022/jemalloc/jemalloc.vcxproj | 1 - .../vc2022/jemalloc/jemalloc.vcxproj.filters | 3 - src/ctl.c | 30 ----- src/jemalloc.c | 5 - src/prof_threshold.c | 69 ----------- src/thread_event.c | 9 -- src/thread_event_registry.c | 3 +- test/unit/mallctl.c | 1 - test/unit/prof_threshold.c | 112 ------------------ test/unit/prof_threshold_small.c | 2 - test/unit/prof_threshold_small.sh | 1 - 22 files changed, 1 insertion(+), 270 deletions(-) delete mode 100644 include/jemalloc/internal/prof_threshold.h delete mode 100644 src/prof_threshold.c delete mode 100644 test/unit/prof_threshold.c delete mode 100644 test/unit/prof_threshold_small.c delete mode 100644 test/unit/prof_threshold_small.sh diff --git a/Makefile.in b/Makefile.in index 83f04e645d..6972c350cf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -145,7 +145,6 @@ C_SRCS := $(srcroot)src/jemalloc.c \ $(srcroot)src/prof_stack_range.c \ $(srcroot)src/prof_stats.c \ $(srcroot)src/prof_sys.c \ - $(srcroot)src/prof_threshold.c \ $(srcroot)src/psset.c \ $(srcroot)src/rtree.c \ $(srcroot)src/safety_check.c \ @@ -270,8 +269,6 @@ TESTS_UNIT := \ $(srcroot)test/unit/prof_stats.c \ $(srcroot)test/unit/prof_tctx.c \ $(srcroot)test/unit/prof_thread_name.c \ - $(srcroot)test/unit/prof_threshold.c \ - $(srcroot)test/unit/prof_threshold_small.c \ $(srcroot)test/unit/prof_sys_thread_name.c \ $(srcroot)test/unit/psset.c \ $(srcroot)test/unit/ql.c \ diff --git a/include/jemalloc/internal/prof_externs.h b/include/jemalloc/internal/prof_externs.h index e41e30a059..e07e69f556 100644 --- a/include/jemalloc/internal/prof_externs.h +++ b/include/jemalloc/internal/prof_externs.h @@ -12,8 +12,6 @@ extern bool opt_prof_active; extern bool opt_prof_thread_active_init; extern unsigned opt_prof_bt_max; extern size_t opt_lg_prof_sample; /* Mean bytes between samples. */ -extern size_t - opt_experimental_lg_prof_threshold; /* Mean bytes between thresholds. */ extern ssize_t opt_lg_prof_interval; /* lg(prof_interval). */ extern bool opt_prof_gdump; /* High-water memory dumping. */ extern bool opt_prof_final; /* Final profile dumping. */ @@ -70,9 +68,6 @@ prof_sample_hook_t prof_sample_hook_get(void); void prof_sample_free_hook_set(prof_sample_free_hook_t hook); prof_sample_free_hook_t prof_sample_free_hook_get(void); -void prof_threshold_hook_set(prof_threshold_hook_t hook); -prof_threshold_hook_t prof_threshold_hook_get(void); - /* Functions only accessed in prof_inlines.h */ prof_tdata_t *prof_tdata_init(tsd_t *tsd); prof_tdata_t *prof_tdata_reinit(tsd_t *tsd, prof_tdata_t *tdata); diff --git a/include/jemalloc/internal/prof_hook.h b/include/jemalloc/internal/prof_hook.h index 69dfaabf91..d5a9b0ff80 100644 --- a/include/jemalloc/internal/prof_hook.h +++ b/include/jemalloc/internal/prof_hook.h @@ -27,10 +27,4 @@ typedef void (*prof_sample_hook_t)(const void *ptr, size_t size, /* ptr, size */ typedef void (*prof_sample_free_hook_t)(const void *, size_t); -/* - * A callback hook that notifies when an allocation threshold has been crossed. - */ -typedef void (*prof_threshold_hook_t)( - uint64_t alloc, uint64_t dealloc, uint64_t peak); - #endif /* JEMALLOC_INTERNAL_PROF_HOOK_H */ diff --git a/include/jemalloc/internal/prof_threshold.h b/include/jemalloc/internal/prof_threshold.h deleted file mode 100644 index 93e9478e1c..0000000000 --- a/include/jemalloc/internal/prof_threshold.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef JEMALLOC_INTERNAL_THRESHOLD_EVENT_H -#define JEMALLOC_INTERNAL_THRESHOLD_EVENT_H - -#include "jemalloc/internal/tsd_types.h" - -extern te_base_cb_t prof_threshold_te_handler; - -#endif /* JEMALLOC_INTERNAL_THRESHOLD_EVENT_H */ diff --git a/include/jemalloc/internal/thread_event_registry.h b/include/jemalloc/internal/thread_event_registry.h index 7ded440d85..bfb140aaf8 100644 --- a/include/jemalloc/internal/thread_event_registry.h +++ b/include/jemalloc/internal/thread_event_registry.h @@ -14,7 +14,6 @@ enum te_alloc_e { te_alloc_stats_interval, te_alloc_tcache_gc, #ifdef JEMALLOC_STATS - te_alloc_prof_threshold, te_alloc_peak, #endif te_alloc_user0, diff --git a/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj b/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj index 1e8def75b5..ca2a8532e5 100644 --- a/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj +++ b/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj @@ -83,7 +83,6 @@ - diff --git a/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj.filters b/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj.filters index f6e340cf5d..443e71a576 100644 --- a/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj.filters +++ b/msvc/projects/vc2015/jemalloc/jemalloc.vcxproj.filters @@ -133,9 +133,6 @@ Source Files - - Source Files - Source Files diff --git a/msvc/projects/vc2017/jemalloc/jemalloc.vcxproj b/msvc/projects/vc2017/jemalloc/jemalloc.vcxproj index 45ddf73d1f..c5d1116b19 100644 --- a/msvc/projects/vc2017/jemalloc/jemalloc.vcxproj +++ b/msvc/projects/vc2017/jemalloc/jemalloc.vcxproj @@ -83,7 +83,6 @@ - diff --git a/msvc/projects/vc2017/jemalloc/jemalloc.vcxproj.filters b/msvc/projects/vc2017/jemalloc/jemalloc.vcxproj.filters index f6e340cf5d..443e71a576 100644 --- a/msvc/projects/vc2017/jemalloc/jemalloc.vcxproj.filters +++ b/msvc/projects/vc2017/jemalloc/jemalloc.vcxproj.filters @@ -133,9 +133,6 @@ Source Files - - Source Files - Source Files diff --git a/msvc/projects/vc2019/jemalloc/jemalloc.vcxproj b/msvc/projects/vc2019/jemalloc/jemalloc.vcxproj index f1a5158aae..4df570c816 100644 --- a/msvc/projects/vc2019/jemalloc/jemalloc.vcxproj +++ b/msvc/projects/vc2019/jemalloc/jemalloc.vcxproj @@ -83,7 +83,6 @@ - diff --git a/msvc/projects/vc2019/jemalloc/jemalloc.vcxproj.filters b/msvc/projects/vc2019/jemalloc/jemalloc.vcxproj.filters index f6e340cf5d..443e71a576 100644 --- a/msvc/projects/vc2019/jemalloc/jemalloc.vcxproj.filters +++ b/msvc/projects/vc2019/jemalloc/jemalloc.vcxproj.filters @@ -133,9 +133,6 @@ Source Files - - Source Files - Source Files diff --git a/msvc/projects/vc2022/jemalloc/jemalloc.vcxproj b/msvc/projects/vc2022/jemalloc/jemalloc.vcxproj index a6f92ccf8c..5e256ec6b9 100644 --- a/msvc/projects/vc2022/jemalloc/jemalloc.vcxproj +++ b/msvc/projects/vc2022/jemalloc/jemalloc.vcxproj @@ -83,7 +83,6 @@ - diff --git a/msvc/projects/vc2022/jemalloc/jemalloc.vcxproj.filters b/msvc/projects/vc2022/jemalloc/jemalloc.vcxproj.filters index f6e340cf5d..443e71a576 100644 --- a/msvc/projects/vc2022/jemalloc/jemalloc.vcxproj.filters +++ b/msvc/projects/vc2022/jemalloc/jemalloc.vcxproj.filters @@ -133,9 +133,6 @@ Source Files - - Source Files - Source Files diff --git a/src/ctl.c b/src/ctl.c index 1260e197da..4cac5608a4 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -156,7 +156,6 @@ CTL_PROTO(opt_prof_active) CTL_PROTO(opt_prof_thread_active_init) CTL_PROTO(opt_prof_bt_max) CTL_PROTO(opt_lg_prof_sample) -CTL_PROTO(opt_experimental_lg_prof_threshold) CTL_PROTO(opt_lg_prof_interval) CTL_PROTO(opt_prof_gdump) CTL_PROTO(opt_prof_final) @@ -364,7 +363,6 @@ CTL_PROTO(experimental_hooks_prof_backtrace) CTL_PROTO(experimental_hooks_prof_dump) CTL_PROTO(experimental_hooks_prof_sample) CTL_PROTO(experimental_hooks_prof_sample_free) -CTL_PROTO(experimental_hooks_prof_threshold) CTL_PROTO(experimental_hooks_thread_event) CTL_PROTO(experimental_hooks_safety_check_abort) CTL_PROTO(experimental_thread_activity_callback) @@ -527,8 +525,6 @@ static const ctl_named_node_t opt_node[] = {{NAME("abort"), CTL(opt_abort)}, {NAME("prof_thread_active_init"), CTL(opt_prof_thread_active_init)}, {NAME("prof_bt_max"), CTL(opt_prof_bt_max)}, {NAME("lg_prof_sample"), CTL(opt_lg_prof_sample)}, - {NAME("experimental_lg_prof_threshold"), - CTL(opt_experimental_lg_prof_threshold)}, {NAME("lg_prof_interval"), CTL(opt_lg_prof_interval)}, {NAME("prof_gdump"), CTL(opt_prof_gdump)}, {NAME("prof_final"), CTL(opt_prof_final)}, @@ -890,7 +886,6 @@ static const ctl_named_node_t experimental_hooks_node[] = { {NAME("prof_dump"), CTL(experimental_hooks_prof_dump)}, {NAME("prof_sample"), CTL(experimental_hooks_prof_sample)}, {NAME("prof_sample_free"), CTL(experimental_hooks_prof_sample_free)}, - {NAME("prof_threshold"), CTL(experimental_hooks_prof_threshold)}, {NAME("safety_check_abort"), CTL(experimental_hooks_safety_check_abort)}, {NAME("thread_event"), CTL(experimental_hooks_thread_event)}, }; @@ -2236,8 +2231,6 @@ CTL_RO_NL_CGEN( config_prof, opt_prof_thread_active_init, opt_prof_thread_active_init, bool) CTL_RO_NL_CGEN(config_prof, opt_prof_bt_max, opt_prof_bt_max, unsigned) CTL_RO_NL_CGEN(config_prof, opt_lg_prof_sample, opt_lg_prof_sample, size_t) -CTL_RO_NL_CGEN(config_prof, opt_experimental_lg_prof_threshold, - opt_experimental_lg_prof_threshold, size_t) CTL_RO_NL_CGEN(config_prof, opt_prof_accum, opt_prof_accum, bool) CTL_RO_NL_CGEN( config_prof, opt_prof_pid_namespace, opt_prof_pid_namespace, bool) @@ -3681,29 +3674,6 @@ experimental_hooks_prof_sample_free_ctl(tsd_t *tsd, const size_t *mib, return ret; } -static int -experimental_hooks_prof_threshold_ctl(tsd_t *tsd, const size_t *mib, - size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen) { - int ret; - - if (oldp == NULL && newp == NULL) { - ret = EINVAL; - goto label_return; - } - if (oldp != NULL) { - prof_threshold_hook_t old_hook = prof_threshold_hook_get(); - READ(old_hook, prof_threshold_hook_t); - } - if (newp != NULL) { - prof_threshold_hook_t new_hook JEMALLOC_CC_SILENCE_INIT(NULL); - WRITE(new_hook, prof_threshold_hook_t); - prof_threshold_hook_set(new_hook); - } - ret = 0; -label_return: - return ret; -} - static int experimental_hooks_thread_event_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen) { diff --git a/src/jemalloc.c b/src/jemalloc.c index 5d23962d67..d82788eba9 100644 --- a/src/jemalloc.c +++ b/src/jemalloc.c @@ -1747,11 +1747,6 @@ malloc_conf_init_helper(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS], "lg_prof_sample", 0, (sizeof(uint64_t) << 3) - 1, CONF_DONT_CHECK_MIN, CONF_CHECK_MAX, true) - CONF_HANDLE_SIZE_T( - opt_experimental_lg_prof_threshold, - "experimental_lg_prof_threshold", 0, - (sizeof(uint64_t) << 3) - 1, - CONF_DONT_CHECK_MIN, CONF_CHECK_MAX, true) CONF_HANDLE_BOOL(opt_prof_accum, "prof_accum") CONF_HANDLE_UNSIGNED(opt_prof_bt_max, "prof_bt_max", 1, PROF_BT_MAX_LIMIT, diff --git a/src/prof_threshold.c b/src/prof_threshold.c deleted file mode 100644 index 5b72a49188..0000000000 --- a/src/prof_threshold.c +++ /dev/null @@ -1,69 +0,0 @@ -#include "jemalloc/internal/jemalloc_preamble.h" -#include "jemalloc/internal/jemalloc_internal_includes.h" - -#include "jemalloc/internal/activity_callback.h" -#include "jemalloc/internal/prof_threshold.h" - -#include "jemalloc/internal/prof_externs.h" - -/* - * Update every 128MB by default. - */ -#define PROF_THRESHOLD_LG_WAIT_DEFAULT 27 - -/* Logically a prof_threshold_hook_t. */ -static atomic_p_t prof_threshold_hook; -size_t opt_experimental_lg_prof_threshold = PROF_THRESHOLD_LG_WAIT_DEFAULT; - -void -prof_threshold_hook_set(prof_threshold_hook_t hook) { - atomic_store_p(&prof_threshold_hook, hook, ATOMIC_RELEASE); -} - -prof_threshold_hook_t -prof_threshold_hook_get(void) { - return (prof_threshold_hook_t)atomic_load_p( - &prof_threshold_hook, ATOMIC_ACQUIRE); -} - -/* Invoke callback for threshold reached */ -static inline void -prof_threshold_update(tsd_t *tsd) { - prof_threshold_hook_t prof_threshold_hook = prof_threshold_hook_get(); - if (prof_threshold_hook == NULL) { - return; - } - uint64_t alloc = tsd_thread_allocated_get(tsd); - uint64_t dalloc = tsd_thread_deallocated_get(tsd); - peak_t *peak = tsd_peakp_get(tsd); - pre_reentrancy(tsd, NULL); - prof_threshold_hook(alloc, dalloc, peak->cur_max); - post_reentrancy(tsd); -} - -uint64_t -prof_threshold_new_event_wait(tsd_t *tsd) { - return 1 << opt_experimental_lg_prof_threshold; -} - -uint64_t -prof_threshold_postponed_event_wait(tsd_t *tsd) { - return TE_MIN_START_WAIT; -} - -void -prof_threshold_event_handler(tsd_t *tsd) { - prof_threshold_update(tsd); -} - -static te_enabled_t -prof_threshold_enabled(void) { - return config_stats ? te_enabled_yes : te_enabled_no; -} - -te_base_cb_t prof_threshold_te_handler = { - .enabled = &prof_threshold_enabled, - .new_event_wait = &prof_threshold_new_event_wait, - .postponed_event_wait = &prof_threshold_postponed_event_wait, - .event_handler = &prof_threshold_event_handler, -}; diff --git a/src/thread_event.c b/src/thread_event.c index c59027ed77..82776342ea 100644 --- a/src/thread_event.c +++ b/src/thread_event.c @@ -290,15 +290,6 @@ te_update_alloc_events(tsd_t *tsd, te_base_cb_t **to_trigger, to_trigger[nto_trigger++] = te_alloc_handlers[te_alloc_peak]; } - assert(te_enabled_yes - == te_alloc_handlers[te_alloc_prof_threshold]->enabled()); - if (te_update_wait(tsd, accumbytes, allow, - &waits[te_alloc_prof_threshold], wait, - te_alloc_handlers[te_alloc_prof_threshold], - 1 << opt_experimental_lg_prof_threshold)) { - to_trigger[nto_trigger++] = - te_alloc_handlers[te_alloc_prof_threshold]; - } #endif for (te_alloc_t ue = te_alloc_user0; ue <= te_alloc_user3; ue++) { diff --git a/src/thread_event_registry.c b/src/thread_event_registry.c index 05882616a7..b8307df067 100644 --- a/src/thread_event_registry.c +++ b/src/thread_event_registry.c @@ -6,7 +6,6 @@ #include "jemalloc/internal/tcache_externs.h" #include "jemalloc/internal/peak_event.h" #include "jemalloc/internal/prof_externs.h" -#include "jemalloc/internal/prof_threshold.h" #include "jemalloc/internal/stats.h" static malloc_mutex_t uevents_mu; @@ -149,7 +148,7 @@ te_base_cb_t *te_alloc_handlers[te_alloc_count] = { #endif &stats_interval_te_handler, &tcache_gc_te_handler, #ifdef JEMALLOC_STATS - &prof_threshold_te_handler, &peak_te_handler, + &peak_te_handler, #endif &user_alloc_handler0, &user_alloc_handler1, &user_alloc_handler2, &user_alloc_handler3}; diff --git a/test/unit/mallctl.c b/test/unit/mallctl.c index 4c11e4857d..4cd0225bed 100644 --- a/test/unit/mallctl.c +++ b/test/unit/mallctl.c @@ -342,7 +342,6 @@ TEST_BEGIN(test_mallctl_opt) { TEST_MALLCTL_OPT(bool, prof_active, prof); TEST_MALLCTL_OPT(unsigned, prof_bt_max, prof); TEST_MALLCTL_OPT(ssize_t, lg_prof_sample, prof); - TEST_MALLCTL_OPT(ssize_t, experimental_lg_prof_threshold, prof); TEST_MALLCTL_OPT(bool, prof_accum, prof); TEST_MALLCTL_OPT(bool, prof_pid_namespace, prof); TEST_MALLCTL_OPT(ssize_t, lg_prof_interval, prof); diff --git a/test/unit/prof_threshold.c b/test/unit/prof_threshold.c deleted file mode 100644 index a31a5a24f2..0000000000 --- a/test/unit/prof_threshold.c +++ /dev/null @@ -1,112 +0,0 @@ -#include "test/jemalloc_test.h" - -/* Test config (set in reset_test_config) */ -#define ALLOC_ITERATIONS_IN_THRESHOLD 10 -uint64_t threshold_bytes = 0; -uint64_t chunk_size = 0; - -/* Test globals for calblack */ -uint64_t hook_calls = 0; -uint64_t last_peak = 0; -uint64_t last_alloc = 0; -uint64_t alloc_baseline = 0; - -void -mock_prof_threshold_hook(uint64_t alloc, uint64_t dealloc, uint64_t peak) { - hook_calls++; - last_peak = peak; - last_alloc = alloc; -} - -/* Need the do_write flag because NULL is a valid to_write value. */ -static void -read_write_prof_threshold_hook(prof_threshold_hook_t *to_read, bool do_write, - prof_threshold_hook_t to_write) { - size_t hook_sz = sizeof(prof_threshold_hook_t); - expect_d_eq( - mallctl("experimental.hooks.prof_threshold", (void *)to_read, - &hook_sz, do_write ? &to_write : NULL, hook_sz), - 0, "Unexpected prof_threshold_hook mallctl failure"); -} - -static void -write_prof_threshold_hook(prof_threshold_hook_t new_hook) { - read_write_prof_threshold_hook(NULL, true, new_hook); -} - -static prof_threshold_hook_t -read_prof_threshold_hook() { - prof_threshold_hook_t hook; - read_write_prof_threshold_hook(&hook, false, NULL); - return hook; -} - -static void -reset_test_config() { - hook_calls = 0; - last_peak = 0; - alloc_baseline = last_alloc; /* We run the test multiple times */ - last_alloc = 0; - threshold_bytes = 1 << opt_experimental_lg_prof_threshold; - chunk_size = threshold_bytes / ALLOC_ITERATIONS_IN_THRESHOLD; -} - -static void -expect_threshold_calls(int calls) { - expect_u64_eq( - hook_calls, calls, "Hook called the right amount of times"); - expect_u64_lt( - last_peak, chunk_size * 2, "We allocate chunk_size at a time"); - expect_u64_ge( - last_alloc, threshold_bytes * calls + alloc_baseline, "Crosses"); -} - -static void -allocate_chunks(int chunks) { - for (int i = 0; i < chunks; i++) { - void *p = mallocx((size_t)chunk_size, 0); - expect_ptr_not_null(p, "Failed to allocate"); - free(p); - } -} - -TEST_BEGIN(test_prof_threshold_hook) { - test_skip_if(!config_stats); - - /* Test setting and reading the hook (both value and null) */ - write_prof_threshold_hook(mock_prof_threshold_hook); - expect_ptr_eq(read_prof_threshold_hook(), mock_prof_threshold_hook, - "Unexpected hook"); - - write_prof_threshold_hook(NULL); - expect_ptr_null(read_prof_threshold_hook(), "Hook was erased"); - - /* Reset everything before the test */ - reset_test_config(); - write_prof_threshold_hook(mock_prof_threshold_hook); - - int err = mallctl("thread.peak.reset", NULL, NULL, NULL, 0); - expect_d_eq(err, 0, "Peak reset failed"); - - /* Note that since we run this test multiple times and we don't reset - the allocation counter, each time we offset the callback by the - amount we allocate over the threshold. */ - - /* A simple small allocation is not enough to trigger the callback */ - allocate_chunks(1); - expect_u64_eq(hook_calls, 0, "Hook not called yet"); - - /* Enough allocations to trigger the callback */ - allocate_chunks(ALLOC_ITERATIONS_IN_THRESHOLD); - expect_threshold_calls(1); - - /* Enough allocations to trigger the callback again */ - allocate_chunks(ALLOC_ITERATIONS_IN_THRESHOLD); - expect_threshold_calls(2); -} -TEST_END - -int -main(void) { - return test(test_prof_threshold_hook); -} diff --git a/test/unit/prof_threshold_small.c b/test/unit/prof_threshold_small.c deleted file mode 100644 index 67f444b1b0..0000000000 --- a/test/unit/prof_threshold_small.c +++ /dev/null @@ -1,2 +0,0 @@ -#include "test/jemalloc_test.h" -#include "prof_threshold.c" diff --git a/test/unit/prof_threshold_small.sh b/test/unit/prof_threshold_small.sh deleted file mode 100644 index 62726069b4..0000000000 --- a/test/unit/prof_threshold_small.sh +++ /dev/null @@ -1 +0,0 @@ -export MALLOC_CONF="experimental_lg_prof_threshold:22"