isc_buffer_t *namebuf = NULL;
dns_tsigkey_t *tsigkey = NULL;
bool validated = true;
-isc_mempool_t *commctx = NULL;
bool debugging = false;
bool debugtiming = false;
bool memdebugging = false;
check_result(result, "dst_lib_init");
is_dst_up = true;
- isc_mempool_create(mctx, COMMSIZE, &commctx);
- isc_mempool_setname(commctx, "COMMPOOL");
- /*
- * 6 and 2 set as reasonable parameters for 3 or 4 nameserver
- * systems.
- */
- isc_mempool_setfreemax(commctx, 6);
- isc_mempool_setfillcount(commctx, 2);
-
isc_mutex_init(&lookup_lock);
}
sockcount--;
debug("sockcount=%d", sockcount);
}
- isc_mempool_put(commctx, query->recvspace);
- isc_mempool_put(commctx, query->tmpsendspace);
+ isc_mem_put(mctx, query->recvspace, COMMSIZE);
+ isc_mem_put(mctx, query->tmpsendspace, COMMSIZE);
isc_buffer_invalidate(&query->recvbuf);
isc_buffer_invalidate(&query->lengthbuf);
isc_buffer_free(&lookup->querysig);
}
if (lookup->sendspace != NULL) {
- isc_mempool_put(commctx, lookup->sendspace);
+ isc_mem_put(mctx, lookup->sendspace, COMMSIZE);
}
if (lookup->tsigctx != NULL) {
check_result(result, "dns_message_settsigkey");
}
- lookup->sendspace = isc_mempool_get(commctx);
- if (lookup->sendspace == NULL) {
- fatal("memory allocation failure");
- }
+ lookup->sendspace = isc_mem_get(mctx, COMMSIZE);
result = dns_compress_init(&cctx, -1, mctx);
check_result(result, "dns_compress_init");
query->byte_count = 0;
query->ixfr_axfr = false;
query->sock = NULL;
- query->recvspace = isc_mempool_get(commctx);
- query->tmpsendspace = isc_mempool_get(commctx);
+ query->recvspace = isc_mem_get(mctx, COMMSIZE);
+ query->tmpsendspace = isc_mem_get(mctx, COMMSIZE);
if (query->recvspace == NULL) {
fatal("memory allocation failure");
}
check_result(result, "dns_name_settotextfilter");
#endif /* HAVE_LIBIDN2 */
- if (commctx != NULL) {
- debug("freeing commctx");
- isc_mempool_destroy(&commctx);
- }
if (socketmgr != NULL) {
debug("freeing socketmgr");
isc_socketmgr_destroy(&socketmgr);
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.
*/
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_aaaa 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.
*/
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->aaaa_acl != NULL) {
dns_acl_detach(&inst->aaaa_acl);
}
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;
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));
}
/*%
unsigned int irefcnt;
unsigned int erefcnt;
- isc_mutex_t mplock;
- isc_mempool_t *nmp; /*%< dns_adbname_t */
- isc_mempool_t *nhmp; /*%< dns_adbnamehook_t */
- isc_mempool_t *limp; /*%< dns_adblameinfo_t */
- isc_mempool_t *emp; /*%< dns_adbentry_t */
- isc_mempool_t *ahmp; /*%< dns_adbfind_t */
- isc_mempool_t *aimp; /*%< dns_adbaddrinfo_t */
- isc_mempool_t *afmp; /*%< dns_adbfetch_t */
+ isc_refcount_t ahrefcnt;
+ isc_refcount_t nhrefcnt;
/*!
* Bucketized locks and lists for names.
newentrylocks = isc_mem_get(adb->mctx, sizeof(*newentrylocks) * n);
newentry_sd = isc_mem_get(adb->mctx, sizeof(*newentry_sd) * n);
newentry_refcnt = isc_mem_get(adb->mctx, sizeof(*newentry_refcnt) * n);
- if (newentries == NULL || newdeadentries == NULL ||
- newentrylocks == NULL || newentry_sd == NULL ||
- newentry_refcnt == NULL)
- {
- goto cleanup;
- }
/*
* Initialise the new resources.
newnamelocks = isc_mem_get(adb->mctx, sizeof(*newnamelocks) * n);
newname_sd = isc_mem_get(adb->mctx, sizeof(*newname_sd) * n);
newname_refcnt = isc_mem_get(adb->mctx, sizeof(*newname_refcnt) * n);
- if (newnames == NULL || newdeadnames == NULL || newnamelocks == NULL ||
- newname_sd == NULL || newname_refcnt == NULL)
- {
- goto cleanup;
- }
/*
* Initialise the new resources.
new_adbname(dns_adb_t *adb, const dns_name_t *dnsname) {
dns_adbname_t *name;
- name = isc_mempool_get(adb->nmp);
- if (name == NULL) {
- return (NULL);
- }
+ name = isc_mem_get(adb->mctx, sizeof(*name));
dns_name_init(&name->name, NULL);
dns_name_dup(dnsname, adb->mctx, &name->name);
n->magic = 0;
dns_name_free(&n->name, adb->mctx);
- isc_mempool_put(adb->nmp, n);
+ isc_mem_put(adb->mctx, n, sizeof(*n));
LOCK(&adb->namescntlock);
adb->namescnt--;
dec_adbstats(adb, dns_adbstats_namescnt);
new_adbnamehook(dns_adb_t *adb, dns_adbentry_t *entry) {
dns_adbnamehook_t *nh;
- nh = isc_mempool_get(adb->nhmp);
- if (nh == NULL) {
- return (NULL);
- }
+ nh = isc_mem_get(adb->mctx, sizeof(*nh));
+ isc_refcount_increment0(&adb->nhrefcnt);
nh->magic = DNS_ADBNAMEHOOK_MAGIC;
nh->entry = entry;
INSIST(!ISC_LINK_LINKED(nh, plink));
nh->magic = 0;
- isc_mempool_put(adb->nhmp, nh);
+
+ isc_refcount_decrement(&adb->nhrefcnt);
+ isc_mem_put(adb->mctx, nh, sizeof(*nh));
}
static inline dns_adblameinfo_t *
dns_rdatatype_t qtype) {
dns_adblameinfo_t *li;
- li = isc_mempool_get(adb->limp);
- if (li == NULL) {
- return (NULL);
- }
+ li = isc_mem_get(adb->mctx, sizeof(*li));
dns_name_init(&li->qname, NULL);
dns_name_dup(qname, adb->mctx, &li->qname);
li->magic = 0;
- isc_mempool_put(adb->limp, li);
+ isc_mem_put(adb->mctx, li, sizeof(*li));
}
static inline dns_adbentry_t *
new_adbentry(dns_adb_t *adb) {
dns_adbentry_t *e;
- e = isc_mempool_get(adb->emp);
- if (e == NULL) {
- return (NULL);
- }
+ e = isc_mem_get(adb->mctx, sizeof(*e));
e->magic = DNS_ADBENTRY_MAGIC;
e->lock_bucket = DNS_ADB_INVALIDBUCKET;
li = ISC_LIST_HEAD(e->lameinfo);
}
- isc_mempool_put(adb->emp, e);
+ isc_mem_put(adb->mctx, e, sizeof(*e));
LOCK(&adb->entriescntlock);
adb->entriescnt--;
dec_adbstats(adb, dns_adbstats_entriescnt);
new_adbfind(dns_adb_t *adb) {
dns_adbfind_t *h;
- h = isc_mempool_get(adb->ahmp);
- if (h == NULL) {
- return (NULL);
- }
+ h = isc_mem_get(adb->mctx, sizeof(*h));
+ isc_refcount_increment0(&adb->ahrefcnt);
/*
* Public members.
new_adbfetch(dns_adb_t *adb) {
dns_adbfetch_t *f;
- f = isc_mempool_get(adb->afmp);
- if (f == NULL) {
- return (NULL);
- }
+ f = isc_mem_get(adb->mctx, sizeof(*f));
f->magic = 0;
f->fetch = NULL;
dns_rdataset_disassociate(&f->rdataset);
}
- isc_mempool_put(adb->afmp, f);
+ isc_mem_put(adb->mctx, f, sizeof(*f));
}
static inline bool
find->magic = 0;
isc_mutex_destroy(&find->lock);
- isc_mempool_put(adb->ahmp, find);
+
+ isc_refcount_decrement(&adb->ahrefcnt);
+ isc_mem_put(adb->mctx, find, sizeof(*find));
return (dec_adb_irefcnt(adb));
}
new_adbaddrinfo(dns_adb_t *adb, dns_adbentry_t *entry, in_port_t port) {
dns_adbaddrinfo_t *ai;
- ai = isc_mempool_get(adb->aimp);
- if (ai == NULL) {
- return (NULL);
- }
+ ai = isc_mem_get(adb->mctx, sizeof(*ai));
ai->magic = DNS_ADBADDRINFO_MAGIC;
ai->sockaddr = entry->sockaddr;
ai->magic = 0;
- isc_mempool_put(adb->aimp, ai);
+ isc_mem_put(adb->mctx, ai, sizeof(*ai));
}
/*
isc_task_detach(&adb->excl);
}
- isc_mempool_destroy(&adb->nmp);
- isc_mempool_destroy(&adb->nhmp);
- isc_mempool_destroy(&adb->limp);
- isc_mempool_destroy(&adb->emp);
- isc_mempool_destroy(&adb->ahmp);
- isc_mempool_destroy(&adb->aimp);
- isc_mempool_destroy(&adb->afmp);
-
isc_mutexblock_destroy(adb->entrylocks, adb->nentries);
isc_mem_put(adb->mctx, adb->entries,
sizeof(*adb->entries) * adb->nentries);
isc_mutex_destroy(&adb->reflock);
isc_mutex_destroy(&adb->lock);
- isc_mutex_destroy(&adb->mplock);
isc_mutex_destroy(&adb->overmemlock);
isc_mutex_destroy(&adb->entriescntlock);
isc_mutex_destroy(&adb->namescntlock);
adb->magic = 0;
adb->erefcnt = 1;
adb->irefcnt = 0;
- adb->nmp = NULL;
- adb->nhmp = NULL;
- adb->limp = NULL;
- adb->emp = NULL;
- adb->ahmp = NULL;
- adb->aimp = NULL;
- adb->afmp = NULL;
adb->task = NULL;
adb->excl = NULL;
adb->mctx = NULL;
isc_mem_attach(mem, &adb->mctx);
isc_mutex_init(&adb->lock);
- isc_mutex_init(&adb->mplock);
isc_mutex_init(&adb->reflock);
isc_mutex_init(&adb->overmemlock);
isc_mutex_init(&adb->entriescntlock);
do { \
(adb)->el = isc_mem_get((adb)->mctx, \
sizeof(*(adb)->el) * (adb)->nentries); \
- if ((adb)->el == NULL) { \
- result = ISC_R_NOMEMORY; \
- goto fail1; \
- } \
} while (0)
ALLOCENTRY(adb, entries);
ALLOCENTRY(adb, deadentries);
do { \
(adb)->el = isc_mem_get((adb)->mctx, \
sizeof(*(adb)->el) * (adb)->nnames); \
- if ((adb)->el == NULL) { \
- result = ISC_R_NOMEMORY; \
- goto fail1; \
- } \
} while (0)
ALLOCNAME(adb, names);
ALLOCNAME(adb, deadnames);
}
isc_mutexblock_init(adb->entrylocks, adb->nentries);
- /*
- * Memory pools
- */
-#define MPINIT(t, p, n) \
- do { \
- isc_mempool_create(mem, sizeof(t), &(p)); \
- isc_mempool_setfreemax((p), FREE_ITEMS); \
- isc_mempool_setfillcount((p), FILL_COUNT); \
- isc_mempool_setname((p), n); \
- isc_mempool_associatelock((p), &adb->mplock); \
- } while (0)
-
- MPINIT(dns_adbname_t, adb->nmp, "adbname");
- MPINIT(dns_adbnamehook_t, adb->nhmp, "adbnamehook");
- MPINIT(dns_adblameinfo_t, adb->limp, "adblameinfo");
- MPINIT(dns_adbentry_t, adb->emp, "adbentry");
- MPINIT(dns_adbfind_t, adb->ahmp, "adbfind");
- MPINIT(dns_adbaddrinfo_t, adb->aimp, "adbaddrinfo");
- MPINIT(dns_adbfetch_t, adb->afmp, "adbfetch");
-
-#undef MPINIT
+ isc_refcount_init(&adb->ahrefcnt, 0);
+ isc_refcount_init(&adb->nhrefcnt, 0);
/*
* Allocate an internal task.
isc_mutexblock_destroy(adb->entrylocks, adb->nentries);
isc_mutexblock_destroy(adb->namelocks, adb->nnames);
-fail1: /* clean up only allocated memory */
if (adb->entries != NULL) {
isc_mem_put(adb->mctx, adb->entries,
sizeof(*adb->entries) * adb->nentries);
isc_mem_put(adb->mctx, adb->name_refcnt,
sizeof(*adb->name_refcnt) * adb->nnames);
}
- if (adb->nmp != NULL) {
- isc_mempool_destroy(&adb->nmp);
- }
- if (adb->nhmp != NULL) {
- isc_mempool_destroy(&adb->nhmp);
- }
- if (adb->limp != NULL) {
- isc_mempool_destroy(&adb->limp);
- }
- if (adb->emp != NULL) {
- isc_mempool_destroy(&adb->emp);
- }
- if (adb->ahmp != NULL) {
- isc_mempool_destroy(&adb->ahmp);
- }
- if (adb->aimp != NULL) {
- isc_mempool_destroy(&adb->aimp);
- }
- if (adb->afmp != NULL) {
- isc_mempool_destroy(&adb->afmp);
- }
isc_mutex_destroy(&adb->namescntlock);
isc_mutex_destroy(&adb->entriescntlock);
isc_mutex_destroy(&adb->overmemlock);
isc_mutex_destroy(&adb->reflock);
- isc_mutex_destroy(&adb->mplock);
isc_mutex_destroy(&adb->lock);
if (adb->excl != NULL) {
isc_task_detach(&adb->excl);
zeroirefcnt = (adb->irefcnt == 0);
if (adb->shutting_down && zeroirefcnt &&
- isc_mempool_getallocated(adb->ahmp) == 0)
+ isc_refcount_current(&adb->ahrefcnt) == 0)
{
/*
* We're already shutdown. Send the event.
fprintf(f, "; [plain success/timeout]\n;\n");
if (debug) {
LOCK(&adb->reflock);
- fprintf(f, "; addr %p, erefcnt %u, irefcnt %u, finds out %u\n",
+ fprintf(f,
+ "; addr %p, erefcnt %u, irefcnt %u, finds out "
+ "%" PRIuFAST32 "\n",
adb, adb->erefcnt, adb->irefcnt,
- isc_mempool_getallocated(adb->nhmp));
+ isc_refcount_current(&adb->nhrefcnt));
UNLOCK(&adb->reflock);
}
unsigned int buffersize; /*%< size of each buffer */
unsigned int maxbuffers; /*%< max buffers */
- /* Locked internally. */
- isc_mutex_t depool_lock;
- isc_mempool_t *depool; /*%< pool for dispatch events */
- isc_mutex_t rpool_lock;
- isc_mempool_t *rpool; /*%< pool for replies */
- isc_mutex_t dpool_lock;
- isc_mempool_t *dpool; /*%< dispatch allocations */
- isc_mutex_t bpool_lock;
- isc_mempool_t *bpool; /*%< pool for buffers */
- isc_mutex_t spool_lock;
- isc_mempool_t *spool; /*%< pool for dispsocks */
+ isc_refcount_t irefs;
/*%
* Locked by qid->lock if qid exists; otherwise, can be used without
unsigned int maxrequests; /*%< max requests */
isc_event_t *ctlevent;
- isc_mutex_t sepool_lock;
- isc_mempool_t *sepool; /*%< pool for socket events */
+ isc_mem_t *sepool; /*%< pool for socket events */
/*% Locked by mgr->lock. */
ISC_LINK(dns_dispatch_t) link;
dns_tcpmsg_t tcpmsg; /*%< for tcp streams */
dns_qid_t *qid;
dispportlist_t *port_table; /*%< hold ports 'owned' by us */
- isc_mempool_t *portpool; /*%< port table entries */
};
#define QID_MAGIC ISC_MAGIC('Q', 'i', 'd', ' ')
disp->socket, disp->task[0]); /* XXXX */
if (disp->sepool != NULL) {
- isc_mempool_destroy(&disp->sepool);
- isc_mutex_destroy(&disp->sepool_lock);
+ isc_mem_destroy(&disp->sepool);
}
if (disp->socket != NULL) {
REQUIRE(disp->port_table != NULL);
- portentry = isc_mempool_get(disp->portpool);
- if (portentry == NULL) {
- return (portentry);
- }
+ portentry = isc_mem_get(disp->mgr->mctx, sizeof(*portentry));
portentry->port = port;
isc_refcount_init(&portentry->refs, 1);
ISC_LIST_UNLINK(disp->port_table[portentry->port %
DNS_DISPATCH_PORTTABLESIZE],
portentry, link);
- isc_mempool_put(disp->portpool, portentry);
+ isc_mem_put(disp->mgr->mctx, portentry, sizeof(*portentry));
}
}
sock = dispsock->socket;
dispsock->socket = NULL;
} else {
- dispsock = isc_mempool_get(mgr->spool);
- if (dispsock == NULL) {
- return (ISC_R_NOMEMORY);
- }
+ dispsock = isc_mem_get(mgr->mctx, sizeof(*dispsock));
disp->nsockets++;
dispsock->socket = NULL;
if (dispsock->task != NULL) {
isc_task_detach(&dispsock->task);
}
- isc_mempool_put(disp->mgr->spool, dispsock);
+ isc_mem_put(disp->mgr->mctx, dispsock, sizeof(*dispsock));
}
/*%
static void
free_buffer(dns_dispatch_t *disp, void *buf, unsigned int len) {
- isc_mempool_t *bpool;
+ unsigned int buffersize;
INSIST(buf != NULL && len != 0);
switch (disp->socktype) {
INSIST(disp->mgr->buffers > 0);
INSIST(len == disp->mgr->buffersize);
disp->mgr->buffers--;
- bpool = disp->mgr->bpool;
+ buffersize = disp->mgr->buffersize;
UNLOCK(&disp->mgr->buffer_lock);
- isc_mempool_put(bpool, buf);
+ isc_mem_put(disp->mgr->mctx, buf, buffersize);
break;
default:
INSIST(0);
static void *
allocate_udp_buffer(dns_dispatch_t *disp) {
- isc_mempool_t *bpool;
- void *temp;
+ unsigned int buffersize;
LOCK(&disp->mgr->buffer_lock);
if (disp->mgr->buffers >= disp->mgr->maxbuffers) {
UNLOCK(&disp->mgr->buffer_lock);
return (NULL);
}
- bpool = disp->mgr->bpool;
+ buffersize = disp->mgr->buffersize;
disp->mgr->buffers++;
UNLOCK(&disp->mgr->buffer_lock);
- temp = isc_mempool_get(bpool);
-
- if (temp == NULL) {
- LOCK(&disp->mgr->buffer_lock);
- disp->mgr->buffers--;
- UNLOCK(&disp->mgr->buffer_lock);
- }
-
- return (temp);
+ return (isc_mem_get(disp->mgr->mctx, buffersize));
}
static inline void
free_sevent(isc_event_t *ev) {
- isc_mempool_t *pool = ev->ev_destroy_arg;
+ isc_mem_t *pool = ev->ev_destroy_arg;
isc_socketevent_t *sev = (isc_socketevent_t *)ev;
- isc_mempool_put(pool, sev);
+ isc_mem_put(pool, sev, sizeof(*sev));
}
static inline isc_socketevent_t *
isc_socketevent_t *ev;
void *deconst_arg;
- ev = isc_mempool_get(disp->sepool);
- if (ev == NULL) {
- return (NULL);
- }
+ ev = isc_mem_get(disp->sepool, sizeof(*ev));
DE_CONST(arg, deconst_arg);
ISC_EVENT_INIT(ev, sizeof(*ev), 0, NULL, type, action, deconst_arg,
sock, free_sevent, disp->sepool);
return;
}
- isc_mempool_put(disp->mgr->depool, ev);
+ isc_refcount_decrement(&disp->mgr->irefs);
+ isc_mem_put(disp->mgr->mctx, ev, sizeof(*ev));
}
static inline dns_dispatchevent_t *
allocate_devent(dns_dispatch_t *disp) {
dns_dispatchevent_t *ev;
- ev = isc_mempool_get(disp->mgr->depool);
- if (ev == NULL) {
- return (NULL);
- }
+ ev = isc_mem_get(disp->mgr->mctx, sizeof(*ev));
+ isc_refcount_increment0(&disp->mgr->irefs);
ISC_EVENT_INIT(ev, sizeof(*ev), 0, NULL, 0, NULL, NULL, NULL, NULL,
NULL);
static bool
destroy_mgr_ok(dns_dispatchmgr_t *mgr) {
mgr_log(mgr, LVL(90),
- "destroy_mgr_ok: shuttingdown=%d, listnonempty=%d, "
- "depool=%d, rpool=%d, dpool=%d",
- MGR_IS_SHUTTINGDOWN(mgr), !ISC_LIST_EMPTY(mgr->list),
- isc_mempool_getallocated(mgr->depool),
- isc_mempool_getallocated(mgr->rpool),
- isc_mempool_getallocated(mgr->dpool));
+ "destroy_mgr_ok: shuttingdown=%d, listnonempty=%d, ",
+ MGR_IS_SHUTTINGDOWN(mgr), !ISC_LIST_EMPTY(mgr->list));
if (!MGR_IS_SHUTTINGDOWN(mgr)) {
return (false);
}
if (!ISC_LIST_EMPTY(mgr->list)) {
return (false);
}
- if (isc_mempool_getallocated(mgr->depool) != 0) {
- return (false);
- }
- if (isc_mempool_getallocated(mgr->rpool) != 0) {
- return (false);
- }
- if (isc_mempool_getallocated(mgr->dpool) != 0) {
+ if (isc_refcount_current(&mgr->irefs) != 0) {
return (false);
}
isc_mutex_destroy(&mgr->lock);
mgr->state = 0;
- isc_mempool_destroy(&mgr->depool);
- isc_mempool_destroy(&mgr->rpool);
- isc_mempool_destroy(&mgr->dpool);
- if (mgr->bpool != NULL) {
- isc_mempool_destroy(&mgr->bpool);
- }
- if (mgr->spool != NULL) {
- isc_mempool_destroy(&mgr->spool);
- }
-
- isc_mutex_destroy(&mgr->spool_lock);
- isc_mutex_destroy(&mgr->bpool_lock);
- isc_mutex_destroy(&mgr->dpool_lock);
- isc_mutex_destroy(&mgr->rpool_lock);
- isc_mutex_destroy(&mgr->depool_lock);
-
if (mgr->qid != NULL) {
qid_destroy(mgr->mctx, &mgr->qid);
}
REQUIRE(mgrp != NULL && *mgrp == NULL);
mgr = isc_mem_get(mctx, sizeof(dns_dispatchmgr_t));
+ *mgr = (dns_dispatchmgr_t){ 0 };
- mgr->mctx = NULL;
isc_mem_attach(mctx, &mgr->mctx);
- mgr->blackhole = NULL;
- mgr->stats = NULL;
-
isc_mutex_init(&mgr->lock);
isc_mutex_init(&mgr->buffer_lock);
- isc_mutex_init(&mgr->depool_lock);
- isc_mutex_init(&mgr->rpool_lock);
- isc_mutex_init(&mgr->dpool_lock);
- isc_mutex_init(&mgr->bpool_lock);
- isc_mutex_init(&mgr->spool_lock);
-
- mgr->depool = NULL;
- isc_mempool_create(mgr->mctx, sizeof(dns_dispatchevent_t),
- &mgr->depool);
-
- mgr->rpool = NULL;
- isc_mempool_create(mgr->mctx, sizeof(dns_dispentry_t), &mgr->rpool);
-
- mgr->dpool = NULL;
- isc_mempool_create(mgr->mctx, sizeof(dns_dispatch_t), &mgr->dpool);
-
- isc_mempool_setname(mgr->depool, "dispmgr_depool");
- isc_mempool_setmaxalloc(mgr->depool, 32768);
- isc_mempool_setfreemax(mgr->depool, 32768);
- isc_mempool_associatelock(mgr->depool, &mgr->depool_lock);
- isc_mempool_setfillcount(mgr->depool, 32);
-
- isc_mempool_setname(mgr->rpool, "dispmgr_rpool");
- isc_mempool_setmaxalloc(mgr->rpool, 32768);
- isc_mempool_setfreemax(mgr->rpool, 32768);
- isc_mempool_associatelock(mgr->rpool, &mgr->rpool_lock);
- isc_mempool_setfillcount(mgr->rpool, 32);
-
- isc_mempool_setname(mgr->dpool, "dispmgr_dpool");
- isc_mempool_setmaxalloc(mgr->dpool, 32768);
- isc_mempool_setfreemax(mgr->dpool, 32768);
- isc_mempool_associatelock(mgr->dpool, &mgr->dpool_lock);
- isc_mempool_setfillcount(mgr->dpool, 32);
-
- mgr->buffers = 0;
- mgr->buffersize = 0;
- mgr->maxbuffers = 0;
- mgr->bpool = NULL;
- mgr->spool = NULL;
- mgr->qid = NULL;
- mgr->state = 0;
+
+ isc_refcount_init(&mgr->irefs, 0);
+
ISC_LIST_INIT(mgr->list);
- mgr->v4ports = NULL;
- mgr->v6ports = NULL;
- mgr->nv4ports = 0;
- mgr->nv6ports = 0;
+
mgr->magic = DNS_DISPATCHMGR_MAGIC;
result = create_default_portset(mctx, &v4portset);
return (ISC_R_SUCCESS);
kill_dpool:
- isc_mempool_destroy(&mgr->dpool);
- isc_mempool_destroy(&mgr->rpool);
- isc_mempool_destroy(&mgr->depool);
- isc_mutex_destroy(&mgr->spool_lock);
- isc_mutex_destroy(&mgr->bpool_lock);
- isc_mutex_destroy(&mgr->dpool_lock);
- isc_mutex_destroy(&mgr->rpool_lock);
- isc_mutex_destroy(&mgr->depool_lock);
isc_mutex_destroy(&mgr->buffer_lock);
isc_mutex_destroy(&mgr->lock);
isc_mem_putanddetach(&mctx, mgr, sizeof(dns_dispatchmgr_t));
REQUIRE(maxbuffers > 0);
REQUIRE(buckets < 2097169); /* next prime > 65536 * 32 */
REQUIRE(increment > buckets);
+ UNUSED(maxrequests);
/*
* Keep some number of items around. This should be a config
LOCK(&mgr->buffer_lock);
- /* Create or adjust buffer pool */
- if (mgr->bpool != NULL) {
- /*
- * We only increase the maxbuffers to avoid accidental buffer
- * shortage. Ideally we'd separate the manager-wide maximum
- * from per-dispatch limits and respect the latter within the
- * global limit. But at this moment that's deemed to be
- * overkilling and isn't worth additional implementation
- * complexity.
- */
- if (maxbuffers > mgr->maxbuffers) {
- isc_mempool_setmaxalloc(mgr->bpool, maxbuffers);
- isc_mempool_setfreemax(mgr->bpool, maxbuffers);
- mgr->maxbuffers = maxbuffers;
- }
- } else {
- isc_mempool_create(mgr->mctx, buffersize, &mgr->bpool);
- isc_mempool_setname(mgr->bpool, "dispmgr_bpool");
- isc_mempool_setmaxalloc(mgr->bpool, maxbuffers);
- isc_mempool_setfreemax(mgr->bpool, maxbuffers);
- isc_mempool_associatelock(mgr->bpool, &mgr->bpool_lock);
- isc_mempool_setfillcount(mgr->bpool, 32);
+ if (maxbuffers > mgr->maxbuffers) {
+ mgr->maxbuffers = maxbuffers;
}
/* Create or adjust socket pool */
- if (mgr->spool != NULL) {
- if (maxrequests < DNS_DISPATCH_POOLSOCKS * 2) {
- isc_mempool_setmaxalloc(mgr->spool,
- DNS_DISPATCH_POOLSOCKS * 2);
- isc_mempool_setfreemax(mgr->spool,
- DNS_DISPATCH_POOLSOCKS * 2);
- }
+ if (mgr->qid != NULL) {
UNLOCK(&mgr->buffer_lock);
return (ISC_R_SUCCESS);
}
- isc_mempool_create(mgr->mctx, sizeof(dispsocket_t), &mgr->spool);
-
- isc_mempool_setname(mgr->spool, "dispmgr_spool");
- isc_mempool_setmaxalloc(mgr->spool, maxrequests);
- isc_mempool_setfreemax(mgr->spool, maxrequests);
- isc_mempool_associatelock(mgr->spool, &mgr->spool_lock);
- isc_mempool_setfillcount(mgr->spool, 32);
result = qid_allocate(mgr, buckets, increment, &mgr->qid, true);
if (result != ISC_R_SUCCESS) {
return (ISC_R_SUCCESS);
cleanup:
- isc_mempool_destroy(&mgr->bpool);
- if (mgr->spool != NULL) {
- isc_mempool_destroy(&mgr->spool);
- }
UNLOCK(&mgr->buffer_lock);
return (result);
}
* the options that are controlled by tcp vs. udp, etc.
*/
- disp = isc_mempool_get(mgr->dpool);
- if (disp == NULL) {
- return (ISC_R_NOMEMORY);
- }
+ disp = isc_mem_get(mgr->mctx, sizeof(*disp));
+ isc_refcount_increment0(&mgr->irefs);
disp->magic = 0;
disp->mgr = mgr;
ISC_LIST_INIT(disp->inactivesockets);
disp->nsockets = 0;
disp->port_table = NULL;
- disp->portpool = NULL;
disp->dscp = -1;
isc_mutex_init(&disp->lock);
*/
kill_lock:
isc_mutex_destroy(&disp->lock);
- isc_mempool_put(mgr->dpool, disp);
+ isc_refcount_decrement(&mgr->irefs);
+ isc_mem_put(mgr->mctx, disp, sizeof(*disp));
return (result);
}
INSIST(ISC_LIST_EMPTY(disp->activesockets));
INSIST(ISC_LIST_EMPTY(disp->inactivesockets));
- isc_mempool_put(mgr->depool, disp->failsafe_ev);
+ isc_refcount_decrement(&mgr->irefs);
+ isc_mem_put(mgr->mctx, disp->failsafe_ev, sizeof(*disp->failsafe_ev));
disp->failsafe_ev = NULL;
if (disp->qid != NULL) {
DNS_DISPATCH_PORTTABLESIZE);
}
- if (disp->portpool != NULL) {
- isc_mempool_destroy(&disp->portpool);
- }
-
disp->mgr = NULL;
isc_mutex_destroy(&disp->lock);
disp->magic = 0;
- isc_mempool_put(mgr->dpool, disp);
+ isc_refcount_decrement(&mgr->irefs);
+ isc_mem_put(mgr->mctx, disp, sizeof(*disp));
}
isc_result_t
for (i = 0; i < DNS_DISPATCH_PORTTABLESIZE; i++) {
ISC_LIST_INIT(disp->port_table[i]);
}
-
- isc_mempool_create(mgr->mctx, sizeof(dispportentry_t),
- &disp->portpool);
- isc_mempool_setname(disp->portpool, "disp_portpool");
- isc_mempool_setfreemax(disp->portpool, 128);
}
disp->socket = sock;
disp->local = *localaddr;
destroy_disp, disp, sizeof(isc_event_t));
disp->sepool = NULL;
- isc_mempool_create(mgr->mctx, sizeof(isc_socketevent_t), &disp->sepool);
-
- isc_mutex_init(&disp->sepool_lock);
-
- isc_mempool_setname(disp->sepool, "disp_sepool");
- isc_mempool_setmaxalloc(disp->sepool, 32768);
- isc_mempool_setfreemax(disp->sepool, 32768);
- isc_mempool_associatelock(disp->sepool, &disp->sepool_lock);
- isc_mempool_setfillcount(disp->sepool, 16);
+ isc_mem_create(&disp->sepool);
+ isc_mem_setname(disp->sepool, "disp_sepool", NULL);
attributes &= ~DNS_DISPATCHATTR_TCP;
attributes |= DNS_DISPATCHATTR_UDP;
return (ISC_R_NOMORE);
}
- res = isc_mempool_get(disp->mgr->rpool);
- if (res == NULL) {
- if (dispsocket != NULL) {
- destroy_dispsocket(disp, &dispsocket);
- }
- UNLOCK(&disp->lock);
- return (ISC_R_NOMEMORY);
- }
+ res = isc_mem_get(disp->mgr->mctx, sizeof(*res));
+ isc_refcount_increment0(&disp->mgr->irefs);
disp->refcount++;
disp->requests++;
UNLOCK(&disp->lock);
isc_task_detach(&res->task);
- isc_mempool_put(disp->mgr->rpool, res);
+ isc_refcount_decrement(&disp->mgr->irefs);
+ isc_mem_put(disp->mgr->mctx, res, sizeof(*res));
return (result);
}
}
ev = ISC_LIST_HEAD(res->items);
}
res->magic = 0;
- isc_mempool_put(disp->mgr->rpool, res);
+ isc_refcount_decrement(&disp->mgr->irefs);
+ isc_mem_put(disp->mgr->mctx, res, sizeof(*res));
if (disp->shutting_down == 1) {
do_cancel(disp);
} else {
isc_stats_t *stats;
- isc_mempool_t *reqpool;
- isc_mutex_t reqlock;
-
- isc_mempool_t *evpool;
- isc_mutex_t evlock;
-
uint_fast32_t workers_running;
atomic_uint_fast32_t workers_paused;
atomic_uint_fast32_t maxudp;
atomic_init(&mgr->keepalive, 30000);
atomic_init(&mgr->advertised, 30000);
- isc_mutex_init(&mgr->reqlock);
- isc_mempool_create(mgr->mctx, sizeof(isc__nm_uvreq_t), &mgr->reqpool);
- isc_mempool_setname(mgr->reqpool, "nm_reqpool");
- isc_mempool_setfreemax(mgr->reqpool, 4096);
- isc_mempool_associatelock(mgr->reqpool, &mgr->reqlock);
- isc_mempool_setfillcount(mgr->reqpool, 32);
-
- isc_mutex_init(&mgr->evlock);
- isc_mempool_create(mgr->mctx, sizeof(isc__netievent_storage_t),
- &mgr->evpool);
- isc_mempool_setname(mgr->evpool, "nm_evpool");
- isc_mempool_setfreemax(mgr->evpool, 4096);
- isc_mempool_associatelock(mgr->evpool, &mgr->evlock);
- isc_mempool_setfillcount(mgr->evpool, 32);
-
isc_barrier_init(&mgr->pausing, workers);
isc_barrier_init(&mgr->resuming, workers);
/* Empty the async event queues */
while ((ievent = DEQUEUE_PRIORITY_NETIEVENT(worker)) != NULL) {
- isc_mempool_put(mgr->evpool, ievent);
+ isc_mem_put(mgr->mctx, ievent, sizeof(*ievent));
}
INSIST(DEQUEUE_PRIVILEGED_NETIEVENT(worker) == NULL);
INSIST(DEQUEUE_TASK_NETIEVENT(worker) == NULL);
while ((ievent = DEQUEUE_PRIORITY_NETIEVENT(worker)) != NULL) {
- isc_mempool_put(mgr->evpool, ievent);
+ isc_mem_put(mgr->mctx, ievent, sizeof(*ievent));
}
isc_condition_destroy(&worker->cond_prio);
isc_mutex_destroy(&worker->lock);
isc_condition_destroy(&mgr->wkpausecond);
isc_mutex_destroy(&mgr->lock);
- isc_mempool_destroy(&mgr->evpool);
- isc_mutex_destroy(&mgr->evlock);
-
- isc_mempool_destroy(&mgr->reqpool);
- isc_mutex_destroy(&mgr->reqlock);
-
isc_mem_put(mgr->mctx, mgr->workers,
mgr->nworkers * sizeof(isc__networker_t));
isc_mem_putanddetach(&mgr->mctx, mgr, sizeof(*mgr));
void *
isc__nm_get_netievent(isc_nm_t *mgr, isc__netievent_type type) {
- isc__netievent_storage_t *event = isc_mempool_get(mgr->evpool);
+ isc__netievent_storage_t *event = isc_mem_get(mgr->mctx,
+ sizeof(*event));
*event = (isc__netievent_storage_t){ .ni.type = type };
return (event);
void
isc__nm_put_netievent(isc_nm_t *mgr, void *ievent) {
- isc_mempool_put(mgr->evpool, ievent);
+ isc_mem_put(mgr->mctx, ievent, sizeof(isc__netievent_storage_t));
}
NETIEVENT_SOCKET_DEF(tcpclose);
isc_astack_destroy(sock->inactivehandles);
while ((uvreq = isc_astack_pop(sock->inactivereqs)) != NULL) {
- isc_mempool_put(sock->mgr->reqpool, uvreq);
+ isc_mem_put(sock->mgr->mctx, uvreq, sizeof(*uvreq));
}
isc_astack_destroy(sock->inactivereqs);
}
if (req == NULL) {
- req = isc_mempool_get(mgr->reqpool);
+ req = isc_mem_get(mgr->mctx, sizeof(*req));
}
*req = (isc__nm_uvreq_t){ .magic = 0 };
if (!isc__nmsocket_active(sock) ||
!isc_astack_trypush(sock->inactivereqs, req)) {
- isc_mempool_put(sock->mgr->reqpool, req);
+ isc_mem_put(sock->mgr->mctx, req, sizeof(*req));
}
if (handle != NULL) {