]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Compact more in dns_qp_compact(DNS_QPGC_ALL)
authorTony Finch <fanf@isc.org>
Fri, 3 Mar 2023 12:05:51 +0000 (12:05 +0000)
committerTony Finch <fanf@isc.org>
Wed, 5 Apr 2023 11:35:04 +0000 (12:35 +0100)
Commit 0858514ae8 enriched dns_qp_compact() to give callers more
control over how thoroughly the trie should be compacted.

In the DNS_QPGC_ALL case, if the trie is small it might be compacted
to a new position in the same memory chunk. In this situation it will
still be holding references to old leaf objects which have been
removed from the trie but will not be completely detached until the
chunk containing the references is freed.

This change resets the qp-trie allocator to a fresh chunk before a
DNS_QPGC_ALL compaction, so all the old memory chunks will be
evacuated and old leaf objects can be detached sooner.

lib/dns/qp.c
tests/bench/load-names.c
tests/bench/qp-dump.c
tests/bench/qpmulti.c

index bec2ef84850e51e902f5998cca38f0e74731821e..881b68ec9a586bf7e0a135898e51e5d9dc579c6b 100644 (file)
@@ -903,6 +903,7 @@ dns_qp_compact(dns_qp_t *qp, dns_qpgc_t mode) {
                return;
        }
        if (mode == DNS_QPGC_ALL) {
+               alloc_reset(qp);
                qp->compact_all = true;
        }
        compact(qp);
index a1473d8694e249bd20eca504aec705b40734eb3c..f7d5aa79d24dea59897c68afe93be371ddab70cb 100644 (file)
@@ -164,7 +164,7 @@ add_qp(void *qp, size_t count) {
 
 static void
 sqz_qp(void *qp) {
-       dns_qp_compact(qp, true);
+       dns_qp_compact(qp, DNS_QPGC_ALL);
 }
 
 static isc_result_t
index 515048ea97fdde7c87b1294092cb42e0f892f0fd..9cf72c1661665183fa2ae404cca194b403cf2941 100644 (file)
@@ -224,7 +224,7 @@ main(int argc, char *argv[]) {
                labels += name->labels;
                names += 1;
        }
-       dns_qp_compact(qp, true);
+       dns_qp_compact(qp, DNS_QPGC_ALL);
 
        size_t smallbytes = wirebytes + labels + names * sizeof(isc_refcount_t);
        dns_qp_memusage_t memusage = dns_qp_memusage(qp);
index 59c9a11a3efdafa49f552fda95eed412abc96d07..f6150024a92300bb0659e4926343d7054586ebf7 100644 (file)
@@ -323,8 +323,12 @@ mutate_transactions(uv_idle_t *idle) {
                                args->absent++;
                        }
                }
+               /*
+                * We would normally use DNS_QPGC_MAYBE, but here we do the
+                * fragmented check ourself so we can count compactions
+                */
                if (dns_qp_memusage(qp).fragmented) {
-                       dns_qp_compact(qp, false);
+                       dns_qp_compact(qp, DNS_QPGC_NOW);
                        args->compactions++;
                }
                dns_qpmulti_commit(args->multi, &qp);
@@ -392,7 +396,7 @@ load_multi(struct bench_state *bctx) {
                item[i].present = true;
                count++;
        }
-       dns_qp_compact(qp, true);
+       dns_qp_compact(qp, DNS_QPGC_ALL);
        dns_qpmulti_commit(bctx->multi, &qp);
 
        bctx->load_time = isc_time_monotonic() - start;