mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: malloc() alignment and max_align_t
Date: Sun, 7 Jul 2019 21:22:00 +0200	[thread overview]
Message-ID: <20190707192200.GA2684@voyager> (raw)
In-Reply-To: <6b44b4a2-0047-6304-8c86-058236dc1c74@gmch.uk>

On Sun, Jul 07, 2019 at 07:17:48PM +0100, Chris Hall wrote:
> Clearly, C11 does not require malloc() to align exactly as max_align_t, and
> bigger is fine.
>
> But I'm curious as to why SIZE_ALIGN is twice as big as it needs to be ?
>

Design decision. For the algorithm to work, every chunk needs to be able
to contain four machine words (one struct chunk). And with a bit of
maneuvering, this alignment can just be achieved on all chunks with
minimal waste (if a completely new region is allocated in expand_heap(),
then two machine words at the start of it are wasted, but if the new
memory happens to be directly behind the previous section, no waste
occurs at all).

This makes it easier to reason about chunk sizes. Right now, SIZE_ALIGN
and minimum chunk size (after adding OVERHEAD) are the same. If we
lowered the alignment to two machine words, that would change.

> Thanks,
>
> Chris

Ciao,
Markus


  reply	other threads:[~2019-07-07 19:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1561802993.8028.ezmlm@lists.openwall.com>
2019-06-29 11:48 ` Detecting musl at compile and/or configure time Chris Hall
2019-06-29 13:27   ` A. Wilcox
2019-06-29 13:58     ` Szabolcs Nagy
2019-06-30 11:48       ` Chris Hall
2019-07-07 18:17         ` malloc() alignment and max_align_t Chris Hall
2019-07-07 19:22           ` Markus Wichmann [this message]
2019-07-08  0:16             ` 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=20190707192200.GA2684@voyager \
    --to=nullplan@gmx.net \
    --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).