atomic_size_t total;
atomic_size_t inuse;
atomic_size_t maxinuse;
- atomic_size_t malloced;
- atomic_size_t maxmalloced;
atomic_bool hi_called;
atomic_bool is_overmem;
isc_mem_water_t water;
print_active(isc_mem_t *ctx, FILE *out);
#endif /* ISC_MEM_TRACKLINES */
-static void
-increment_malloced(isc_mem_t *ctx, size_t size) {
- size_t malloced = atomic_fetch_add_relaxed(&ctx->malloced, size) + size;
- size_t maxmalloced = atomic_load_relaxed(&ctx->maxmalloced);
-
- if (malloced > maxmalloced) {
- atomic_compare_exchange_strong(&ctx->maxmalloced, &maxmalloced,
- malloced);
- }
-}
-
-static void
-decrement_malloced(isc_mem_t *ctx, size_t size) {
- (void)atomic_fetch_sub_relaxed(&ctx->malloced, size);
-}
-
#if ISC_MEM_TRACKLINES
/*!
* mctx must not be locked.
dl = mallocx(sizeof(debuglink_t), 0);
INSIST(dl != NULL);
- increment_malloced(mctx, sizeof(debuglink_t));
ISC_LINK_INIT(dl, link);
dl->ptr = ptr;
while (dl != NULL) {
if (dl->ptr == ptr) {
ISC_LIST_UNLINK(mctx->debuglist[idx], dl, link);
- decrement_malloced(mctx, sizeof(*dl));
sdallocx(dl, sizeof(*dl), 0);
goto unlock;
}
atomic_fetch_add_relaxed(&stats->gets, 1);
atomic_fetch_add_relaxed(&stats->totalgets, 1);
-
- increment_malloced(ctx, size);
}
/*!
g = atomic_fetch_sub_release(&stats->gets, 1);
INSIST(g >= 1);
-
- decrement_malloced(ctx, size);
}
/*
atomic_init(&ctx->total, 0);
atomic_init(&ctx->inuse, 0);
atomic_init(&ctx->maxinuse, 0);
- atomic_init(&ctx->malloced, sizeof(*ctx));
- atomic_init(&ctx->maxmalloced, sizeof(*ctx));
atomic_init(&ctx->hi_water, 0);
atomic_init(&ctx->lo_water, 0);
atomic_init(&ctx->hi_called, false);
for (i = 0; i < DEBUG_TABLE_COUNT; i++) {
ISC_LIST_INIT(ctx->debuglist[i]);
}
- increment_malloced(ctx,
- DEBUG_TABLE_COUNT * sizeof(debuglist_t));
}
#endif /* if ISC_MEM_TRACKLINES */
ISC_LIST_UNLINK(ctx->debuglist[i], dl, link);
sdallocx(dl, sizeof(*dl), 0);
- decrement_malloced(ctx, sizeof(*dl));
}
}
sdallocx(ctx->debuglist,
(DEBUG_TABLE_COUNT * sizeof(debuglist_t)), 0);
- decrement_malloced(ctx,
- DEBUG_TABLE_COUNT * sizeof(debuglist_t));
}
#endif /* if ISC_MEM_TRACKLINES */
isc_mutex_destroy(&ctx->lock);
if (ctx->checkfree) {
- INSIST(atomic_load(&ctx->malloced) == 0);
+ INSIST(atomic_load(&ctx->inuse) == 0);
}
sdallocx(ctx, sizeof(*ctx), ISC_MEM_ALIGN(isc_os_cacheline()));
}
return (atomic_load_acquire(&ctx->total));
}
-size_t
-isc_mem_malloced(isc_mem_t *ctx) {
- REQUIRE(VALID_CONTEXT(ctx));
-
- return (atomic_load_acquire(&ctx->malloced));
-}
-
-size_t
-isc_mem_maxmalloced(isc_mem_t *ctx) {
- REQUIRE(VALID_CONTEXT(ctx));
-
- return (atomic_load_acquire(&ctx->maxmalloced));
-}
-
void
isc_mem_clearwater(isc_mem_t *mctx) {
isc_mem_setwater(mctx, NULL, NULL, 0, 0);
typedef struct summarystat {
uint64_t total;
uint64_t inuse;
- uint64_t malloced;
uint64_t contextsize;
} summarystat_t;
(uint64_t)isc_mem_maxinuse(ctx)));
TRY0(xmlTextWriterEndElement(writer)); /* maxinuse */
- summary->malloced += isc_mem_malloced(ctx);
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "malloced"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%" PRIu64 "",
- (uint64_t)isc_mem_malloced(ctx)));
- TRY0(xmlTextWriterEndElement(writer)); /* malloced */
-
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "maxmalloced"));
- TRY0(xmlTextWriterWriteFormatString(
- writer, "%" PRIu64 "", (uint64_t)isc_mem_maxmalloced(ctx)));
- TRY0(xmlTextWriterEndElement(writer)); /* maxmalloced */
-
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "pools"));
TRY0(xmlTextWriterWriteFormatString(writer, "%u", ctx->poolcnt));
TRY0(xmlTextWriterEndElement(writer)); /* pools */
summary.inuse));
TRY0(xmlTextWriterEndElement(writer)); /* InUse */
- TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "Malloced"));
- TRY0(xmlTextWriterWriteFormatString(writer, "%" PRIu64 "",
- summary.malloced));
- TRY0(xmlTextWriterEndElement(writer)); /* InUse */
-
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "ContextSize"));
TRY0(xmlTextWriterWriteFormatString(writer, "%" PRIu64 "",
summary.contextsize));
summary->contextsize += sizeof(*ctx);
summary->total += isc_mem_total(ctx);
summary->inuse += isc_mem_inuse(ctx);
- summary->malloced += isc_mem_malloced(ctx);
#if ISC_MEM_TRACKLINES
if (ctx->debuglist != NULL) {
summary->contextsize += DEBUG_TABLE_COUNT *
CHECKMEM(obj);
json_object_object_add(ctxobj, "maxinuse", obj);
- obj = json_object_new_int64(isc_mem_malloced(ctx));
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "malloced", obj);
-
- obj = json_object_new_int64(isc_mem_maxmalloced(ctx));
- CHECKMEM(obj);
- json_object_object_add(ctxobj, "maxmalloced", obj);
-
obj = json_object_new_int64(ctx->poolcnt);
CHECKMEM(obj);
json_object_object_add(ctxobj, "pools", obj);
CHECKMEM(obj);
json_object_object_add(memobj, "InUse", obj);
- obj = json_object_new_int64(summary.malloced);
- CHECKMEM(obj);
- json_object_object_add(memobj, "Malloced", obj);
-
obj = json_object_new_int64(summary.contextsize);
CHECKMEM(obj);
json_object_object_add(memobj, "ContextSize", obj);