]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: activity/memprofile: offer a function to unregister stale info
authorWilly Tarreau <w@1wt.eu>
Thu, 21 Nov 2024 10:27:52 +0000 (11:27 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 21 Nov 2024 18:58:06 +0000 (19:58 +0100)
There's actually a problem with memprofiles: the pool pointer is stored
in ->info but some pools are replaced during startup, such as the trash
pool, leaving a dangling pointer there.

Let's complete the API with a new function memprof_remove_stale_info()
that will remove all stale references to this info pointer. It's also
present when USE_MEMORY_PROFILING is not set so as to ease the job on
callers.

include/haproxy/activity.h
src/activity.c

index dbc8ec3a83d2f9e44e11da920a923a7c3a89c9c2..e6cb09bbf19bbfdbdfc3485c604b09e23c410a60 100644 (file)
@@ -35,6 +35,12 @@ struct sched_activity *sched_activity_entry(struct sched_activity *array, const
 
 #ifdef USE_MEMORY_PROFILING
 struct memprof_stats *memprof_get_bin(const void *ra, enum memprof_method meth);
+void memprof_remove_stale_info(const void *info);
+#else
+static inline void memprof_remove_stale_info(const void *info)
+{
+       /* nothing to do */
+}
 #endif
 
 #endif /* _HAPROXY_ACTIVITY_H */
index d65508856f240d858a38a598e96eaa1a1e74d283..b6939d9d54fdfcf0b0b1df4d63a95379e28b193a 100644 (file)
@@ -324,6 +324,23 @@ void free(void *ptr)
        _HA_ATOMIC_ADD(&bin->free_tot, size_before);
 }
 
+/* remove info from entries matching <info>. This needs to be used by callers
+ * of pool_destroy() so that we don't keep a reference to a dead pool. Nothing
+ * is done if <info> is NULL.
+ */
+void memprof_remove_stale_info(const void *info)
+{
+       int i;
+
+       if (!info)
+               return;
+
+       for (i = 0; i < MEMPROF_HASH_BUCKETS; i++) {
+               if (_HA_ATOMIC_LOAD(&memprof_stats[i].info) == info)
+                       _HA_ATOMIC_STORE(&memprof_stats[i].info, NULL);
+       }
+}
+
 #endif // USE_MEMORY_PROFILING
 
 /* Updates the current thread's statistics about stolen CPU time. The unit for