[Dnsmasq-discuss] [PATCH 0/2] Skip the full cache scan while no entry can have expired

Dominik Derigs git at dl6er.de
Fri Oct 30 06:34:43 UTC 2026


From: DL6ER <dl6er at dl6er.de>

Hi Simon,

with a full cache, really_insert() walks every cached entry looking for expired ones before it evicts the least-recently-used entry. With use-stale-cache a full cache normally holds nothing that can have expired yet, so the walk finds nothing and runs again on the next insert. With cache-size=100000 a miss spends about 3.6M instructions there, 7-9 ms on x86.

Patch 2 skips the walk until an entry can actually have expired. Patch 1 restores the hash-chain order the walk depends on: an entry that make_non_terminals() marks immortal stays in front of mortal entries, and the walk stops there, which also hides expired entries from it today.

I fuzzed the series against a build that always walks, comparing both operation by operation (A/AAAA, PTR, negative and DNSSEC entries, zero TTLs, DHCP leases, clock jumps, use-stale-cache off, =30 and =0), and found no difference in what gets freed or evicted.

Best regards,
Dominik


DL6ER (2):
  Keep the hash chain order when an entry becomes immortal.
  Skip the full cache scan while no entry can have expired.

 src/cache.c | 40 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)

-- 
2.53.0




More information about the Dnsmasq-discuss mailing list