public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Steve Vormwald <sdvormwa@cray.com>
To: Florian Weimer <fweimer@redhat.com>,
	Joseph Myers <joseph@codesourcery.com>
Cc: "libc-alpha@sourceware.org" <libc-alpha@sourceware.org>
Subject: Re: [PATCH] malloc: Deprecate hook variables, __default_morecore, <mcheck.h>
Date: Fri, 18 Nov 2016 17:29:00 -0000	[thread overview]
Message-ID: <DM5PR11MB1531F4EF20DDAA6F8DC35DA7BBB00@DM5PR11MB1531.namprd11.prod.outlook.com> (raw)
In-Reply-To: <915065cd-079b-0f7b-eebf-7ca835ca4030@redhat.com>

> On 11/18/2016 04:13 AM, Florian Weimer wrote:
> I've been considering for a while to remove the use of sbrk from the
> allocator, both to simplify it and to take away the possibility for
> attacks to tweak the NON_MAIN_ARENA flag to trick the allocator into
> doing something bad.  Some embedded targets appear to strongly prefer
> the sbrk as well, so maybe this approach is doomed.

For us anyway, the use of sbrk isn't as important as its semantics (eg,
heap is contiguous in virtual address space and only grows/shrinks on
one end).  Thus, things like libhugetlbfs that provide the same semantics
via __morecore work just as well.

> Would your configuration have problems if we handed all allocations
> which are larger than 1 MiB or so straight to mmap?

That would probably not work out for us.  The underlying problem we have
is that unmapping pages can be extremely expensive (on the order of tens
of seconds or worse in certain circumstances).  We use segments with
fixed base addresses and maximum length to transparently make portions
of a process's virtual address space (notably including all user allocations)
available for hardware DMA.  Updating page mappings within a segment is
extremely cheap.  Adding a new segment is also relatively cheap, but they
are a limited resource.  Invalidating a segment so it can be reused can get
very expensive since everything that has used it needs to be notified of the
invalidation.  We can take a fast path if the allocator has sbrk-like semantics
as described above because we know it only requires updating page
mappings, assuming the existing segment is large enough.  We have to be
much more conservative for allocations that are satisfied with mmap,
leading to a lot of expensive and potentially unnecessary segment creation
and invalidation.

> We would also be interested in general patterns of fragmentation you
> have encountered, if any.  Maybe there's something we can do about them.

The usual culprit is something "caching" small (<128byte) allocations for
future reuse rather than freeing them when they become unused, which
prevents the allocator from coalescing free regions to satisfy larger allocations.
Changing the code either to allocate in bulk instead of one object at a time or
to simply free them without caching is generally sufficient to fix the
fragmentation issue.

Steven Vormwald

  reply	other threads:[~2016-11-18 17:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-26 15:02 Florian Weimer
2016-10-26 15:55 ` Joseph Myers
2016-11-15 13:22   ` Florian Weimer
2016-11-15 15:39     ` Joseph Myers
2016-11-15 15:56       ` Florian Weimer
2016-11-16  1:37         ` Joseph Myers
2016-11-16  9:46           ` Will Newton
2016-11-17 13:00           ` Florian Weimer
2016-11-17 14:27             ` Joseph Myers
2016-11-17 14:50             ` Steve Vormwald
2016-11-17 16:08               ` Adhemerval Zanella
2016-11-18  9:13               ` Florian Weimer
2016-11-18 17:29                 ` Steve Vormwald [this message]
2016-11-21 19:43                   ` DJ Delorie
2016-11-22 15:12 ` Florian Weimer

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=DM5PR11MB1531F4EF20DDAA6F8DC35DA7BBB00@DM5PR11MB1531.namprd11.prod.outlook.com \
    --to=sdvormwa@cray.com \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    /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).