]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add and use dns_cache_total_allocation()
authorNeel Chauhan <neel@neelc.org>
Mon, 16 Jul 2018 21:19:53 +0000 (17:19 -0400)
committerNeel Chauhan <neel@neelc.org>
Mon, 16 Jul 2018 21:19:53 +0000 (17:19 -0400)
src/feature/relay/dns.c
src/feature/relay/dns.h

index f4e39dfd3def1c76389d3f61640b6f9c18c27a92..8a49829d5594ddb242f485b97c87c2b43a4de99f 100644 (file)
@@ -2076,14 +2076,21 @@ dns_cache_entry_count(void)
    return HT_SIZE(&cache_root);
 }
 
+/* Return the total size in bytes of the DNS cache. */
+size_t
+dns_cache_total_allocation(void)
+{
+  return sizeof(struct cached_resolve_t) * dns_cache_entry_count() +
+         HT_MEM_USAGE(&cache_root);
+}
+
 /** Log memory information about our internal DNS cache at level 'severity'. */
 void
 dump_dns_mem_usage(int severity)
 {
   /* This should never be larger than INT_MAX. */
   int hash_count = dns_cache_entry_count();
-  size_t hash_mem = sizeof(struct cached_resolve_t) * hash_count;
-  hash_mem += HT_MEM_USAGE(&cache_root);
+  size_t hash_mem = dns_cache_total_allocation();
 
   /* Print out the count and estimated size of our &cache_root.  It undercounts
      hostnames in cached reverse resolves.
index 69c1764b73947fc3bbfd438a0106ff48602ea6cf..1d5266c73fd2e1375c2acf341830bc2d82bf5ed9 100644 (file)
@@ -38,6 +38,7 @@ void dns_launch_correctness_checks(void);
 int dns_seems_to_be_broken(void);
 int dns_seems_to_be_broken_for_ipv6(void);
 void dns_reset_correctness_checks(void);
+size_t dns_cache_total_allocation(void);
 void dump_dns_mem_usage(int severity);
 
 #ifdef DNS_PRIVATE