qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] rcu: reduce half heap memory size by malloc_trim()
@ 2017-11-17  6:23 Yang Zhong
  2017-11-17 13:54 ` Stefan Hajnoczi
  2017-11-20 14:28 ` Fam Zheng
  0 siblings, 2 replies; 11+ messages in thread
From: Yang Zhong @ 2017-11-17  6:23 UTC (permalink / raw)
  To: qemu-devel, pbonzini
  Cc: stefanha, anthony.xu, yang.zhong, stone.xulei, arei.gonglei,
	wangxinxin.wang, weidong.huang, zhang.zhanghailiang, liujunjie23

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.zhong@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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-11-21  5:46 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-17  6:23 [Qemu-devel] [PATCH] rcu: reduce half heap memory size by malloc_trim() Yang Zhong
2017-11-17 13:54 ` Stefan Hajnoczi
2017-11-17 14:06   ` Daniel P. Berrange
2017-11-20  8:54     ` Zhong Yang
2017-11-20 14:14       ` Daniel P. Berrange
2017-11-21  5:46         ` Zhong Yang
2017-11-20  8:41   ` Zhong Yang
2017-11-20 14:03     ` Stefan Hajnoczi
2017-11-21  3:20       ` Zhong Yang
2017-11-20 14:28 ` Fam Zheng
2017-11-21  3:12   ` Zhong Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).