2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Make the mempool names unconditional

The named memory pools were default and always compiled-in.  Remove the
extra complexity by removing the #define and #ifdefs around the code.
This commit is contained in:
Ondřej Surý
2021-02-04 23:10:39 +01:00
committed by Ondřej Surý
parent b09106e93a
commit c9fe12443f
2 changed files with 8 additions and 42 deletions

View File

@@ -36,15 +36,6 @@ typedef void (*isc_mem_water_t)(void *, int);
#define ISC_MEM_TRACKLINES 1 #define ISC_MEM_TRACKLINES 1
#endif /* ifndef ISC_MEM_TRACKLINES */ #endif /* ifndef ISC_MEM_TRACKLINES */
/*%
* Define ISC_MEMPOOL_NAMES=1 to make memory pools store a symbolic
* name so that the leaking pool can be more readily identified in
* case of a memory leak.
*/
#ifndef ISC_MEMPOOL_NAMES
#define ISC_MEMPOOL_NAMES 1
#endif /* ifndef ISC_MEMPOOL_NAMES */
LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_debugging; LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_debugging;
LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags; LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags;

View File

@@ -177,9 +177,7 @@ struct isc_mempool {
/*%< Stats only. */ /*%< Stats only. */
atomic_size_t gets; /*%< # of requests to this pool */ atomic_size_t gets; /*%< # of requests to this pool */
/*%< Debugging only. */ /*%< Debugging only. */
#if ISC_MEMPOOL_NAMES char name[16]; /*%< printed name in stats reports */
char name[16]; /*%< printed name in stats reports */
#endif /* if ISC_MEMPOOL_NAMES */
}; };
/* /*
@@ -226,7 +224,6 @@ increment_malloced(isc_mem_t *ctx, size_t size) {
static inline size_t static inline size_t
decrement_malloced(isc_mem_t *ctx, size_t size) { decrement_malloced(isc_mem_t *ctx, size_t size) {
size_t malloced = atomic_fetch_sub_release(&ctx->malloced, size) - size; size_t malloced = atomic_fetch_sub_release(&ctx->malloced, size) - size;
INSIST(size >= 0);
return (malloced); return (malloced);
} }
@@ -885,12 +882,8 @@ isc_mem_stats(isc_mem_t *ctx, FILE *out) {
while (pool != NULL) { while (pool != NULL) {
fprintf(out, fprintf(out,
"%15s %10zu %10zu %10zu %10zu %10zu %10zu %10zu %s\n", "%15s %10zu %10zu %10zu %10zu %10zu %10zu %10zu %s\n",
#if ISC_MEMPOOL_NAMES pool->name, pool->size,
pool->name, atomic_load_relaxed(&pool->maxalloc),
#else /* if ISC_MEMPOOL_NAMES */
"(not tracked)",
#endif /* if ISC_MEMPOOL_NAMES */
pool->size, atomic_load_relaxed(&pool->maxalloc),
atomic_load_relaxed(&pool->allocated), atomic_load_relaxed(&pool->allocated),
atomic_load_relaxed(&pool->freecount), atomic_load_relaxed(&pool->freecount),
atomic_load_relaxed(&pool->freemax), atomic_load_relaxed(&pool->freemax),
@@ -1129,7 +1122,7 @@ isc_mem_setwater(isc_mem_t *ctx, isc_mem_water_t water, void *water_arg,
oldwater = ctx->water; oldwater = ctx->water;
oldwater_arg = ctx->water_arg; oldwater_arg = ctx->water_arg;
if (water == NULL) { if (water == NULL) {
callwater = atomic_load(&ctx->hi_called); callwater = atomic_load_acquire(&ctx->hi_called);
ctx->water = NULL; ctx->water = NULL;
ctx->water_arg = NULL; ctx->water_arg = NULL;
atomic_store_release(&ctx->hi_water, 0); atomic_store_release(&ctx->hi_water, 0);
@@ -1231,17 +1224,11 @@ isc_mempool_setname(isc_mempool_t *mpctx, const char *name) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
REQUIRE(name != NULL); REQUIRE(name != NULL);
#if ISC_MEMPOOL_NAMES
MPCTXLOCK(mpctx); MPCTXLOCK(mpctx);
strlcpy(mpctx->name, name, sizeof(mpctx->name)); strlcpy(mpctx->name, name, sizeof(mpctx->name));
MPCTXUNLOCK(mpctx); MPCTXUNLOCK(mpctx);
#else /* if ISC_MEMPOOL_NAMES */
UNUSED(mpctx);
UNUSED(name);
#endif /* if ISC_MEMPOOL_NAMES */
} }
void void
@@ -1256,14 +1243,12 @@ isc_mempool_destroy(isc_mempool_t **mpctxp) {
mpctx = *mpctxp; mpctx = *mpctxp;
*mpctxp = NULL; *mpctxp = NULL;
#if ISC_MEMPOOL_NAMES
if (atomic_load_acquire(&mpctx->allocated) > 0) { if (atomic_load_acquire(&mpctx->allocated) > 0) {
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_mempool_destroy(): mempool %s " "isc_mempool_destroy(): mempool %s "
"leaked memory", "leaked memory",
mpctx->name); mpctx->name);
} }
#endif /* if ISC_MEMPOOL_NAMES */
REQUIRE(atomic_load_acquire(&mpctx->allocated) == 0); REQUIRE(atomic_load_acquire(&mpctx->allocated) == 0);
mctx = mpctx->mctx; mctx = mpctx->mctx;
@@ -1415,26 +1400,14 @@ void
isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit) { isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
MPCTXLOCK(mpctx); atomic_store_release(&mpctx->freemax, limit);
mpctx->freemax = limit;
MPCTXUNLOCK(mpctx);
} }
unsigned int unsigned int
isc_mempool_getfreemax(isc_mempool_t *mpctx) { isc_mempool_getfreemax(isc_mempool_t *mpctx) {
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
unsigned int freemax; return (atomic_load_acquire(&mpctx->freemax));
MPCTXLOCK(mpctx);
freemax = mpctx->freemax;
MPCTXUNLOCK(mpctx);
return (freemax);
} }
unsigned int unsigned int
@@ -1484,6 +1457,7 @@ isc_mempool_getfillcount(isc_mempool_t *mpctx) {
/* /*
* Requires contextslock to be held by caller. * Requires contextslock to be held by caller.
*/ */
#if ISC_MEM_TRACKLINES
static void static void
print_contexts(FILE *file) { print_contexts(FILE *file) {
isc_mem_t *ctx; isc_mem_t *ctx;
@@ -1497,6 +1471,7 @@ print_contexts(FILE *file) {
} }
fflush(file); fflush(file);
} }
#endif
void void
isc_mem_checkdestroyed(FILE *file) { isc_mem_checkdestroyed(FILE *file) {