public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Konstantin Kharlamov <hi-angel@yandex.ru>
To: tomas@tuxteam.de
Cc: libc-help@sourceware.org
Subject: Re: `free` fails to reclaim memory
Date: Tue, 22 Dec 2020 01:59:46 +0300	[thread overview]
Message-ID: <453d41b6d3f13dac758eee840a2d5693ac032bbb.camel@yandex.ru> (raw)
In-Reply-To: <20201213123241.GC30670@tuxteam.de>

On Sun, 2020-12-13 at 13:32 +0100, tomas@tuxteam.de wrote:
> On Sun, Dec 13, 2020 at 03:14:39PM +0300, Konstantin Kharlamov wrote:
>
> [...]
>
> > Thanks, I might look at tunables, but I'd also like to point out that this
> > doesn't make it less of a glibc problem. Because you can't expect everyone
> > to
> > tune app up specifically for glibc. There're various libc libs on different
> > platforms, and it would take a lot of effort from developers to tune an app
> > for
> > every existing libc out there.
>
> That's right. On the other hand, what we are seeing as the "libc defaults"
> is most probably the result of a compromise. The library has to behave
> sanely for a wide range of malloc/free behaviours. Returning space to the
> OS for every 16 byte free will quickly become prohibitive (it involves
> a syscall, after all).
>
> I don't think the libc authors will see that as a bug.

For these usecases Glibc already has a per-thread malloc cache, to which, if I correctly understand, the discussed behavior is irrelevant. It's just failure of libc to figure out it conserved too much memory, and that it needs to free some up.

So, I see no reason why it would not be considered a bug. Either way, since this discussion doesn't seem to be too popular, I just went ahead and reported it: https://sourceware.org/bugzilla/show_bug.cgi?id=27103

> If the generic behaviour doesn't fit your application's usage pattern,
> that's what the tunables are for. Or the explicit call to malloc_trim.
>
> In most applications, you'll be calling malloc and free in some interleaved
> pattern, so the virtual size will stabilise at some point corresponding
> to the maximum used space. In those cases, it seems a "good thing" that
> this space isn't returned to the OS "too early" -- that would slow down
> memory management.
>
> That's what one should see in the Emacs case, I think.

Well, in my case it won't stabilize. The usecase is that I disabled memory-threshold for Emacs garbage-collector (for performance reasons), and instead I hooked-up running GC to idle time.

Now, there can easily appear short-burst workloads which would allocate lots of memory before GC gets a chance to run. And then what? The memory Emacs just took will hardly be used again, but glibc isn't gonna return memory either.



  reply	other threads:[~2020-12-21 22:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <dd4a240ab3ff14d8f04d02b2504611a4d9f3f816.camel@yandex.ru>
     [not found] ` <83k0tmeq6f.fsf@gnu.org>
     [not found]   ` <9f49e5542f303736d2e53ce3dc53c1374969e6b4.camel@yandex.ru>
     [not found]     ` <E1koKKT-0007bp-7N@fencepost.gnu.org>
2020-12-13 11:41       ` Konstantin Kharlamov
2020-12-13 11:57         ` tomas
2020-12-13 12:14           ` Konstantin Kharlamov
2020-12-13 12:32             ` tomas
2020-12-21 22:59               ` Konstantin Kharlamov [this message]
2020-12-13 12:33           ` Konstantin Kharlamov
2020-12-13 12:42             ` tomas
2020-12-21 23:18               ` Konstantin Kharlamov

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=453d41b6d3f13dac758eee840a2d5693ac032bbb.camel@yandex.ru \
    --to=hi-angel@yandex.ru \
    --cc=libc-help@sourceware.org \
    --cc=tomas@tuxteam.de \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).