mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 23:25:38 +00:00
Replace locked mempools with memory contexts
Current mempools are kind of hybrid structures - they serve two purposes: 1. mempool with a lock is basically static sized allocator with pre-allocated free items 2. mempool without a lock is a doubly-linked list of preallocated items The first kind of usage could be easily replaced with jemalloc small sized arena objects and thread-local caches. The second usage not-so-much and we need to keep this (in libdns:message.c) for performance reasons.
This commit is contained in:
@@ -77,12 +77,6 @@ typedef struct filter_instance {
|
||||
ns_plugin_t *module;
|
||||
isc_mem_t *mctx;
|
||||
|
||||
/*
|
||||
* Memory pool for use with persistent data.
|
||||
*/
|
||||
isc_mempool_t *datapool;
|
||||
isc_mutex_t plock;
|
||||
|
||||
/*
|
||||
* Hash table associating a client object with its persistent data.
|
||||
*/
|
||||
@@ -353,25 +347,9 @@ plugin_register(const char *parameters, const void *cfg, const char *cfg_file,
|
||||
cfg_line, mctx, lctx, actx));
|
||||
}
|
||||
|
||||
isc_mempool_create(mctx, sizeof(filter_data_t), &inst->datapool);
|
||||
CHECK(isc_ht_init(&inst->ht, mctx, 16));
|
||||
isc_mutex_init(&inst->hlock);
|
||||
|
||||
/*
|
||||
* Fill the mempool with 1K filter_a state objects at
|
||||
* a time; ideally after a single allocation, the mempool will
|
||||
* have enough to handle all the simultaneous queries the system
|
||||
* requires and it won't be necessary to allocate more.
|
||||
*
|
||||
* We don't set any limit on the number of free state objects
|
||||
* so that they'll always be returned to the pool and not
|
||||
* freed until the pool is destroyed on shutdown.
|
||||
*/
|
||||
isc_mempool_setfillcount(inst->datapool, 1024);
|
||||
isc_mempool_setfreemax(inst->datapool, UINT_MAX);
|
||||
isc_mutex_init(&inst->plock);
|
||||
isc_mempool_associatelock(inst->datapool, &inst->plock);
|
||||
|
||||
/*
|
||||
* Set hook points in the view's hooktable.
|
||||
*/
|
||||
@@ -427,10 +405,6 @@ plugin_destroy(void **instp) {
|
||||
isc_ht_destroy(&inst->ht);
|
||||
isc_mutex_destroy(&inst->hlock);
|
||||
}
|
||||
if (inst->datapool != NULL) {
|
||||
isc_mempool_destroy(&inst->datapool);
|
||||
isc_mutex_destroy(&inst->plock);
|
||||
}
|
||||
if (inst->a_acl != NULL) {
|
||||
dns_acl_detach(&inst->a_acl);
|
||||
}
|
||||
@@ -512,10 +486,7 @@ client_state_create(const query_ctx_t *qctx, filter_instance_t *inst) {
|
||||
filter_data_t *client_state;
|
||||
isc_result_t result;
|
||||
|
||||
client_state = isc_mempool_get(inst->datapool);
|
||||
if (client_state == NULL) {
|
||||
return;
|
||||
}
|
||||
client_state = isc_mem_get(inst->mctx, sizeof(*client_state));
|
||||
|
||||
client_state->mode = NONE;
|
||||
client_state->flags = 0;
|
||||
@@ -542,7 +513,7 @@ client_state_destroy(const query_ctx_t *qctx, filter_instance_t *inst) {
|
||||
UNLOCK(&inst->hlock);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
|
||||
isc_mempool_put(inst->datapool, client_state);
|
||||
isc_mem_put(inst->mctx, client_state, sizeof(*client_state));
|
||||
}
|
||||
|
||||
/*%
|
||||
|
Reference in New Issue
Block a user