From 39f38754e22d048275e0cadf2ce480408c70cab7 Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Fri, 3 Mar 2023 12:05:51 +0000 Subject: [PATCH] Compact more in dns_qp_compact(DNS_QPGC_ALL) 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 | 1 + tests/bench/load-names.c | 2 +- tests/bench/qp-dump.c | 2 +- tests/bench/qpmulti.c | 8 ++++++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/dns/qp.c b/lib/dns/qp.c index bec2ef8485..881b68ec9a 100644 --- a/lib/dns/qp.c +++ b/lib/dns/qp.c @@ -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); diff --git a/tests/bench/load-names.c b/tests/bench/load-names.c index a1473d8694..f7d5aa79d2 100644 --- a/tests/bench/load-names.c +++ b/tests/bench/load-names.c @@ -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 diff --git a/tests/bench/qp-dump.c b/tests/bench/qp-dump.c index 515048ea97..9cf72c1661 100644 --- a/tests/bench/qp-dump.c +++ b/tests/bench/qp-dump.c @@ -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); diff --git a/tests/bench/qpmulti.c b/tests/bench/qpmulti.c index 59c9a11a3e..f6150024a9 100644 --- a/tests/bench/qpmulti.c +++ b/tests/bench/qpmulti.c @@ -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;