diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2018-10-26 16:53:56 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2018-10-26 16:53:56 +0000 |
commit | c9464ba0fc86ebd662b34c995d589414d0e088fa (patch) | |
tree | 8db2c42d30b6f883ed0c3e6aaf20b67ae22a7d07 | |
parent | e0a9ae8c19422164f2423e1e9e205a3fd1799dff (diff) |
Track the amount of memory used for sets and tries (aka anything-set)
OK deraadt@
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 7 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_sets.c | 10 | ||||
-rw-r--r-- | usr.sbin/bgpd/rde_trie.c | 14 |
3 files changed, 28 insertions, 3 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index c45f23ba0b0..702d00aa1bf 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.349 2018/10/03 11:36:39 denis Exp $ */ +/* $OpenBSD: bgpd.h,v 1.350 2018/10/26 16:53:55 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -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 { diff --git a/usr.sbin/bgpd/rde_sets.c b/usr.sbin/bgpd/rde_sets.c index 6c72748d7e5..5621af1bf5f 100644 --- a/usr.sbin/bgpd/rde_sets.c +++ b/usr.sbin/bgpd/rde_sets.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_sets.c,v 1.5 2018/09/20 11:45:59 claudio Exp $ */ +/* $OpenBSD: rde_sets.c,v 1.6 2018/10/26 16:53:55 claudio Exp $ */ /* * Copyright (c) 2018 Claudio Jeker <claudio@openbsd.org> @@ -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 *elms, size_t nelms) 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 *elms, size_t nelms) memcpy((u_int8_t *)set->set + set->nmemb * set->size, elms, nelms * set->size); set->nmemb += nelms; + rdemem.aset_nmemb += nelms; return 0; } diff --git a/usr.sbin/bgpd/rde_trie.c b/usr.sbin/bgpd/rde_trie.c index 72ba4f534be..13b92b139d7 100644 --- a/usr.sbin/bgpd/rde_trie.c +++ b/usr.sbin/bgpd/rde_trie.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_trie.c,v 1.9 2018/09/29 08:11:11 claudio Exp $ */ +/* $OpenBSD: rde_trie.c,v 1.10 2018/10/26 16:53:55 claudio Exp $ */ /* * Copyright (c) 2018 Claudio Jeker <claudio@openbsd.org> @@ -165,6 +165,8 @@ trie_add_v4(struct trie_head *th, struct in_addr *prefix, u_int8_t plen) */ 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 in_addr *prefix, u_int8_t plen) /* 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 in6_addr *prefix, u_int8_t plen) */ 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 in6_addr *prefix, u_int8_t plen) /* 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 |