From: Shannon Zhao <zhaoshenglong@huawei.com>
To: Yang Zhong <yang.zhong@intel.com>, qemu-devel@nongnu.org
Cc: zhang.zhanghailiang@huawei.com, liujunjie23@huawei.com,
wangxinxin.wang@huawei.com, stone.xulei@huawei.com,
arei.gonglei@huawei.com, stefanha@redhat.com,
pbonzini@redhat.com, weidong.huang@huawei.com
Subject: Re: [Qemu-devel] [PATCH v3] rcu: reduce more than 7MB heap memory by malloc_trim()
Date: Sun, 26 Nov 2017 14:17:18 +0800 [thread overview]
Message-ID: <5A1A5C6E.9060409@huawei.com> (raw)
In-Reply-To: <1511505030-3669-1-git-send-email-yang.zhong@intel.com>
Hi,
On 2017/11/24 14:30, Yang Zhong wrote:
> 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 | 29 +++++++++++++++++++++++++++++
> util/rcu.c | 6 ++++++
> 2 files changed, 35 insertions(+)
>
> diff --git a/configure b/configure
> index 0c6e757..6292ab0 100755
> --- a/configure
> +++ b/configure
> @@ -426,6 +426,7 @@ vxhs=""
> supported_cpu="no"
> supported_os="no"
> bogus_os="no"
> +malloc_trim="yes"
>
> # parse CC options first
> for opt do
> @@ -3857,6 +3858,30 @@ if test "$tcmalloc" = "yes" && test "$jemalloc" = "yes" ; then
> exit 1
> fi
>
> +# Even if malloc_trim() is available, these non-libc memory allocators
> +# do not support it.
> +if test "$tcmalloc" = "yes" || test "$jemalloc" = "yes" ; then
> + if test "$malloc_trim" = "yes" ; then
> + echo "Disabling malloc_trim with non-libc memory allocator"
> + fi
> + malloc_trim="no"
> +fi
> +
> +#######################################
> +# malloc_trim
> +
> +if test "$malloc_trim" != "no" ; then
> + cat > $TMPC << EOF
> +#include <malloc.h>
> +int main(void) { malloc_trim(0); return 0; }
> +EOF
> + if compile_prog "" "" ; then
> + malloc_trim="yes"
> + else
> + malloc_trim="no"
> + fi
> +fi
> +
> ##########################################
> # tcmalloc probe
>
> @@ -6012,6 +6037,10 @@ if test "$opengl" = "yes" ; then
> fi
> fi
>
> +if test "$malloc_trim" = "yes" ; then
> + echo "CONFIG_MALLOC_TRIM=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..f403b77 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_MALLOC_TRIM)
> +#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_MALLOC_TRIM)
> + malloc_trim(4 * 1024 * 1024);
> +#endif
> }
> abort();
> }
>
Looks like this patch introduces a performance regression. With this
patch the time of booting a VM with 60 scsi disks on ARM64 is increased
by 200+ seconds.
Thanks,
--
Shannon
next prev parent reply other threads:[~2017-11-26 7:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-24 6:30 [Qemu-devel] [PATCH v3] rcu: reduce more than 7MB heap memory by malloc_trim() Yang Zhong
2017-11-24 11:27 ` Stefan Hajnoczi
2017-11-26 6:17 ` Shannon Zhao [this message]
2017-11-27 3:06 ` Zhong Yang
2017-11-27 11:59 ` Paolo Bonzini
[not found] ` <20171201105622.GB26237@yangzhon-Virtual>
[not found] ` <74cccd14-e485-90d4-82d9-03355c05faca@redhat.com>
2017-12-04 12:03 ` Yang Zhong
2017-12-04 12:07 ` Daniel P. Berrange
2017-12-04 12:16 ` Yang Zhong
2017-12-04 12:18 ` Paolo Bonzini
2017-12-04 12:26 ` Shannon Zhao
2017-12-05 6:00 ` Yang Zhong
2017-12-05 14:10 ` Paolo Bonzini
2017-12-06 9:26 ` Yang Zhong
2017-12-06 9:48 ` Paolo Bonzini
2017-12-07 15:06 ` Yang Zhong
2017-12-11 16:31 ` Paolo Bonzini
2017-12-12 6:54 ` Yang Zhong
2017-12-12 7:09 ` Shannon Zhao
2017-12-18 7:17 ` Shannon Zhao
2017-12-18 7:51 ` Yang Zhong
2017-12-19 12:57 ` Paolo Bonzini
2017-12-08 11:06 ` 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=5A1A5C6E.9060409@huawei.com \
--to=zhaoshenglong@huawei.com \
--cc=arei.gonglei@huawei.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=yang.zhong@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.