Remove build-time configuration 'config_limit_usize_gap'

This commit is contained in:
Guangli Dai 2025-04-15 23:50:43 -07:00 committed by Qi Wang
parent 852da1be15
commit 01e9ecbeb2
15 changed files with 160 additions and 244 deletions

View file

@ -154,17 +154,12 @@ arena_stats_merge(tsdn_t *tsdn, arena_t *arena, unsigned *nthreads,
size_t curlextents = (size_t)(nmalloc - ndalloc);
lstats[i].curlextents += curlextents;
if (config_limit_usize_gap) {
uint64_t active_bytes = locked_read_u64(tsdn,
LOCKEDINT_MTX(arena->stats.mtx),
&arena->stats.lstats[i].active_bytes);
locked_inc_u64_unsynchronized(
&lstats[i].active_bytes, active_bytes);
astats->allocated_large += active_bytes;
} else {
astats->allocated_large +=
curlextents * sz_index2size(SC_NBINS + i);
}
uint64_t active_bytes = locked_read_u64(tsdn,
LOCKEDINT_MTX(arena->stats.mtx),
&arena->stats.lstats[i].active_bytes);
locked_inc_u64_unsynchronized(
&lstats[i].active_bytes, active_bytes);
astats->allocated_large += active_bytes;
}
pa_shard_stats_merge(tsdn, &arena->pa_shard, &astats->pa_shard_stats,
@ -333,11 +328,9 @@ arena_large_malloc_stats_update(tsdn_t *tsdn, arena_t *arena, size_t usize) {
LOCKEDINT_MTX_LOCK(tsdn, arena->stats.mtx);
locked_inc_u64(tsdn, LOCKEDINT_MTX(arena->stats.mtx),
&arena->stats.lstats[hindex].nmalloc, 1);
if (config_limit_usize_gap) {
locked_inc_u64(tsdn, LOCKEDINT_MTX(arena->stats.mtx),
&arena->stats.lstats[hindex].active_bytes,
usize);
}
locked_inc_u64(tsdn, LOCKEDINT_MTX(arena->stats.mtx),
&arena->stats.lstats[hindex].active_bytes,
usize);
LOCKEDINT_MTX_UNLOCK(tsdn, arena->stats.mtx);
}
}
@ -361,11 +354,9 @@ arena_large_dalloc_stats_update(tsdn_t *tsdn, arena_t *arena, size_t usize) {
LOCKEDINT_MTX_LOCK(tsdn, arena->stats.mtx);
locked_inc_u64(tsdn, LOCKEDINT_MTX(arena->stats.mtx),
&arena->stats.lstats[hindex].ndalloc, 1);
if (config_limit_usize_gap) {
locked_dec_u64(tsdn, LOCKEDINT_MTX(arena->stats.mtx),
&arena->stats.lstats[hindex].active_bytes,
usize);
}
locked_dec_u64(tsdn, LOCKEDINT_MTX(arena->stats.mtx),
&arena->stats.lstats[hindex].active_bytes,
usize);
LOCKEDINT_MTX_UNLOCK(tsdn, arena->stats.mtx);
}
}

View file

@ -2355,8 +2355,7 @@ CTL_RO_NL_CGEN(config_uaf_detection, opt_lg_san_uaf_align,
opt_lg_san_uaf_align, ssize_t)
CTL_RO_NL_GEN(opt_zero_realloc,
zero_realloc_mode_names[opt_zero_realloc_action], const char *)
CTL_RO_NL_CGEN(config_limit_usize_gap, opt_limit_usize_gap, opt_limit_usize_gap,
bool)
CTL_RO_NL_GEN(opt_limit_usize_gap, opt_limit_usize_gap, bool)
/* malloc_conf options */
CTL_RO_NL_CGEN(opt_malloc_conf_symlink, opt_malloc_conf_symlink,

View file

@ -123,12 +123,7 @@ zero_realloc_action_t opt_zero_realloc_action =
atomic_zu_t zero_realloc_count = ATOMIC_INIT(0);
bool opt_limit_usize_gap =
#ifdef LIMIT_USIZE_GAP
true;
#else
false;
#endif
bool opt_limit_usize_gap = true;
const char *const zero_realloc_mode_names[] = {
"alloc",
@ -1785,10 +1780,8 @@ malloc_conf_init_helper(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS],
"san_guard_large", 0, SIZE_T_MAX,
CONF_DONT_CHECK_MIN, CONF_DONT_CHECK_MAX, false)
if (config_limit_usize_gap) {
CONF_HANDLE_BOOL(opt_limit_usize_gap,
"limit_usize_gap");
}
CONF_HANDLE_BOOL(opt_limit_usize_gap,
"limit_usize_gap");
CONF_ERROR("Invalid conf pair", k, klen, v, vlen);
#undef CONF_ERROR
@ -2209,17 +2202,16 @@ static bool
malloc_init_hard(void) {
tsd_t *tsd;
if (config_limit_usize_gap) {
assert(TCACHE_MAXCLASS_LIMIT <= USIZE_GROW_SLOW_THRESHOLD);
assert(SC_LOOKUP_MAXCLASS <= USIZE_GROW_SLOW_THRESHOLD);
/*
* This asserts an extreme case where TINY_MAXCLASS is larger
* than LARGE_MINCLASS. It could only happen if some constants
* are configured miserably wrong.
*/
assert(SC_LG_TINY_MAXCLASS <=
(size_t)1ULL << (LG_PAGE + SC_LG_NGROUP));
}
assert(TCACHE_MAXCLASS_LIMIT <= USIZE_GROW_SLOW_THRESHOLD);
assert(SC_LOOKUP_MAXCLASS <= USIZE_GROW_SLOW_THRESHOLD);
/*
* This asserts an extreme case where TINY_MAXCLASS is larger
* than LARGE_MINCLASS. It could only happen if some constants
* are configured miserably wrong.
*/
assert(SC_LG_TINY_MAXCLASS <=
(size_t)1ULL << (LG_PAGE + SC_LG_NGROUP));
#if defined(_WIN32) && _WIN32_WINNT < 0x0600
_init_init_lock();
#endif