This adds the memory consumed by any kind of as-set, prefix-set,
origin-set or roa-set to the output of show rib mem.

Here the output of a system that has RPKI ROA loaded.

RDE memory statistics
    714982 IPv4 unicast network entries using 27.3M of memory
     56393 IPv6 unicast network entries using 3.0M of memory
   1526718 rib entries using 93.2M of memory
   3053428 prefix entries using 280M of memory
    270426 BGP path attribute entries using 28.9M of memory
    112881 BGP AS-PATH attribute entries using 5.2M of memory,
           and holding 270426 references
     18337 BGP attributes entries using 716K of memory
           and holding 330395 references
     18336 BGP attributes using 252K of memory
     61415 as-set elements in 57669 tables using 1.8M of memory
    102389 prefix-set elments using 4.3M of memory
RIB using 438M of memory
Sets using 6.0M of memory

-- 
:wq Claudio

Index: bgpctl/bgpctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpctl/bgpctl.c,v
retrieving revision 1.219
diff -u -p -r1.219 bgpctl.c
--- bgpctl/bgpctl.c     1 Oct 2018 23:09:53 -0000       1.219
+++ bgpctl/bgpctl.c     26 Oct 2018 11:09:07 -0000
@@ -1875,12 +1875,19 @@ show_rib_memory_msg(struct imsg *imsg)
                    (long long)stats.attr_refs);
                printf("%10lld BGP attributes using %s of memory\n",
                    (long long)stats.attr_dcnt, fmt_mem(stats.attr_data));
+               printf("%10lld as-set elements in %lld tables using "
+                   "%s of memory\n", stats.aset_nmemb, stats.aset_cnt,
+                   fmt_mem(stats.aset_size));
+               printf("%10lld prefix-set elments using %s of memory\n",
+                   stats.pset_cnt, fmt_mem(stats.pset_size));
                printf("RIB using %s of memory\n", fmt_mem(pts +
                    stats.prefix_cnt * sizeof(struct prefix) +
                    stats.rib_cnt * sizeof(struct rib_entry) +
                    stats.path_cnt * sizeof(struct rde_aspath) +
                    stats.aspath_size + stats.attr_cnt * sizeof(struct attr) +
                    stats.attr_data));
+               printf("Sets using %s of memory\n", fmt_mem(stats.aset_size +
+                   stats.pset_size));
                printf("\nRDE hash statistics\n");
                break;
        case IMSG_CTL_SHOW_RIB_HASH:
Index: bgpd/bgpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.349
diff -u -p -r1.349 bgpd.h
--- bgpd/bgpd.h 3 Oct 2018 11:36:39 -0000       1.349
+++ bgpd/bgpd.h 26 Oct 2018 11:23:53 -0000
@@ -1077,6 +1077,11 @@ struct rde_memstats {
        int64_t         attr_refs;
        int64_t         attr_data;
        int64_t         attr_dcnt;
+       int64_t         aset_cnt;
+       int64_t         aset_size;
+       int64_t         aset_nmemb;
+       int64_t         pset_cnt;
+       int64_t         pset_size;
 };
 
 struct rde_hashstats {
Index: bgpd/rde_sets.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_sets.c,v
retrieving revision 1.5
diff -u -p -r1.5 rde_sets.c
--- bgpd/rde_sets.c     20 Sep 2018 11:45:59 -0000      1.5
+++ bgpd/rde_sets.c     26 Oct 2018 11:01:26 -0000
@@ -125,6 +125,8 @@ set_new(size_t nmemb, size_t size)
                return NULL;
        }
 
+       rdemem.aset_cnt++;
+       rdemem.aset_size += sizeof(*set);
        return set;
 }
 
@@ -133,6 +135,10 @@ set_free(struct set_table *set)
 {
        if (set == NULL)
                return;
+       rdemem.aset_cnt--;
+       rdemem.aset_size -= sizeof(*set);
+       rdemem.aset_size -= set->size * set->max;
+       rdemem.aset_nmemb -= set->nmemb;
        free(set->set);
        free(set);
 }
@@ -154,6 +160,7 @@ set_add(struct set_table *set, void *elm
                s = reallocarray(set->set, new_size, set->size);
                if (s == NULL)
                        return -1;
+               rdemem.aset_size += set->size * (new_size - set->max);
                set->set = s;
                set->max = new_size;
        }
@@ -161,6 +168,7 @@ set_add(struct set_table *set, void *elm
        memcpy((u_int8_t *)set->set + set->nmemb * set->size, elms,
            nelms * set->size);
        set->nmemb += nelms;
+       rdemem.aset_nmemb += nelms;
 
        return 0;
 }
Index: bgpd/rde_trie.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_trie.c,v
retrieving revision 1.9
diff -u -p -r1.9 rde_trie.c
--- bgpd/rde_trie.c     29 Sep 2018 08:11:11 -0000      1.9
+++ bgpd/rde_trie.c     26 Oct 2018 10:49:20 -0000
@@ -165,6 +165,8 @@ trie_add_v4(struct trie_head *th, struct
                         */
                        if ((b = calloc(1, sizeof(*b))) == NULL)
                                return NULL;
+                       rdemem.pset_cnt++;
+                       rdemem.pset_size += sizeof(*b);
                        b->plen = inet4findmsb(&n->addr, &mp);
                        inet4applymask(&b->addr, &n->addr, b->plen);
 
@@ -202,6 +204,8 @@ trie_add_v4(struct trie_head *th, struct
        /* create new node */
        if ((new = calloc(1, sizeof(*new))) == NULL)
                return NULL;
+       rdemem.pset_cnt++;
+       rdemem.pset_size += sizeof(*new);
        new->addr = p;
        new->plen = plen;
        new->node = 1;
@@ -241,6 +245,8 @@ trie_add_v6(struct trie_head *th, struct
                         */
                        if ((b = calloc(1, sizeof(*b))) == NULL)
                                return NULL;
+                       rdemem.pset_cnt++;
+                       rdemem.pset_size += sizeof(*b);
                        b->plen = inet6findmsb(&n->addr, &mp);
                        inet6applymask(&b->addr, &n->addr, b->plen);
 
@@ -278,6 +284,8 @@ trie_add_v6(struct trie_head *th, struct
        /* create new node */
        if ((new = calloc(1, sizeof(*new))) == NULL)
                return NULL;
+       rdemem.pset_cnt++;
+       rdemem.pset_size += sizeof(*new);
        new->addr = p;
        new->plen = plen;
        new->node = 1;
@@ -420,6 +428,8 @@ trie_free_v4(struct tentry_v4 *n)
        trie_free_v4(n->trie[1]);
        set_free(n->set);
        free(n);
+       rdemem.pset_cnt--;
+       rdemem.pset_size -= sizeof(*n);
 }
 
 static void
@@ -431,6 +441,8 @@ trie_free_v6(struct tentry_v6 *n)
        trie_free_v6(n->trie[1]);
        set_free(n->set);
        free(n);
+       rdemem.pset_cnt--;
+       rdemem.pset_size -= sizeof(*n);
 }
 
 void

Reply via email to