mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-23 13:13:06 +00:00
Extract bin->stats.nrequests mutation into bin_stats_nrequests_add
This commit is contained in:
@@ -100,6 +100,13 @@ bin_t *bin_choose(tsdn_t *tsdn, arena_t *arena, szind_t binind,
|
|||||||
unsigned *binshard_p);
|
unsigned *binshard_p);
|
||||||
|
|
||||||
/* Stats. */
|
/* Stats. */
|
||||||
|
static inline void
|
||||||
|
bin_stats_nrequests_add(tsdn_t *tsdn, bin_t *bin, uint64_t n) {
|
||||||
|
malloc_mutex_lock(tsdn, &bin->lock);
|
||||||
|
bin->stats.nrequests += n;
|
||||||
|
malloc_mutex_unlock(tsdn, &bin->lock);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
bin_stats_merge(tsdn_t *tsdn, bin_stats_data_t *dst_bin_stats, bin_t *bin) {
|
bin_stats_merge(tsdn_t *tsdn, bin_stats_data_t *dst_bin_stats, bin_t *bin) {
|
||||||
malloc_mutex_lock(tsdn, &bin->lock);
|
malloc_mutex_lock(tsdn, &bin->lock);
|
||||||
|
|||||||
@@ -1287,9 +1287,8 @@ tcache_stats_merge(tsdn_t *tsdn, tcache_t *tcache, arena_t *arena) {
|
|||||||
}
|
}
|
||||||
if (i < SC_NBINS) {
|
if (i < SC_NBINS) {
|
||||||
bin_t *bin = bin_choose(tsdn, arena, i, NULL);
|
bin_t *bin = bin_choose(tsdn, arena, i, NULL);
|
||||||
malloc_mutex_lock(tsdn, &bin->lock);
|
bin_stats_nrequests_add(tsdn, bin,
|
||||||
bin->stats.nrequests += cache_bin->tstats.nrequests;
|
cache_bin->tstats.nrequests);
|
||||||
malloc_mutex_unlock(tsdn, &bin->lock);
|
|
||||||
} else {
|
} else {
|
||||||
arena_stats_large_flush_nrequests_add(tsdn,
|
arena_stats_large_flush_nrequests_add(tsdn,
|
||||||
&arena->stats, i, cache_bin->tstats.nrequests);
|
&arena->stats, i, cache_bin->tstats.nrequests);
|
||||||
|
|||||||
@@ -647,6 +647,42 @@ TEST_BEGIN(test_bin_dalloc_slab_prepare) {
|
|||||||
}
|
}
|
||||||
TEST_END
|
TEST_END
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test that bin_stats_nrequests_add accumulates under the bin lock.
|
||||||
|
*/
|
||||||
|
TEST_BEGIN(test_bin_stats_nrequests_add) {
|
||||||
|
tsdn_t *tsdn = tsdn_fetch();
|
||||||
|
bin_t bin;
|
||||||
|
|
||||||
|
bin_init(&bin);
|
||||||
|
if (config_stats) {
|
||||||
|
expect_u64_eq(bin.stats.nrequests, 0,
|
||||||
|
"Fresh bin should have zero nrequests");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Single add. */
|
||||||
|
bin_stats_nrequests_add(tsdn, &bin, 7);
|
||||||
|
if (config_stats) {
|
||||||
|
expect_u64_eq(bin.stats.nrequests, 7,
|
||||||
|
"nrequests should equal the added value");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adds accumulate. */
|
||||||
|
bin_stats_nrequests_add(tsdn, &bin, 3);
|
||||||
|
if (config_stats) {
|
||||||
|
expect_u64_eq(bin.stats.nrequests, 10,
|
||||||
|
"nrequests should accumulate across calls");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adding zero is a no-op. */
|
||||||
|
bin_stats_nrequests_add(tsdn, &bin, 0);
|
||||||
|
if (config_stats) {
|
||||||
|
expect_u64_eq(bin.stats.nrequests, 10,
|
||||||
|
"Adding zero should not change nrequests");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TEST_END
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test bin_shard_sizes_boot and bin_update_shard_size.
|
* Test bin_shard_sizes_boot and bin_update_shard_size.
|
||||||
*/
|
*/
|
||||||
@@ -819,6 +855,7 @@ main(void) {
|
|||||||
test_bin_lower_slab_replaces_slabcur,
|
test_bin_lower_slab_replaces_slabcur,
|
||||||
test_bin_lower_slab_inserts_nonfull,
|
test_bin_lower_slab_inserts_nonfull,
|
||||||
test_bin_dalloc_slab_prepare,
|
test_bin_dalloc_slab_prepare,
|
||||||
|
test_bin_stats_nrequests_add,
|
||||||
test_bin_shard_sizes,
|
test_bin_shard_sizes,
|
||||||
test_bin_alloc_free_cycle,
|
test_bin_alloc_free_cycle,
|
||||||
test_bin_multi_size_class);
|
test_bin_multi_size_class);
|
||||||
|
|||||||
Reference in New Issue
Block a user