2017-11-05 03:50:19 +08:00
|
|
|
#ifndef JEMALLOC_INTERNAL_ARENA_STATS_H
|
|
|
|
#define JEMALLOC_INTERNAL_ARENA_STATS_H
|
|
|
|
|
|
|
|
#include "jemalloc/internal/atomic.h"
|
2020-03-09 11:43:41 +08:00
|
|
|
#include "jemalloc/internal/lockedint.h"
|
2017-11-05 03:50:19 +08:00
|
|
|
#include "jemalloc/internal/mutex.h"
|
|
|
|
#include "jemalloc/internal/mutex_prof.h"
|
2020-03-09 04:08:15 +08:00
|
|
|
#include "jemalloc/internal/pa.h"
|
2017-12-15 04:46:39 +08:00
|
|
|
#include "jemalloc/internal/sc.h"
|
2017-11-05 03:50:19 +08:00
|
|
|
|
2018-05-03 17:40:53 +08:00
|
|
|
JEMALLOC_DIAGNOSTIC_DISABLE_SPURIOUS
|
|
|
|
|
2017-11-05 03:50:19 +08:00
|
|
|
typedef struct arena_stats_large_s arena_stats_large_t;
|
|
|
|
struct arena_stats_large_s {
|
|
|
|
/*
|
|
|
|
* Total number of allocation/deallocation requests served directly by
|
|
|
|
* the arena.
|
|
|
|
*/
|
2020-03-09 11:43:41 +08:00
|
|
|
locked_u64_t nmalloc;
|
|
|
|
locked_u64_t ndalloc;
|
2017-11-05 03:50:19 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Number of allocation requests that correspond to this size class.
|
|
|
|
* This includes requests served by tcache, though tcache only
|
|
|
|
* periodically merges into this counter.
|
|
|
|
*/
|
2020-03-09 11:43:41 +08:00
|
|
|
locked_u64_t nrequests; /* Partially derived. */
|
2019-05-07 07:36:55 +08:00
|
|
|
/*
|
|
|
|
* Number of tcache fills / flushes for large (similarly, periodically
|
|
|
|
* merged). Note that there is no large tcache batch-fill currently
|
|
|
|
* (i.e. only fill 1 at a time); however flush may be batched.
|
|
|
|
*/
|
2020-03-09 11:43:41 +08:00
|
|
|
locked_u64_t nfills; /* Partially derived. */
|
|
|
|
locked_u64_t nflushes; /* Partially derived. */
|
2017-11-05 03:50:19 +08:00
|
|
|
|
|
|
|
/* Current number of allocations of this size class. */
|
|
|
|
size_t curlextents; /* Derived. */
|
|
|
|
};
|
|
|
|
|
2018-08-01 00:49:49 +08:00
|
|
|
typedef struct arena_stats_extents_s arena_stats_extents_t;
|
|
|
|
struct arena_stats_extents_s {
|
|
|
|
/*
|
|
|
|
* Stats for a given index in the range [0, SC_NPSIZES] in an extents_t.
|
|
|
|
* We track both bytes and # of extents: two extents in the same bucket
|
|
|
|
* may have different sizes if adjacent size classes differ by more than
|
|
|
|
* a page, so bytes cannot always be derived from # of extents.
|
|
|
|
*/
|
|
|
|
atomic_zu_t ndirty;
|
|
|
|
atomic_zu_t dirty_bytes;
|
|
|
|
atomic_zu_t nmuzzy;
|
|
|
|
atomic_zu_t muzzy_bytes;
|
|
|
|
atomic_zu_t nretained;
|
|
|
|
atomic_zu_t retained_bytes;
|
|
|
|
};
|
|
|
|
|
2017-11-05 03:50:19 +08:00
|
|
|
/*
|
|
|
|
* Arena stats. Note that fields marked "derived" are not directly maintained
|
|
|
|
* within the arena code; rather their values are derived during stats merge
|
|
|
|
* requests.
|
|
|
|
*/
|
|
|
|
typedef struct arena_stats_s arena_stats_t;
|
|
|
|
struct arena_stats_s {
|
2020-03-09 11:43:41 +08:00
|
|
|
LOCKEDINT_MTX_DECLARE(mtx)
|
2017-11-05 03:50:19 +08:00
|
|
|
/*
|
|
|
|
* Number of unused virtual memory bytes currently retained. Retained
|
|
|
|
* bytes are technically mapped (though always decommitted or purged),
|
|
|
|
* but they are excluded from the mapped statistic (above).
|
|
|
|
*/
|
2020-03-09 11:43:41 +08:00
|
|
|
locked_zu_t retained; /* Derived. */
|
2017-11-05 03:50:19 +08:00
|
|
|
|
2019-12-10 06:36:45 +08:00
|
|
|
/* Number of edata_t structs allocated by base, but not being used. */
|
2020-03-10 04:19:09 +08:00
|
|
|
atomic_zu_t edata_avail; /* Derived. */
|
2018-08-02 05:14:33 +08:00
|
|
|
|
2017-11-05 03:50:19 +08:00
|
|
|
atomic_zu_t base; /* Derived. */
|
|
|
|
atomic_zu_t internal;
|
|
|
|
atomic_zu_t resident; /* Derived. */
|
|
|
|
atomic_zu_t metadata_thp;
|
|
|
|
|
|
|
|
atomic_zu_t allocated_large; /* Derived. */
|
2020-03-09 11:43:41 +08:00
|
|
|
locked_u64_t nmalloc_large; /* Derived. */
|
|
|
|
locked_u64_t ndalloc_large; /* Derived. */
|
|
|
|
locked_u64_t nfills_large; /* Derived. */
|
|
|
|
locked_u64_t nflushes_large; /* Derived. */
|
|
|
|
locked_u64_t nrequests_large; /* Derived. */
|
2017-11-05 03:50:19 +08:00
|
|
|
|
2020-03-09 04:08:15 +08:00
|
|
|
/*
|
|
|
|
* The stats logically owned by the pa_shard in the same arena. This
|
|
|
|
* lives here only because it's convenient for the purposes of the ctl
|
|
|
|
* module -- it only knows about the single arena_stats.
|
|
|
|
*/
|
|
|
|
pa_shard_stats_t pa_shard_stats;
|
2019-07-16 06:56:05 +08:00
|
|
|
|
2017-11-05 03:50:19 +08:00
|
|
|
/* Number of bytes cached in tcache associated with this arena. */
|
|
|
|
atomic_zu_t tcache_bytes; /* Derived. */
|
|
|
|
|
|
|
|
mutex_prof_data_t mutex_prof_data[mutex_prof_num_arena_mutexes];
|
|
|
|
|
|
|
|
/* One element for each large size class. */
|
2017-12-15 04:46:39 +08:00
|
|
|
arena_stats_large_t lstats[SC_NSIZES - SC_NBINS];
|
2017-11-05 03:50:19 +08:00
|
|
|
|
|
|
|
/* Arena uptime. */
|
|
|
|
nstime_t uptime;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool
|
2018-05-03 17:40:53 +08:00
|
|
|
arena_stats_init(tsdn_t *tsdn, arena_stats_t *arena_stats) {
|
2017-11-05 03:50:19 +08:00
|
|
|
if (config_debug) {
|
|
|
|
for (size_t i = 0; i < sizeof(arena_stats_t); i++) {
|
|
|
|
assert(((char *)arena_stats)[i] == 0);
|
|
|
|
}
|
|
|
|
}
|
2020-03-09 11:43:41 +08:00
|
|
|
if (LOCKEDINT_MTX_INIT(LOCKEDINT_MTX(arena_stats->mtx), "arena_stats",
|
2017-11-05 03:50:19 +08:00
|
|
|
WITNESS_RANK_ARENA_STATS, malloc_mutex_rank_exclusive)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
/* Memory is zeroed, so there is no need to clear stats. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-05-07 07:36:55 +08:00
|
|
|
arena_stats_large_flush_nrequests_add(tsdn_t *tsdn, arena_stats_t *arena_stats,
|
2017-11-05 03:50:19 +08:00
|
|
|
szind_t szind, uint64_t nrequests) {
|
2020-03-09 11:43:41 +08:00
|
|
|
LOCKEDINT_MTX_LOCK(tsdn, arena_stats->mtx);
|
2019-05-07 07:36:55 +08:00
|
|
|
arena_stats_large_t *lstats = &arena_stats->lstats[szind - SC_NBINS];
|
2020-03-09 11:43:41 +08:00
|
|
|
locked_inc_u64(tsdn, LOCKEDINT_MTX(arena_stats->mtx),
|
|
|
|
&lstats->nrequests, nrequests);
|
|
|
|
locked_inc_u64(tsdn, LOCKEDINT_MTX(arena_stats->mtx),
|
|
|
|
&lstats->nflushes, 1);
|
|
|
|
LOCKEDINT_MTX_UNLOCK(tsdn, arena_stats->mtx);
|
2017-11-05 03:50:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* JEMALLOC_INTERNAL_ARENA_STATS_H */
|