From: Zhong Yang <yang.zhong@intel.com>
To: "Daniel P. Berrange" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, pbonzini@redhat.com, stefanha@redhat.com,
anthony.xu@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: Re: [Qemu-devel] [PATCH] rcu: reduce half heap memory size by malloc_trim()
Date: Mon, 20 Nov 2017 16:54:42 +0800 [thread overview]
Message-ID: <20171120085442.GB6622@yangzhon-Virtual> (raw)
In-Reply-To: <20171117140620.GS25830@redhat.com>
On Fri, Nov 17, 2017 at 02:06:20PM +0000, Daniel P. Berrange wrote:
> On Fri, Nov 17, 2017 at 01:54:09PM +0000, Stefan Hajnoczi wrote:
> > On Fri, Nov 17, 2017 at 02:23:34PM +0800, Yang Zhong wrote:
> > > 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>
> >
> > This header file is not mentioned in the C99 standard or POSIX. It is
> > probably not available on all host OSes that QEMU supports. Please use
> > #ifdef CONFIG_LINUX.
> >
> > > #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
> >
> > It is important that the rcu thread isn't overzealous in minimizing heap
> > size if that means ordinary malloc(3) calls will experience latency
> > spikes. Please leave a few MB free so that malloc(3) doesn't take the
> > slow path.
>
> If you pass '0' the docs say that the minimum amount is left in the
> heap, per M_TOP_PAD, which is 128kb.
>
> Strangely the mallopt(3) man page suggests, that free() should automatically
> trim the heap when its size exceeds M_TOP_TRIM, which is again 128kb by
> default. So I'm puzzelled by malloc_trim() would be needed unless there
> are scenarios in which free() won't trim, that aren't mentioned in the
> manpage.
Hello Daniel,
In fact, i firstly adopted mallopt() solution to optimize the heap memory,
but i found this function is NOT useful, which are difference with MAN's
description, so i had to swith to use malloc_trim().
Regards,
Yang
> Also, how does malloc_trim interact with tcmalloc.so that people often
> use in preference to glibc's built in malloc ?
Thanks, you reminded me to consider tcmalloc or jemalloc.
Whether below code is more suitable? thanks!
#if defined(CONFIG_LINUX) && defined(__GLIBC__)
malloc_trim(0);
#endif
Regards,
Yang
>
> Regards,
> Daniel
> --
> |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o- https://fstop138.berrange.com :|
> |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2017-11-20 8:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=20171120085442.GB6622@yangzhon-Virtual \
--to=yang.zhong@intel.com \
--cc=anthony.xu@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).