From: Arran Cudbard-Bell Date: Thu, 24 May 2018 09:22:13 +0000 (+0600) Subject: Reduce amount of memory pre-allocated for dictionaries X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=43ee91014264c80cf4767e0e4ed203fcbb40767c;p=thirdparty%2Ffreeradius-server.git Reduce amount of memory pre-allocated for dictionaries --- diff --git a/src/lib/util/dict.c b/src/lib/util/dict.c index 6cfc6c55298..6042f49b62e 100644 --- a/src/lib/util/dict.c +++ b/src/lib/util/dict.c @@ -3679,9 +3679,12 @@ static fr_dict_t *dict_alloc(TALLOC_CTX *ctx) } /* - * Pre-Allocate 5MB of pool memory for rapid startup + * Pre-Allocate 2MB of pool memory for rapid startup + * This is about what's reported for all current dictionary + * attributes in the monolithic dictionary, and will go + * down once the dictionaries are split. */ - dict->pool = talloc_pool(dict, (1024 * 1024 * 5)); + dict->pool = talloc_pool(dict, (1024 * 1024 * 2)); if (!dict->pool) goto error; /* @@ -5382,8 +5385,12 @@ static void _fr_dict_dump(fr_dict_attr_t const *da, unsigned int lvl) unsigned int i; size_t len; fr_dict_attr_t const *p; + char flags[256]; - printf("%p - %s (%u) %s\n", da, da->name, da->attr, fr_int2str(dict_attr_types, da->type, "")); + fr_dict_snprint_flags(flags, sizeof(flags), &da->flags); + + printf("[%02i] 0x%016" PRIxPTR "%*s %s(%u) %s %s\n", lvl, (unsigned long)da, lvl * 2, " ", + da->name, da->attr, fr_int2str(dict_attr_types, da->type, ""), flags); len = talloc_array_length(da->children); for (i = 0; i < len; i++) { @@ -5391,7 +5398,6 @@ static void _fr_dict_dump(fr_dict_attr_t const *da, unsigned int lvl) _fr_dict_dump(p, lvl + 1); } } - } void fr_dict_dump(fr_dict_t *dict) diff --git a/src/main/radict.c b/src/main/radict.c index 77be8b3571e..d1992d18b90 100644 --- a/src/main/radict.c +++ b/src/main/radict.c @@ -136,6 +136,35 @@ static void da_print_info_td(fr_dict_t const *dict, fr_dict_attr_t const *da) fr_int2str(dict_attr_types, da->type, "?Unknown?"), flags); } +static void _fr_dict_export(uint64_t *count, fr_dict_attr_t const *da, unsigned int lvl) +{ + unsigned int i; + size_t len; + fr_dict_attr_t const *p; + char flags[256]; + + fr_dict_snprint_flags(flags, sizeof(flags), &da->flags); + + if (!da->flags.is_root) da_print_info_td(fr_dict_by_da(da), da); + (*count)++; + + len = talloc_array_length(da->children); + for (i = 0; i < len; i++) { + for (p = da->children[i]; p; p = p->next) { + _fr_dict_export(count, p, lvl + 1); + } + } +} + +static uint64_t fr_dict_export(fr_dict_t *dict) +{ + uint64_t count = 0; + + _fr_dict_export(&count, fr_dict_root(dict), 0); + + return count; +} + int main(int argc, char *argv[]) { char const *dict_dir = DICTDIR; @@ -216,7 +245,11 @@ int main(int argc, char *argv[]) fr_dict_t **dict_p = dicts; do { - fr_dict_dump(*dict_p); + uint64_t count; + + count = fr_dict_export(*dict_p); + DEBUG2("Total attr %" PRIu64, count); + DEBUG2("Total size %zu (bytes)", talloc_total_size(*dict_p)); } while (++dict_p < dict_end); }