Since there are some issues in memory alloc/free machenism in glibc for little chunk memory, if Qemu frequently alloc/free little chunk memory, the glibc doesn't alloc little chunk memory from free list of glibc and still allocate from OS, which make the heap size bigger and bigger.
This patch introduce malloc_trim(), which will free heap memory. Below are test results from smaps file. 55f0783e1000-55f07992a000 rw-p 00000000 00:00 0 [heap] Size: 21796 kB Rss: 14260 kB Pss: 14260 kB 55cc5fadf000-55cc61008000 rw-p 00000000 00:00 0 [heap] Size: 21668 kB Rss: 6940 kB Pss: 6940 kB Signed-off-by: Yang Zhong <yang.zh...@intel.com> --- util/rcu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/rcu.c b/util/rcu.c index ca5a63e..8d491a6 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -26,6 +26,7 @@ * IBM's contributions to this file may be relicensed under LGPLv2 or later. */ +#include <malloc.h> #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/rcu.h" @@ -272,6 +273,9 @@ static void *call_rcu_thread(void *opaque) node->func(node); } qemu_mutex_unlock_iothread(); +#ifdef CONFIG_LINUX + malloc_trim(0); +#endif } abort(); } -- 1.9.1