mempool: rework mempool_cleanup() to only release freed tiles

This substantially reworks mempool_cleanup() so that it releases pools
with all freed tiles only, but keeps all pools with still-allocated
tiles around.

This is more correct, as the previous implementation just released all
pools regardless if anything was still used or not. This would make
valgrind shut up but would just hide memory leaks altogether. Moreover
if called during regular runtime of a program would result in bad memory
accesses all over.

Hence, let's add a proper implementation and only trim pools we really
know are empty.

This way we can safely call these functions later, when under memory
pressure, at any time.
This commit is contained in:
Lennart Poettering
2023-02-17 15:03:53 +01:00
parent 4392b983b8
commit a2b052b29f
4 changed files with 92 additions and 12 deletions
+1 -1
View File
@@ -444,4 +444,4 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(IteratedCache*, iterated_cache_free);
#define _cleanup_iterated_cache_free_ _cleanup_(iterated_cache_freep)
void hashmap_cleanup_pools(void);
void hashmap_trim_pools(void);