From: Wouter Wijngaards Date: Tue, 27 Nov 2007 15:52:41 +0000 (+0000) Subject: memory footprint improvements. X-Git-Tag: release-0.8~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f64778a893f67236de2507d26ae34a8666de6ce2;p=thirdparty%2Funbound.git memory footprint improvements. git-svn-id: file:///svn/unbound/trunk@778 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index 1b0d77004..834fb9e76 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,11 @@ 27 November 2007: Wouter - per suggestion in rfc2308, replaced default max-ttl value with 1 day. + - set size of msgparse lookup table to 32, from 1024, so that its size + is below the 2048 regional large size threshold, and does not cause + a call to malloc when a message is parsed. + - update of memstats tool to print number of allocation calls. + This is what is taking time (not space) and indicates the avg size + of the allocations as well. region_alloc stat is removed. 22 November 2007: Wouter - noted EDNS in-the-middle dropping trouble as a TODO. diff --git a/services/cache/dns.h b/services/cache/dns.h index 152c44ad2..6d16022f2 100644 --- a/services/cache/dns.h +++ b/services/cache/dns.h @@ -137,6 +137,4 @@ struct dns_msg* dns_cache_lookup(struct module_env* env, int cache_fill_missing(struct module_env* env, uint16_t qclass, struct regional* region, struct delegpt* dp); -/** Find covering DNAME */ - #endif /* SERVICES_CACHE_DNS_H */ diff --git a/testcode/memstats.c b/testcode/memstats.c index 369dc59ce..bf48d7f71 100644 --- a/testcode/memstats.c +++ b/testcode/memstats.c @@ -60,14 +60,8 @@ struct codeline { uint64_t alloc; /** number of bytes freed */ uint64_t free; -}; - -/** - * Other allocation stats - */ -struct alloc_misc { - /** number of region allocs */ - uint64_t region_alloc; + /** number allocations and frees */ + uint64_t calls; }; /** print usage and exit */ @@ -101,18 +95,6 @@ match(char* line) return 0; } -/** read up the region stats */ -static void -read_region_stat(char* line, struct alloc_misc* misc) -{ - long num = 0; - if(sscanf(line+50, "%ld", &num) != 1) { - printf("%s\n%s\n", line, line+50); - fatal_exit("unhandled region"); - } - misc->region_alloc += num; -} - /** find or alloc codeline in tree */ static struct codeline* get_codeline(rbtree_t* tree, char* key, char* func) @@ -153,6 +135,7 @@ read_malloc_stat(char* line, rbtree_t* tree) if(!cl) fatal_exit("alloc failure"); cl->alloc += num; + cl->calls ++; } /** read up the calloc stats */ @@ -177,6 +160,7 @@ read_calloc_stat(char* line, rbtree_t* tree) if(!cl) fatal_exit("alloc failure"); cl->alloc += num*sz; + cl->calls ++; } /** get size of file */ @@ -192,7 +176,7 @@ get_file_size(const char* fname) /** read the logfile */ static void -readfile(rbtree_t* tree, const char* fname, struct alloc_misc* misc) +readfile(rbtree_t* tree, const char* fname) { off_t total = get_file_size(fname); off_t done = (off_t)0; @@ -213,8 +197,6 @@ readfile(rbtree_t* tree, const char* fname, struct alloc_misc* misc) if(!match(buf)) continue; - if(strncmp(buf+36, "region ", 7) == 0) - read_region_stat(buf, misc); else if(strstr(buf+36, "malloc(")) read_malloc_stat(buf, tree); else if(strstr(buf+36, "calloc(")) @@ -230,20 +212,19 @@ readfile(rbtree_t* tree, const char* fname, struct alloc_misc* misc) /** print memory stats */ static void -printstats(rbtree_t* tree, struct alloc_misc* misc) +printstats(rbtree_t* tree) { struct codeline* cl; - uint64_t total = 0; - printf("%12lld in region alloc\n", (long long)misc->region_alloc); - total += misc->region_alloc; + uint64_t total = 0, tcalls = 0; RBTREE_FOR(cl, struct codeline*, tree) { - printf("%12lld in %s %s\n", (long long)cl->alloc, - cl->codeline, cl->func); + printf("%12lld / %8lld in %s %s\n", (long long)cl->alloc, + (long long)cl->calls, cl->codeline, cl->func); total += cl->alloc; + tcalls += cl->calls; } printf("------------\n"); - printf("%12lld total in %ld code lines\n", (long long)total, - (long)tree->count); + printf("%12lld / %8lld total in %ld code lines\n", (long long)total, + (long long)tcalls, (long)tree->count); printf("\n"); } @@ -251,15 +232,13 @@ printstats(rbtree_t* tree, struct alloc_misc* misc) int main(int argc, const char* argv[]) { rbtree_t* tree = 0; - struct alloc_misc misc; if(argc != 2) { usage(); } tree = rbtree_create(codeline_cmp); if(!tree) fatal_exit("alloc failure"); - memset(&misc, 0, sizeof(misc)); - readfile(tree, argv[1], &misc); - printstats(tree, &misc); + readfile(tree, argv[1]); + printstats(tree); return 0; } diff --git a/util/data/msgparse.h b/util/data/msgparse.h index c5e258874..ea21a4269 100644 --- a/util/data/msgparse.h +++ b/util/data/msgparse.h @@ -68,7 +68,7 @@ struct rr_parse; struct regional; /** number of buckets in parse rrset hash table. Must be power of 2. */ -#define PARSE_TABLE_SIZE 1024 +#define PARSE_TABLE_SIZE 32 /** Maximum TTL that is allowed. */ extern uint32_t MAX_TTL; /** Negative cache time (for entries without any RRs.) */