mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] malloc/expand_heap.c: really try to use all available memory
Date: Tue, 18 Jul 2017 13:27:54 -0400	[thread overview]
Message-ID: <20170718172754.GR1627@brightrain.aerifal.cx> (raw)
In-Reply-To: <20170718125259.19932-1-stevenrwalter@gmail.com>

On Tue, Jul 18, 2017 at 08:52:59AM -0400, Steven Walter wrote:
> Previously expand_heap would ask for increasingly larger mmap areas
> every time, in order to avoid allocating a bunch of small areas and
> fragmenting memory.  However, after a point, we may ask for an mmap area
> so large that it can't possibly succeed, even though there is still
> system memory available.  This is particularly likely on a 32-bit system
> with gigs of RAM, or else on a no-MMU system with pretty much any amount
> of RAM.  Without an MMU to make physically-discontiguous pages appear
> contigious, the chance of any large mmap succeeding are very low.

This is partly intentional, since beyond this point fragmentation is
expected to be catastrophic to the point that it would prevent mmap
(and on nommu, bring down the whole system). But if it's seriously
capping how much memory you can get with malloc on a 32-bit system
(esp one with mmu), some tweaking is probably needed.

> To fix this, support decreasing mmap_step once we hit an allocation
> failure.  We'll try smaller and smaller amounts until we either ask for
> a single page or exactly as many pages as we currently need.  Only if
> that fails do we fail the overall request.

This is probably a really bad idea, though I don't have data to back
that up; it's just an intuition about what happens. Would it work to
instead decrease the growth rate on requests? If you're at the point
where a single page (or a few pages) makes the difference between
success and failure, it's already highly unpredictable (due to aslr &
other memory layout factors) whether your job is going to succeed
either way. If you get in a situation where there are hundreds of megs
free but you can't use them, that's a real problem, but I think it's
one we can solve without dropping down to small requests.

Note that there's also a bad fragmentation behavior from your proposal
if a large expand_heap is only temporarily blocked, e.g. by a
short-lived mmap. In that case, dropping down to smaller requests will
just fragment memory horribly so that subsequent requests (after the
mmap is released) will fail even worse.

Rich


      reply	other threads:[~2017-07-18 17:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-18 12:52 Steven Walter
2017-07-18 17:27 ` Rich Felker [this message]

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=20170718172754.GR1627@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).