summaryrefslogtreecommitdiff
path: root/lib/memory.h
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2018-08-08 16:44:43 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2018-08-08 20:17:55 +0200
commit602a6584ee4f7c9f881204cc413fab73f18791f0 (patch)
tree77ff31767a676b1f544b1938065995c285c78ce2 /lib/memory.h
parentfa896a1d807248b8bd3343b77f8668d80de1ec98 (diff)
lib: count total memory allocation per MTYPE
If malloc_usable_size() or malloc_size() are available, we can count total usage of a particular MTYPE. (Without the functions, we don't know how much to subtract on free.) Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/memory.h')
-rw-r--r--lib/memory.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/memory.h b/lib/memory.h
index 1fbbbe4231..c39f34e3a7 100644
--- a/lib/memory.h
+++ b/lib/memory.h
@@ -24,12 +24,20 @@
#define array_size(ar) (sizeof(ar) / sizeof(ar[0]))
+#if defined(HAVE_MALLOC_SIZE) && !defined(HAVE_MALLOC_USABLE_SIZE)
+#define malloc_usable_size(x) malloc_size(x)
+#define HAVE_MALLOC_USABLE_SIZE
+#endif
+
#define SIZE_VAR ~0UL
struct memtype {
struct memtype *next, **ref;
const char *name;
_Atomic size_t n_alloc;
_Atomic size_t size;
+#ifdef HAVE_MALLOC_USABLE_SIZE
+ _Atomic size_t total;
+#endif
};
struct memgroup {