diff mbox series

[ovs-dev,v2,08/10] lflow-cache: Reclaim heap memory after cache flush.

Message ID 20210204132610.9958.16465.stgit@dceara.remote.csb
State Changes Requested
Headers show
Series ovn-controller: Make lflow cache size configurable. | expand

Commit Message

Dumitru Ceara Feb. 4, 2021, 1:26 p.m. UTC
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.

Signed-off-by: Dumitru Ceara <dceara@redhat.com>
---
 configure.ac             |    1 +
 controller/lflow-cache.c |    9 +++++++++
 2 files changed, 10 insertions(+)

Comments

Numan Siddique Feb. 9, 2021, 6 a.m. UTC | #1
On Thu, Feb 4, 2021 at 6:57 PM Dumitru Ceara <dceara@redhat.com> wrote:
>
> 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.
>
> Signed-off-by: Dumitru Ceara <dceara@redhat.com>

Acked-by: Numan Siddique <numans@ovn.org>

Numan
> ---
>  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 1549034..2453b10 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 "lib/ovn-sb-idl.h"
>  #include "lflow-cache.h"
> @@ -87,7 +91,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
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
diff mbox series

Patch

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 1549034..2453b10 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 "lib/ovn-sb-idl.h"
 #include "lflow-cache.h"
@@ -87,7 +91,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