From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Guoyi Tu <tugy@chinatelecom.cn>
Cc: Markus Armbruster <armbru@redhat.com>,
"Dr. David Alan Gilbert" <dave@treblig.org>,
Eric Blake <eblake@redhat.com>,
qemu-devel@nongnu.org, dengpc12@chinatelecom.cn,
zhangl161@chinatelecom.cn, Paolo Bonzini <pbonzini@redhat.com>,
Yang Zhong <yang.zhong@intel.com>
Subject: Re: [PATCH] misc: introduce strim-memory qapi to support free memory trimming
Date: Thu, 1 Aug 2024 14:12:31 +0100 [thread overview]
Message-ID: <ZquJv9ZwzPX0hIj6@redhat.com> (raw)
In-Reply-To: <80321ce6-1596-460d-b4e1-622a0b69f8e1@chinatelecom.cn>
On Sat, Jul 27, 2024 at 01:18:32PM +0800, Guoyi Tu wrote:
> On 2024/7/25 19:57, Daniel P. Berrangé wrote:
> > On Thu, Jul 25, 2024 at 01:35:21PM +0200, Markus Armbruster wrote:
> > > Guoyi Tu <tugy@chinatelecom.cn> writes:
> > >
> > > > In the test environment, we conducted IO stress tests on all storage disks
> > > > within a virtual machine that had five storage devices mounted.During
> > > > testing,
> > > > we found that the qemu process allocated a large amount of memory (~800MB)
> > > > to handle these IO operations.
> > > >
> > > > When the test ended, although qemu called free() to release the allocated
> > > > memory, the memory was not actually returned to the operating system, as
> > > > observed via the top command.
> > > >
> > > > Upon researching the glibc memory management mechanism, we found that when
> > > > small chunks of memory are allocated in user space and then released with
> > > > free(), the glibc memory management mechanism does not necessarily return
> > > > this memory to the operating system. Instead, it retains the memory until
> > > > certain conditions are met for release.
> > >
> > > Yes.
> >
> > Looking at mallopt(3) man page, the M_TRIM_THRESHOLD is said to control
> > when glibc releases the top of the heap back to the OS. It is said to
> > default to 128 kb.
> Yes, the M_TRIM_THRESHOLD option can control glibc to release the free
> memory at the top of the heap, but glibc will not release the free
> memory in the middle of the heap.
>
> > I'm curious how we get from that default, to 800 MB of unused memory > Is it related to the number of distinct malloc arenas that are in use ?
>
> At least 600MB of memory is free, and this memory might be in the middle of
> the heap and cannot be automatically released.
>
> > I'm curious what malloc_stats() would report before & after malloc_trim
> > when QEMU is in this situation with lots of wasted memory.
> Here is the test case:
snip
That looks like an artifical reproducer, rather than the real world
QEMU scenario.
What's the actual I/O stress test scenario you use to reproduce the
problem in QEMU, and how have you configured QEMU (ie what CLI args) ?
I'm fairly inclined to suggest that having such a huge amount of
freed memory is a glibc bug, but to escalate this to glibc requires
us to provide them better real world examples of the problems.
> > The above usage is automatic, while this proposal requires that
> > an external mgmt app monitor QEMU and tell it to free memory.
> > I'm wondering if the latter is really desirable, or whether QEMU
> > can call this itself when reasonable ?
>
> Yes, I have also considered implementing an automatic memory release
> function within qemu. This approach would require qemu to periodically
> monitor the IO load of all backend storage, and if the IO load is very
> low over a period of time, it would proactively release memory.
I would note that in systemd they have logic which is monitoring
either /proc/pressure/memory or $CGROUP/memory.pressure, and in
response to events on that, it will call malloc_trim
https://github.com/systemd/systemd/blob/main/docs/MEMORY_PRESSURE.md
https://docs.kernel.org/accounting/psi.html
Something like that might be better, as it lets us hide the specific
design & impl choices inside QEMU, letting us change/evolve them at
will without impacting public API designs.
With 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:[~2024-08-01 13:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-28 10:22 [PATCH] misc: introduce strim-memory qapi to support free memory trimming Guoyi Tu
2024-07-07 3:48 ` Guoyi Tu
2024-07-25 11:35 ` Markus Armbruster
2024-07-25 11:57 ` Daniel P. Berrangé
2024-07-25 12:50 ` Dr. David Alan Gilbert
2024-07-27 5:18 ` Guoyi Tu
2024-08-01 13:12 ` Daniel P. Berrangé [this message]
[not found] ` <1020253492.3796.1721956050910.JavaMail.root@jt-retransmission-dep-7c968f646d-qxbl2>
2024-07-27 5:25 ` Guoyi Tu
2024-07-27 4:09 ` Guoyi Tu
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=ZquJv9ZwzPX0hIj6@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=dave@treblig.org \
--cc=dengpc12@chinatelecom.cn \
--cc=eblake@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=tugy@chinatelecom.cn \
--cc=yang.zhong@intel.com \
--cc=zhangl161@chinatelecom.cn \
/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).