]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Reduce the number of mctx created in clientmgr
authorOndřej Surý <ondrej@sury.org>
Tue, 11 May 2021 10:03:11 +0000 (12:03 +0200)
committerOndřej Surý <ondrej@sury.org>
Mon, 24 May 2021 18:02:20 +0000 (20:02 +0200)
The number of memory contexts created in the clientmgr was enormous.  It
could easily create thousands of memory contexts because the formula was:

    nprotocols * ncpus * ninterfaces * CLIENT_NMCTXS_PERCPU (8)

The original goal was to reduce the contention when allocating the
memory, but after a while nobody noticed that the amount of memory
context allocated would not reduce contention at all.

This commit removes the whole mctxpool and just uses the mctx from
clientmgr as the contention will be reduced directly in the allocator.

lib/ns/client.c
lib/ns/include/ns/client.h

index 940ad08caf38aded9e3dbeed21e61a9abaa30ebb..6d50c1564c24b4d02e845e7aa3e02b20e0642446 100644 (file)
@@ -147,8 +147,6 @@ static void
 compute_cookie(ns_client_t *client, uint32_t when, uint32_t nonce,
               const unsigned char *secret, isc_buffer_t *buf);
 static void
-get_clientmctx(ns_clientmgr_t *manager, isc_mem_t **mctxp);
-static void
 get_clienttask(ns_clientmgr_t *manager, isc_task_t **taskp);
 
 void
@@ -2236,22 +2234,6 @@ ns__client_tcpconn(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
        return (ISC_R_SUCCESS);
 }
 
-static void
-get_clientmctx(ns_clientmgr_t *manager, isc_mem_t **mctxp) {
-       isc_mem_t *clientmctx;
-       MTRACE("clientmctx");
-
-       int tid = isc_nm_tid();
-       if (tid < 0) {
-               tid = isc_random_uniform(manager->ncpus);
-       }
-       int rand = isc_random_uniform(CLIENT_NMCTXS_PERCPU);
-       int nextmctx = (rand * manager->ncpus) + tid;
-       clientmctx = manager->mctxpool[nextmctx];
-
-       isc_mem_attach(clientmctx, mctxp);
-}
-
 static void
 get_clienttask(ns_clientmgr_t *manager, isc_task_t **taskp) {
        MTRACE("clienttask");
@@ -2284,7 +2266,7 @@ ns__client_setup(ns_client_t *client, ns_clientmgr_t *mgr, bool new) {
        if (new) {
                *client = (ns_client_t){ .magic = 0 };
 
-               get_clientmctx(mgr, &client->mctx);
+               isc_mem_attach(mgr->mctx, &client->mctx);
                clientmgr_attach(mgr, &client->manager);
                ns_server_attach(mgr->sctx, &client->sctx);
                get_clienttask(mgr, &client->task);
@@ -2419,13 +2401,6 @@ clientmgr_destroy(ns_clientmgr_t *manager) {
        isc_refcount_destroy(&manager->references);
        manager->magic = 0;
 
-       for (i = 0; i < manager->ncpus * CLIENT_NMCTXS_PERCPU; i++) {
-               isc_mem_detach(&manager->mctxpool[i]);
-       }
-       isc_mem_put(manager->mctx, manager->mctxpool,
-                   manager->ncpus * CLIENT_NMCTXS_PERCPU *
-                           sizeof(isc_mem_t *));
-
        if (manager->interface != NULL) {
                ns_interface_detach(&manager->interface);
        }
@@ -2457,7 +2432,6 @@ ns_clientmgr_create(isc_mem_t *mctx, ns_server_t *sctx, isc_taskmgr_t *taskmgr,
        ns_clientmgr_t *manager;
        isc_result_t result;
        int i;
-       int npools;
 
        manager = isc_mem_get(mctx, sizeof(*manager));
        *manager = (ns_clientmgr_t){ .magic = 0 };
@@ -2494,15 +2468,6 @@ ns_clientmgr_create(isc_mem_t *mctx, ns_server_t *sctx, isc_taskmgr_t *taskmgr,
 
        ISC_LIST_INIT(manager->recursing);
 
-       npools = CLIENT_NMCTXS_PERCPU * manager->ncpus;
-       manager->mctxpool = isc_mem_get(manager->mctx,
-                                       npools * sizeof(isc_mem_t *));
-       for (i = 0; i < npools; i++) {
-               manager->mctxpool[i] = NULL;
-               isc_mem_create(&manager->mctxpool[i]);
-               isc_mem_setname(manager->mctxpool[i], "client");
-       }
-
        manager->magic = MANAGER_MAGIC;
 
        MTRACE("create");
index 737d5e417da0d3b8c45fad64be968ee6d59da706..c107277f8480afcca5b28b7866aebd707e14815c 100644 (file)
@@ -164,9 +164,6 @@ struct ns_clientmgr {
        /* Lock covers the recursing list */
        isc_mutex_t   reclock;
        client_list_t recursing; /*%< Recursing clients */
-
-       /*%< mctx pool for clients. */
-       isc_mem_t **mctxpool;
 };
 
 /*% nameserver client structure */