If possible, automatically reclaim heap memory when the lflow cache is flushed. This can be an expensive operation but cache flushing is not a very common operation.
This change is inspired by Ilya Maximets' OVS commit: f38f98a2c0dd ("ovsdb-server: Reclaim heap memory after compaction.") Additionally, when flushing the cache, also shrink the backing hmap. Acked-by: Mark Michelson <mmich...@redhat.com> Acked-by: Numan Siddique <num...@ovn.org> Signed-off-by: Dumitru Ceara <dce...@redhat.com> --- configure.ac | 1 + controller/lflow-cache.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/configure.ac b/configure.ac index b2d0843..ebb09a5 100644 --- a/configure.ac +++ b/configure.ac @@ -96,6 +96,7 @@ OVN_CHECK_DOT OVS_CHECK_IF_DL OVS_CHECK_STRTOK_R AC_CHECK_DECLS([sys_siglist], [], [], [[#include <signal.h>]]) +AC_CHECK_DECLS([malloc_trim], [], [], [[#include <malloc.h>]]) AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec, struct stat.st_mtimensec], [], [], [[#include <sys/stat.h>]]) AC_CHECK_MEMBERS([struct ifreq.ifr_flagshigh], [], [], [[#include <net/if.h>]]) diff --git a/controller/lflow-cache.c b/controller/lflow-cache.c index be764d5..403aed4 100644 --- a/controller/lflow-cache.c +++ b/controller/lflow-cache.c @@ -17,6 +17,10 @@ #include <config.h> +#if HAVE_DECL_MALLOC_TRIM +#include <malloc.h> +#endif + #include "coverage.h" #include "lflow-cache.h" #include "lib/uuid.h" @@ -86,7 +90,12 @@ lflow_cache_flush(struct lflow_cache *lc) HMAP_FOR_EACH_SAFE (lce, lce_next, node, &lc->entries[i]) { lflow_cache_delete__(lc, lce); } + hmap_shrink(&lc->entries[i]); } + +#if HAVE_DECL_MALLOC_TRIM + malloc_trim(0); +#endif } void _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev