Merge branch '2770-allow-hash-tables-for-cache-rbts-to-be-grown-v9_16' into 'v9_16'

[v9_16] Allow hash tables for cache RBTs to be grown

See merge request isc-projects/bind9!5191
This commit is contained in:
Michał Kępień
2021-06-17 15:44:38 +00:00
4 changed files with 35 additions and 11 deletions

View File

@@ -1,3 +1,8 @@
5658. [bug] Increasing "max-cache-size" for a running named instance
(using "rndc reconfig") was not causing the hash tables
used by cache databases to be grown accordingly. This
has been fixed. [GL #2770]
5655. [bug] Signed, insecure delegation responses prepared by named
either lacked the necessary NSEC records or contained
duplicate NSEC records when both wildcard expansion and

View File

@@ -957,8 +957,9 @@ dns_cache_setcachesize(dns_cache_t *cache, size_t size) {
* time, or replacing other limits).
*/
isc_mem_setwater(cache->mctx, water, cache, hiwater, lowater);
dns_db_adjusthashsize(cache->db, size);
}
dns_db_adjusthashsize(cache->db, size);
}
size_t

View File

@@ -1400,14 +1400,15 @@ dns_db_hashsize(dns_db_t *db);
isc_result_t
dns_db_adjusthashsize(dns_db_t *db, size_t size);
/*%<
* For database implementations using a hash table, adjust
* the size of the hash table to store objects with size
* memory footprint.
* For database implementations using a hash table, adjust the size of
* the hash table to store objects with a maximum total memory footprint
* of 'size' bytes. If 'size' is set to 0, it means no finite limit is
* requested.
*
* Requires:
*
* \li 'db' is a valid database.
* \li 'size' is maximum memory footprint of the database
* \li 'size' is maximum memory footprint of the database in bytes
*
* Returns:
* \li #ISC_R_SUCCESS The registration succeeded

View File

@@ -1081,11 +1081,28 @@ isc_result_t
dns_rbt_adjusthashsize(dns_rbt_t *rbt, size_t size) {
REQUIRE(VALID_RBT(rbt));
size_t newsize = size / RBT_HASH_BUCKETSIZE;
rbt->maxhashbits = rehash_bits(rbt, newsize);
maybe_rehash(rbt, newsize);
if (size > 0) {
/*
* Setting a new, finite size limit was requested for the RBT.
* Estimate how many hash table slots are needed for the
* requested size and how many bits would be needed to index
* those hash table slots, then rehash the RBT if necessary.
* Note that the hash table can only grow, it is not shrunk if
* the requested size limit is lower than the current one.
*/
size_t newsize = size / RBT_HASH_BUCKETSIZE;
rbt->maxhashbits = rehash_bits(rbt, newsize);
maybe_rehash(rbt, newsize);
} else {
/*
* Setting an infinite size limit was requested for the RBT.
* Increase the maximum allowed number of hash table slots to
* 2^32, which enables the hash table to grow as nodes are
* added to the RBT without immediately preallocating 2^32 hash
* table slots.
*/
rbt->maxhashbits = RBT_HASH_MAX_BITS;
}
return (ISC_R_SUCCESS);
}
@@ -2338,7 +2355,7 @@ static uint32_t
rehash_bits(dns_rbt_t *rbt, size_t newcount) {
uint32_t newbits = rbt->hashbits;
while (newcount >= HASHSIZE(newbits) && newbits < rbt->maxhashbits) {
while (newcount >= HASHSIZE(newbits) && newbits < RBT_HASH_MAX_BITS) {
newbits += 1;
}