mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 18:19:42 +00:00
Give every memory pool a name
Instead of giving the memory pools names with an explicit call to isc_mempool_setname(), add the name to isc_mempool_create() call to have all the memory pools an unconditional name.
This commit is contained in:
parent
4e79e9baae
commit
7f498cc60d
@ -5070,15 +5070,15 @@ dns_message_createpools(isc_mem_t *mctx, isc_mempool_t **namepoolp,
|
||||
REQUIRE(namepoolp != NULL && *namepoolp == NULL);
|
||||
REQUIRE(rdspoolp != NULL && *rdspoolp == NULL);
|
||||
|
||||
isc_mempool_create(mctx, sizeof(dns_fixedname_t), namepoolp);
|
||||
isc_mempool_create(mctx, sizeof(dns_fixedname_t), "dns_fixedname_pool",
|
||||
namepoolp);
|
||||
isc_mempool_setfillcount(*namepoolp, NAME_FILLCOUNT);
|
||||
isc_mempool_setfreemax(*namepoolp, NAME_FREEMAX);
|
||||
isc_mempool_setname(*namepoolp, "dns_fixedname_pool");
|
||||
|
||||
isc_mempool_create(mctx, sizeof(dns_rdataset_t), rdspoolp);
|
||||
isc_mempool_create(mctx, sizeof(dns_rdataset_t), "dns_rdataset_pool",
|
||||
rdspoolp);
|
||||
isc_mempool_setfillcount(*rdspoolp, RDATASET_FILLCOUNT);
|
||||
isc_mempool_setfreemax(*rdspoolp, RDATASET_FREEMAX);
|
||||
isc_mempool_setname(*rdspoolp, "dns_rdataset_pool");
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -360,11 +360,11 @@ isc_mem_renderjson(void *memobj0);
|
||||
* Memory pools
|
||||
*/
|
||||
|
||||
#define isc_mempool_create(c, s, mp) \
|
||||
isc__mempool_create((c), (s), (mp)_ISC_MEM_FILELINE)
|
||||
#define isc_mempool_create(c, s, n, mp) \
|
||||
isc__mempool_create((c), (s), (n), (mp)_ISC_MEM_FILELINE)
|
||||
void
|
||||
isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size,
|
||||
isc_mempool_t **mpctxp _ISC_MEM_FLARG);
|
||||
const char *name, isc_mempool_t **mpctxp _ISC_MEM_FLARG);
|
||||
/*%<
|
||||
* Create a memory pool.
|
||||
*
|
||||
@ -389,17 +389,6 @@ isc__mempool_destroy(isc_mempool_t **restrict mpctxp _ISC_MEM_FLARG);
|
||||
*\li The pool has no un"put" allocations outstanding
|
||||
*/
|
||||
|
||||
void
|
||||
isc_mempool_setname(isc_mempool_t *restrict mpctx, const char *name);
|
||||
/*%<
|
||||
* Associate a name with a memory pool. At most 15 characters may be
|
||||
*used.
|
||||
*
|
||||
* Requires:
|
||||
*\li mpctx is a valid pool.
|
||||
*\li name != NULL;
|
||||
*/
|
||||
|
||||
/*
|
||||
* The following functions get/set various parameters. Note that due to
|
||||
* the unlocked nature of pools these are potentially random values
|
||||
|
@ -157,7 +157,7 @@ struct isc_mempool {
|
||||
/*%< Stats only. */
|
||||
size_t gets; /*%< # of requests to this pool */
|
||||
/*%< Debugging only. */
|
||||
char name[16]; /*%< printed name in stats reports */
|
||||
char *name; /*%< printed name in stats reports */
|
||||
};
|
||||
|
||||
/*
|
||||
@ -921,13 +921,14 @@ isc_mem_getname(isc_mem_t *ctx) {
|
||||
|
||||
void
|
||||
isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size,
|
||||
isc_mempool_t **restrict mpctxp FLARG) {
|
||||
const char *name, isc_mempool_t **restrict mpctxp FLARG) {
|
||||
isc_mempool_t *restrict mpctx = NULL;
|
||||
size_t size = element_size;
|
||||
|
||||
REQUIRE(VALID_CONTEXT(mctx));
|
||||
REQUIRE(size > 0U);
|
||||
REQUIRE(mpctxp != NULL && *mpctxp == NULL);
|
||||
REQUIRE(name != NULL);
|
||||
|
||||
/*
|
||||
* Mempools are stored as a linked list of element.
|
||||
@ -946,6 +947,7 @@ isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size,
|
||||
.size = size,
|
||||
.freemax = 1,
|
||||
.fillcount = 1,
|
||||
.name = strdup(name),
|
||||
};
|
||||
|
||||
#if ISC_MEM_TRACKLINES
|
||||
@ -967,14 +969,6 @@ isc__mempool_create(isc_mem_t *restrict mctx, const size_t element_size,
|
||||
MCTXUNLOCK(mctx);
|
||||
}
|
||||
|
||||
void
|
||||
isc_mempool_setname(isc_mempool_t *restrict mpctx, const char *name) {
|
||||
REQUIRE(VALID_MEMPOOL(mpctx));
|
||||
REQUIRE(name != NULL);
|
||||
|
||||
strlcpy(mpctx->name, name, sizeof(mpctx->name));
|
||||
}
|
||||
|
||||
void
|
||||
isc__mempool_destroy(isc_mempool_t **restrict mpctxp FLARG) {
|
||||
isc_mempool_t *restrict mpctx = NULL;
|
||||
@ -1024,6 +1018,8 @@ isc__mempool_destroy(isc_mempool_t **restrict mpctxp FLARG) {
|
||||
mctx->poolcnt--;
|
||||
MCTXUNLOCK(mctx);
|
||||
|
||||
free(mpctx->name);
|
||||
|
||||
mpctx->magic = 0;
|
||||
|
||||
isc_mem_putanddetach(&mpctx->mctx, mpctx, sizeof(isc_mempool_t));
|
||||
|
@ -223,12 +223,12 @@ isc_netmgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, isc_nm_t **netmgrp) {
|
||||
isc_mem_attach(loop->mctx, &worker->mctx);
|
||||
|
||||
isc_mempool_create(worker->mctx, sizeof(isc_nmsocket_t),
|
||||
&worker->nmsocket_pool);
|
||||
"nmsocket_pool", &worker->nmsocket_pool);
|
||||
isc_mempool_setfreemax(worker->nmsocket_pool,
|
||||
ISC_NM_NMSOCKET_MAX);
|
||||
|
||||
isc_mempool_create(worker->mctx, sizeof(isc__nm_uvreq_t),
|
||||
&worker->uvreq_pool);
|
||||
"uvreq_pool", &worker->uvreq_pool);
|
||||
isc_mempool_setfreemax(worker->uvreq_pool, ISC_NM_UVREQS_MAX);
|
||||
|
||||
isc_loop_attach(loop, &worker->loop);
|
||||
|
@ -56,8 +56,8 @@ ISC_RUN_TEST_IMPL(isc_mem_get) {
|
||||
unsigned int i, j;
|
||||
int rval;
|
||||
|
||||
isc_mempool_create(mctx, 24, &mp1);
|
||||
isc_mempool_create(mctx, 31, &mp2);
|
||||
isc_mempool_create(mctx, 24, "mp1", &mp1);
|
||||
isc_mempool_create(mctx, 31, "mp2", &mp2);
|
||||
|
||||
isc_mempool_setfreemax(mp1, MP1_FREEMAX);
|
||||
isc_mempool_setfillcount(mp1, MP1_FILLCNT);
|
||||
@ -114,7 +114,7 @@ ISC_RUN_TEST_IMPL(isc_mem_get) {
|
||||
isc_mempool_destroy(&mp1);
|
||||
isc_mempool_destroy(&mp2);
|
||||
|
||||
isc_mempool_create(mctx, 2, &mp1);
|
||||
isc_mempool_create(mctx, 2, "mp1", &mp1);
|
||||
|
||||
tmp = isc_mempool_get(mp1);
|
||||
assert_non_null(tmp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user