2019-12-05 01:44:59 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_preamble.h"
|
|
|
|
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
inspect_extent_util_stats_get(tsdn_t *tsdn, const void *ptr, size_t *nfree,
|
|
|
|
size_t *nregs, size_t *size) {
|
|
|
|
assert(ptr != NULL && nfree != NULL && nregs != NULL && size != NULL);
|
|
|
|
|
2020-03-15 01:49:34 +08:00
|
|
|
const edata_t *edata = emap_edata_lookup(tsdn, &arena_emap_global, ptr);
|
2019-12-10 06:36:45 +08:00
|
|
|
if (unlikely(edata == NULL)) {
|
2019-12-05 01:44:59 +08:00
|
|
|
*nfree = *nregs = *size = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-10 06:36:45 +08:00
|
|
|
*size = edata_size_get(edata);
|
|
|
|
if (!edata_slab_get(edata)) {
|
2019-12-05 01:44:59 +08:00
|
|
|
*nfree = 0;
|
|
|
|
*nregs = 1;
|
|
|
|
} else {
|
2019-12-10 06:36:45 +08:00
|
|
|
*nfree = edata_nfree_get(edata);
|
|
|
|
*nregs = bin_infos[edata_szind_get(edata)].nregs;
|
2019-12-05 01:44:59 +08:00
|
|
|
assert(*nfree <= *nregs);
|
2019-12-10 06:36:45 +08:00
|
|
|
assert(*nfree * edata_usize_get(edata) <= *size);
|
2019-12-05 01:44:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
inspect_extent_util_stats_verbose_get(tsdn_t *tsdn, const void *ptr,
|
|
|
|
size_t *nfree, size_t *nregs, size_t *size, size_t *bin_nfree,
|
|
|
|
size_t *bin_nregs, void **slabcur_addr) {
|
|
|
|
assert(ptr != NULL && nfree != NULL && nregs != NULL && size != NULL
|
|
|
|
&& bin_nfree != NULL && bin_nregs != NULL && slabcur_addr != NULL);
|
|
|
|
|
2020-03-15 01:49:34 +08:00
|
|
|
const edata_t *edata = emap_edata_lookup(tsdn, &arena_emap_global, ptr);
|
2019-12-10 06:36:45 +08:00
|
|
|
if (unlikely(edata == NULL)) {
|
2019-12-05 01:44:59 +08:00
|
|
|
*nfree = *nregs = *size = *bin_nfree = *bin_nregs = 0;
|
|
|
|
*slabcur_addr = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-10 06:36:45 +08:00
|
|
|
*size = edata_size_get(edata);
|
|
|
|
if (!edata_slab_get(edata)) {
|
2019-12-05 01:44:59 +08:00
|
|
|
*nfree = *bin_nfree = *bin_nregs = 0;
|
|
|
|
*nregs = 1;
|
|
|
|
*slabcur_addr = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-10 06:36:45 +08:00
|
|
|
*nfree = edata_nfree_get(edata);
|
|
|
|
const szind_t szind = edata_szind_get(edata);
|
2019-12-05 01:44:59 +08:00
|
|
|
*nregs = bin_infos[szind].nregs;
|
|
|
|
assert(*nfree <= *nregs);
|
2019-12-10 06:36:45 +08:00
|
|
|
assert(*nfree * edata_usize_get(edata) <= *size);
|
2019-12-05 01:44:59 +08:00
|
|
|
|
2021-01-31 07:35:33 +08:00
|
|
|
arena_t *arena = (arena_t *)atomic_load_p(
|
2019-12-10 06:36:45 +08:00
|
|
|
&arenas[edata_arena_ind_get(edata)], ATOMIC_RELAXED);
|
2019-12-05 01:44:59 +08:00
|
|
|
assert(arena != NULL);
|
2019-12-10 06:36:45 +08:00
|
|
|
const unsigned binshard = edata_binshard_get(edata);
|
2021-01-31 07:35:33 +08:00
|
|
|
bin_t *bin = arena_get_bin(arena, szind, binshard);
|
2019-12-05 01:44:59 +08:00
|
|
|
|
|
|
|
malloc_mutex_lock(tsdn, &bin->lock);
|
|
|
|
if (config_stats) {
|
|
|
|
*bin_nregs = *nregs * bin->stats.curslabs;
|
|
|
|
assert(*bin_nregs >= bin->stats.curregs);
|
|
|
|
*bin_nfree = *bin_nregs - bin->stats.curregs;
|
|
|
|
} else {
|
|
|
|
*bin_nfree = *bin_nregs = 0;
|
|
|
|
}
|
2019-12-10 06:36:45 +08:00
|
|
|
edata_t *slab;
|
2019-12-05 01:44:59 +08:00
|
|
|
if (bin->slabcur != NULL) {
|
|
|
|
slab = bin->slabcur;
|
|
|
|
} else {
|
2019-12-10 06:36:45 +08:00
|
|
|
slab = edata_heap_first(&bin->slabs_nonfull);
|
2019-12-05 01:44:59 +08:00
|
|
|
}
|
2019-12-10 06:36:45 +08:00
|
|
|
*slabcur_addr = slab != NULL ? edata_addr_get(slab) : NULL;
|
2019-12-05 01:44:59 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &bin->lock);
|
|
|
|
}
|