mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: What's wrong with musl's malloc
Date: Sat, 21 Apr 2018 01:52:36 -0400	[thread overview]
Message-ID: <20180421055236.GV3094@brightrain.aerifal.cx> (raw)
In-Reply-To: <20180421052812.GU3094@brightrain.aerifal.cx>

On Sat, Apr 21, 2018 at 01:28:12AM -0400, Rich Felker wrote:
> One protocol that might work:
> 
> When locking multiple bins, they must be locked in decreasing order.
> 
> For malloc, this is the natural thing to do -- the bin you return the
> excess to will be the same or smaller than the bin you allocate from.
> 
> For free, take the freelock from the beginning, rather than just
> momentarily at the end. Then you know the bin sizes you'll be working
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> with (up to at most 3 -- self, prev, and next) and can lock them in
  ^^^^^^^^^^^^^^^^^^^^^

I don't think this is actually quite correct. A concurrent malloc
could consume part of either of the adjacent free chunks. It's okay if
it consumes the whole thing, but if it only consumes part, you'll end
up with a new adjacent free chunk of a different size (different bin).

Of course loop-and-retry is an option but doesn't seem like a good
one; the retry time could be unbounded.

Not sure if this is salvagable or not. Problems like this keep
pointing in the direction of wanting to lock chunks (via their
header/footer) rather than locking just bins. On the plus side it's
much finer-grained locking and MT-friendly. Unfortunately it's also
more complex and might have more fixed overhead.

Rich


  reply	other threads:[~2018-04-21  5:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-20 20:09 Rich Felker
2018-04-21  5:28 ` Rich Felker
2018-04-21  5:52   ` Rich Felker [this message]
2018-04-22 19:34 ` Markus Wichmann
2018-04-23  2:00   ` Rich Felker
2018-04-23 19:02     ` Markus Wichmann
2018-04-23 19:47       ` Rich Felker
2018-04-23  6:50   ` A. Wilcox
2018-04-23 16:43     ` Rich Felker
2018-04-22 21:40 ` Michael Clark
2018-04-23  2:09   ` Rich Felker
2018-04-23  2:51   ` musl riscv port Rich Felker

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=20180421055236.GV3094@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).