jemalloc/src/inspect.c
Slobodan Predolac c411b0ab3b Collapse arena_inlines_a/b and jemalloc_internal_inlines_b into arena_inlines.h
The arena_inlines_a.h / arena_inlines_b.h split, and the parallel
jemalloc_internal_inlines_b.h file that defined arena_choose() between
them, all existed to manage one ordering constraint: arena_choose()
had to be defined before arena_choose_maybe_huge() (which calls it),
but had to be defined after the tsd/tcache inlines it depends on.
Three files, one staged include order, no real semantic boundary.

After the malloc_dispatch refactor moved the heaviest tcache-pulling
inlines (the malloc/dalloc routing) out of arena_inlines_b.h, the
arena-side inlines that remain all belong together.  Merge them into
a single arena_inlines.h that:

  - explicitly includes jemalloc_internal_inlines_a.h (for tsd
    accessors) and tcache.h (for tcache_arena_associate /
    reassociate externs) -- both were previously pulled
    transitively;
  - orders functions so each caller appears after its callee
    (cheap accessors -> arena_choose family -> the rest), so no
    forward references are needed;
  - drops the load-bearing-split comment, which is no longer true.

All consumers that included any of the three old headers now include
arena_inlines.h.  background_thread_inlines.h now pulls a heavier set
of transitive includes (prof.h, large.h, mutex.h, ...) than when it
only needed cheap accessors; this is acceptable because every TU that
includes background_thread_inlines.h already pulls those headers via
other paths.
2026-05-29 09:04:09 -07:00

82 lines
2.4 KiB
C

#include "jemalloc/internal/jemalloc_preamble.h"
#include "jemalloc/internal/arena.h"
#include "jemalloc/internal/arena_inlines.h"
#include "jemalloc/internal/bin_info.h"
#include "jemalloc/internal/edata.h"
#include "jemalloc/internal/emap.h"
#include "jemalloc/internal/inspect.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);
const edata_t *edata = emap_edata_lookup(tsdn, &arena_emap_global, ptr);
if (unlikely(edata == NULL)) {
*nfree = *nregs = *size = 0;
return;
}
*size = edata_size_get(edata);
if (!edata_slab_get(edata)) {
*nfree = 0;
*nregs = 1;
} else {
*nfree = edata_nfree_get(edata);
*nregs = bin_infos[edata_szind_get(edata)].nregs;
assert(*nfree <= *nregs);
assert(*nfree * edata_usize_get(edata) <= *size);
}
}
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);
const edata_t *edata = emap_edata_lookup(tsdn, &arena_emap_global, ptr);
if (unlikely(edata == NULL)) {
*nfree = *nregs = *size = *bin_nfree = *bin_nregs = 0;
*slabcur_addr = NULL;
return;
}
*size = edata_size_get(edata);
if (!edata_slab_get(edata)) {
*nfree = *bin_nfree = *bin_nregs = 0;
*nregs = 1;
*slabcur_addr = NULL;
return;
}
*nfree = edata_nfree_get(edata);
const szind_t szind = edata_szind_get(edata);
*nregs = bin_infos[szind].nregs;
assert(*nfree <= *nregs);
assert(*nfree * edata_usize_get(edata) <= *size);
arena_t *arena = arena_get_from_edata(edata);
assert(arena != NULL);
const unsigned binshard = edata_binshard_get(edata);
bin_t *bin = arena_get_bin(arena, szind, binshard);
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;
}
edata_t *slab;
if (bin->slabcur != NULL) {
slab = bin->slabcur;
} else {
slab = edata_heap_first(&bin->slabs_nonfull);
}
*slabcur_addr = slab != NULL ? edata_addr_get(slab) : NULL;
malloc_mutex_unlock(tsdn, &bin->lock);
}