summaryrefslogtreecommitdiff
path: root/lib/memory.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2018-08-30 16:44:47 +0200
committerGitHub <noreply@github.com>2018-08-30 16:44:47 +0200
commit66a9aa8b8860d8c79d8b395eb22ccddcdebf69e6 (patch)
tree87acadf7aab4ff94d153bdb9b47cd807f733442b /lib/memory.c
parentf177317a20ff417c2dc9d719f2e1135d81ff96f8 (diff)
parent7a153339b2ea6b9cdef3f9ce2113e27f417c6fab (diff)
Merge pull request #2859 from LabNConsulting/working/master/meminfo
lib: qmem show changes (header and max)
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..695bbfe115 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 = 1 + atomic_fetch_add_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 = mallocsz + atomic_fetch_add_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
}