From: Yang Zhong <yang.zhong@intel.com>
To: qemu-devel@nongnu.org
Cc: stefanha@redhat.com, berrange@redhat.com, pbonzini@redhat.com,
yang.zhong@intel.com, stone.xulei@huawei.com,
arei.gonglei@huawei.com, wangxinxin.wang@huawei.com,
weidong.huang@huawei.com, zhang.zhanghailiang@huawei.com,
liujunjie23@huawei.com
Subject: [Qemu-devel] [PATCH v2] rcu: reduce more than 7MB heap memory by malloc_trim()
Date: Thu, 23 Nov 2017 14:41:16 +0800 [thread overview]
Message-ID: <1511419276-31212-1-git-send-email-yang.zhong@intel.com> (raw)
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.
(1)without patch
55f0783e1000-55f07992a000 rw-p 00000000 00:00 0 [heap]
Size: 21796 kB
Rss: 14260 kB
Pss: 14260 kB
(2)with patch
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>
---
configure | 4 ++++
util/rcu.c | 6 ++++++
2 files changed, 10 insertions(+)
diff --git a/configure b/configure
index 0e856bb..5b463d4 100755
--- a/configure
+++ b/configure
@@ -6012,6 +6012,10 @@ if test "$opengl" = "yes" ; then
fi
fi
+if test "$tcmalloc" = "yes" || test "$jemalloc" = "yes" ; then
+ echo "CONFIG_NONGLIBMALLOC=y" >> $config_host_mak
+fi
+
if test "$avx2_opt" = "yes" ; then
echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
fi
diff --git a/util/rcu.c b/util/rcu.c
index ca5a63e..f3e96a8 100644
--- a/util/rcu.c
+++ b/util/rcu.c
@@ -32,6 +32,9 @@
#include "qemu/atomic.h"
#include "qemu/thread.h"
#include "qemu/main-loop.h"
+#if defined(CONFIG_LINUX)
+#include <malloc.h>
+#endif
/*
* Global grace period counter. Bit 0 is always one in rcu_gp_ctr.
@@ -272,6 +275,9 @@ static void *call_rcu_thread(void *opaque)
node->func(node);
}
qemu_mutex_unlock_iothread();
+#if defined(CONFIG_LINUX) && !defined(CONFIG_NONGLIBMALLOC)
+ malloc_trim(4 * 1024 * 1024);
+#endif
}
abort();
}
--
1.9.1
next reply other threads:[~2017-11-23 6:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-23 6:41 Yang Zhong [this message]
2017-11-23 11:19 ` [Qemu-devel] [PATCH v2] rcu: reduce more than 7MB heap memory by malloc_trim() Stefan Hajnoczi
2017-11-24 6:29 ` Zhong Yang
2017-12-07 15:33 ` Marc-André Lureau
2017-12-08 5:14 ` Yang Zhong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1511419276-31212-1-git-send-email-yang.zhong@intel.com \
--to=yang.zhong@intel.com \
--cc=arei.gonglei@huawei.com \
--cc=berrange@redhat.com \
--cc=liujunjie23@huawei.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=stone.xulei@huawei.com \
--cc=wangxinxin.wang@huawei.com \
--cc=weidong.huang@huawei.com \
--cc=zhang.zhanghailiang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).