]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix the isc_hp initialization and memory usage
authorOndřej Surý <ondrej@isc.org>
Tue, 7 Dec 2021 10:15:27 +0000 (11:15 +0100)
committerOndřej Surý <ondrej@isc.org>
Tue, 7 Dec 2021 19:41:46 +0000 (20:41 +0100)
Previously, the isc_hp_init() could not lower the value of
isc__hp_max_threads, but because of a mistake the isc__hp_max_threads
would be set to HP_MAX_THREADS (e.g. 128 threads) thus it would be
always set to 128.  This would result in increased memory usage even
when small number of workers were in use.

Change the default value of isc__hp_max_threads to be 1.

Additionally, enforce the max_hps value in isc_hp_new() to be smaller or
equal to HP_MAX_HPS.  The only user is isc_queue which uses just 1
hazard pointer, so it's only theoretical issue.

lib/isc/hp.c

index 20646a8a74463a9d6d0a64ac6c70a09df870539f..aaa59f6c45eb7c7a94d835f2f6471f899b27c0af 100644 (file)
@@ -54,7 +54,7 @@
 #include <isc/util.h>
 
 #define HP_MAX_THREADS 128
-static int isc__hp_max_threads = HP_MAX_THREADS;
+static int isc__hp_max_threads = 1;
 #define HP_MAX_HPS     4 /* This is named 'K' in the HP paper */
 #define CLPAD         (128 / sizeof(uintptr_t))
 #define HP_THRESHOLD_R 0 /* This is named 'R' in the HP paper */
@@ -82,9 +82,12 @@ tid(void) {
 
 void
 isc_hp_init(int max_threads) {
+       REQUIRE(max_threads > 0);
+
        if (isc__hp_max_threads > max_threads) {
                return;
        }
+
        isc__hp_max_threads = max_threads;
        isc__hp_max_retired = max_threads * HP_MAX_HPS;
 }
@@ -93,6 +96,9 @@ isc_hp_t *
 isc_hp_new(isc_mem_t *mctx, size_t max_hps, isc_hp_deletefunc_t *deletefunc) {
        isc_hp_t *hp = isc_mem_get(mctx, sizeof(*hp));
 
+       REQUIRE(isc__hp_max_threads > 0);
+       REQUIRE(max_hps <= HP_MAX_HPS);
+
        if (max_hps == 0) {
                max_hps = HP_MAX_HPS;
        }