summaryrefslogtreecommitdiff
path: root/lib/memory.c
diff options
context:
space:
mode:
authorLou Berger <lberger@labn.net>2018-08-28 16:54:07 -0400
committerLou Berger <lberger@labn.net>2018-08-28 19:22:30 -0400
commit13f1ba41a12a1a5298b0fb0021895284990aaf70 (patch)
treefcc0d85f8c5cc45ecf4296d6808bb9263db42a8c /lib/memory.c
parent96487ee47875a8d47590e17343a4b373ef5adf9d (diff)
lib: qmem show changes (header and max)
add header to show qmem, align table with headers add tracking of max # allocs and max bytes alloc'ed Signed-off-by: Lou Berger <lberger@labn.net>
Diffstat (limited to 'lib/memory.c')
-rw-r--r--lib/memory.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/memory.c b/lib/memory.c
index 87cba69fc5..642d1325ed 100644
--- a/lib/memory.c
+++ b/lib/memory.c
@@ -36,9 +36,19 @@ DEFINE_MTYPE(LIB, PREFIX_FLOWSPEC, "Prefix Flowspec")
static inline void mt_count_alloc(struct memtype *mt, size_t size, void *ptr)
{
+ size_t current;
size_t oldsize;
- atomic_fetch_add_explicit(&mt->n_alloc, 1, memory_order_relaxed);
+ current = atomic_add_fetch_explicit(&mt->n_alloc, 1,
+ memory_order_relaxed);
+
+ oldsize = atomic_load_explicit(&mt->n_max, memory_order_relaxed);
+ if (current > oldsize)
+ /* note that this may fail, but approximation is sufficient */
+ atomic_compare_exchange_weak_explicit(&mt->n_max, &oldsize,
+ current,
+ memory_order_relaxed,
+ memory_order_relaxed);
oldsize = atomic_load_explicit(&mt->size, memory_order_relaxed);
if (oldsize == 0)
@@ -51,7 +61,15 @@ static inline void mt_count_alloc(struct memtype *mt, size_t size, void *ptr)
#ifdef HAVE_MALLOC_USABLE_SIZE
size_t mallocsz = malloc_usable_size(ptr);
- atomic_fetch_add_explicit(&mt->total, mallocsz, memory_order_relaxed);
+ current = atomic_add_fetch_explicit(&mt->total, mallocsz,
+ memory_order_relaxed);
+ oldsize = atomic_load_explicit(&mt->max_size, memory_order_relaxed);
+ if (current > oldsize)
+ /* note that this may fail, but approximation is sufficient */
+ atomic_compare_exchange_weak_explicit(&mt->max_size, &oldsize,
+ current,
+ memory_order_relaxed,
+ memory_order_relaxed);
#endif
}