2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 18:19:42 +00:00
bind/lib/dns/lib.c
Alessio Podda 25daa047d4 Replace per-zone lock buckets with global buckets
Qpzone employs a locking strategy where rwlocks are grouped into
buckets, and each zone gets 17 buckets.
This strategy is suboptimal in two ways:
 - If named is serving a single zone or a zone is the majority of the
   traffic, this strategy pretty much guarantees contention when using
   more than a dozen threads.
 - If named is serving many small zones, it causes substantial memory
   usage.

This commit switches the locking to a global table initialized at start
time. This should have three effects:
 - Performance should improve in the single zone case, since now we are
   selecting from a bigger pool of locks.
 - Memory consumption should go down significantly in the many zone
   cases.
 - Performance should not degrade substantially in the many zone cases.
   The reason for this is that, while we could have substantially more
   zones than locks, we can query/edit only O(num threads) at the same
   time. So by making the global table much bigger than the expected
   number of threads, we can limit contention.
2025-07-09 15:27:38 +02:00

67 lines
1.3 KiB
C

/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/*! \file */
#include <isc/once.h>
#include <isc/refcount.h>
#include "acl_p.h"
#include "db_p.h"
#include "dlz_p.h"
#include "dst_internal.h"
#include "dyndb_p.h"
#include "qp_p.h"
#include "qpzone_p.h"
/***
*** Functions
***/
static isc_refcount_t dns__lib_references = 0;
void
dns__lib_initialize(void);
void
dns__lib_shutdown(void);
void
dns__lib_initialize(void) {
if (isc_refcount_increment0(&dns__lib_references) > 0) {
return;
}
dst__lib_initialize();
dns__acl_initialize();
dns__dlz_initialize();
dns__db_initialize();
dns__dyndb_initialize();
dns__qp_initialize();
dns__qpzone_initialize();
}
void
dns__lib_shutdown(void) {
if (isc_refcount_decrement(&dns__lib_references) > 1) {
return;
}
dns__qpzone_shutdown();
dns__qp_shutdown();
dns__dyndb_shutdown();
dns__db_shutdown();
dns__dlz_shutdown();
dns__acl_shutdown();
dst__lib_shutdown();
}