]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Reduce amount of memory pre-allocated for dictionaries
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 24 May 2018 09:22:13 +0000 (15:22 +0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 24 May 2018 09:22:13 +0000 (15:22 +0600)
src/lib/util/dict.c
src/main/radict.c

index 6cfc6c5529881258a2349c56b0c0eff0f50b3ac2..6042f49b62edb78ead6ee77d0a0ab63d7928dd64 100644 (file)
@@ -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, "<INVALID>"));
+       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, "<INVALID>"), 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)
index 77be8b3571e83bbf7d4ccdb889bfe436b8ff0819..d1992d18b90bf996a4a48191f51a0da5f9e7cd62 100644 (file)
@@ -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);
        }