#define ALIGNMENT 8U /*%< must be a power of 2 */
#define ALIGNMENT_SIZE sizeof(size_info)
#define DEBUG_TABLE_COUNT 512U
-#define STATS_BUCKETS 512U
-#define STATS_BUCKET_SIZE 32U
/*
* Types.
element *next;
};
-struct stats {
- atomic_size_t gets;
-};
-
#define MEM_MAGIC ISC_MAGIC('M', 'e', 'm', 'C')
#define VALID_CONTEXT(c) ISC_MAGIC_VALID(c, MEM_MAGIC)
unsigned int debugging;
isc_mutex_t lock;
bool checkfree;
- struct stats stats[STATS_BUCKETS + 1];
isc_refcount_t references;
char name[16];
atomic_size_t inuse;
*/
static void
mem_getstats(isc_mem_t *ctx, size_t size) {
- struct stats *stats = stats_bucket(ctx, size);
-
atomic_fetch_add_release(&ctx->inuse, size);
-
- atomic_fetch_add_relaxed(&stats->gets, 1);
}
/*!
*/
static void
mem_putstats(isc_mem_t *ctx, void *ptr, size_t size) {
- struct stats *stats = stats_bucket(ctx, size);
- atomic_size_t s, g;
+ atomic_size_t s;
UNUSED(ptr);
s = atomic_fetch_sub_release(&ctx->inuse, size);
INSIST(s >= size);
-
- g = atomic_fetch_sub_release(&stats->gets, 1);
- INSIST(g >= 1);
}
/*
atomic_init(&ctx->hi_called, false);
atomic_init(&ctx->is_overmem, false);
- for (size_t i = 0; i < STATS_BUCKETS + 1; i++) {
- atomic_init(&ctx->stats[i].gets, 0);
- }
ISC_LIST_INIT(ctx->pools);
#if ISC_MEM_TRACKLINES
static void
destroy(isc_mem_t *ctx) {
- unsigned int i;
-
LOCK(&contextslock);
ISC_LIST_UNLINK(contexts, ctx, link);
totallost += isc_mem_inuse(ctx);
#if ISC_MEM_TRACKLINES
if (ctx->debuglist != NULL) {
debuglink_t *dl;
- for (i = 0; i < DEBUG_TABLE_COUNT; i++) {
+ for (size_t i = 0; i < DEBUG_TABLE_COUNT; i++) {
for (dl = ISC_LIST_HEAD(ctx->debuglist[i]); dl != NULL;
dl = ISC_LIST_HEAD(ctx->debuglist[i]))
{
}
#endif /* if ISC_MEM_TRACKLINES */
- if (ctx->checkfree) {
- for (i = 0; i <= STATS_BUCKETS; i++) {
- struct stats *stats = &ctx->stats[i];
- size_t gets = atomic_load_acquire(&stats->gets);
- if (gets != 0U) {
- fprintf(stderr,
- "Failing assertion due to probable "
- "leaked memory in context %p (\"%s\") "
- "(stats[%u].gets == %zu).\n",
- ctx, ctx->name, i, gets);
-#if ISC_MEM_TRACKLINES
- print_active(ctx, stderr);
-#endif /* if ISC_MEM_TRACKLINES */
- INSIST(gets == 0U);
- }
- }
- }
-
isc_mutex_destroy(&ctx->lock);
if (ctx->checkfree) {
MCTXLOCK(ctx);
- for (size_t i = 0; i <= STATS_BUCKETS; i++) {
- size_t gets;
- struct stats *stats = &ctx->stats[i];
-
- gets = atomic_load_acquire(&stats->gets);
-
- if (gets != 0U) {
- fprintf(out, "%s%5zu: %11zu rem",
- (i == STATS_BUCKETS) ? ">=" : " ", i, gets);
- fputc('\n', out);
- }
- }
-
/*
* Note that since a pool can be locked now, these stats might
* be somewhat off if the pool is in active use at the time the