From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14359 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Markus Wichmann Newsgroups: gmane.linux.lib.musl.general Subject: Re: malloc() alignment and max_align_t Date: Sun, 7 Jul 2019 21:22:00 +0200 Message-ID: <20190707192200.GA2684@voyager> References: <1561802993.8028.ezmlm@lists.openwall.com> <8c2d963e-1fcf-df2e-2a52-614f0250b594@gmch.uk> <20425c39-b411-b9bb-1e83-bf26dbcd7d4d@adelielinux.org> <20190629135859.GA21055@port70.net> <7dfceb33-b903-de2a-7abe-825f44512f0c@gmch.uk> <6b44b4a2-0047-6304-8c86-058236dc1c74@gmch.uk> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="99273"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) To: musl@lists.openwall.com Original-X-From: musl-return-14375-gllmg-musl=m.gmane.org@lists.openwall.com Sun Jul 07 21:22:26 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1hkCjt-000Pbj-SE for gllmg-musl@m.gmane.org; Sun, 07 Jul 2019 21:22:21 +0200 Original-Received: (qmail 23742 invoked by uid 550); 7 Jul 2019 19:22:14 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 23717 invoked from network); 7 Jul 2019 19:22:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1562527322; bh=YipJ61l37eb7GbIqkcznSNahmombgOPvuA5wcFsHgPo=; h=X-UI-Sender-Class:Date:From:To:Subject:References:In-Reply-To; b=I6TYF8P1QDXVstTpN7I/ls40E1J3Gu4hhynkHLXrfzfWopTgNU+BB3bRxUK3OvSki Cld6HwqorKPrJ7ueVYEbdL4u4FErcM2MDQfoCb/rZ8UBBGzuyVzI5dpwOWI9+g63PR JBbHvvl2Ww3zoTDoRRlNmDaraBAHrw2CxeEn5ziE= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Content-Disposition: inline In-Reply-To: <6b44b4a2-0047-6304-8c86-058236dc1c74@gmch.uk> X-Provags-ID: V03:K1:oY7o9U629AzfzSGIiMt/+iAcEZ3N4puyYFE/YopfZLJ4cLUC8h2 6rSA43th9YPB1dkzeus1zwOd1VKYtJVvGqINjzB6le7ds0Lro+1Uz1bBe61mCVyqaq2sK06 22FupH6TT2vy9EogHQw3lChmLD3rsq2TNUvGKjAx36AA7JyBf1lCo2eOvl8CW5jrYq4xaeP mxmAOjyEssC8FJIY8dhZA== X-UI-Out-Filterresults: notjunk:1;V03:K0:itfcxJP/lAE=:QQyyAhaQierk7QDFq0Flf4 o5T5CgFtVkgk3IXlkDwhYJ9cok474Xljww1OH3wdhhlXWxYOar+1Nuj/9xu6kQP6SWomrV+Y2 S4qUptmTV6o+j0W8XqCsJNDz1j9rw1euc1Gg1Dp4vSue01tb1HccwrpZ8m809lV8cKBKY/ds9 01Gjh5TbL/xD4ztHbYBcvrp2raU+AeCy7NMqNpSLQkLr7iceYCLs8ZVBw6avJuwEzZCyA6wIH Qq8BwfR2fWbkspn08UqfYAkFJPyYdVUQfAgfNdLqraHtRwhX4AFqjHnwZzTRxnswnyjxPAZ35 Xuq2vnlmgTNb7WO16ScKyyJFAi3rlhC3gic3rnaInBIO2XEWE/6y//CL22HSLLSTRB+s7T3bI IrjLSoeFQ7MD6ojN1GdQrR3jCu1h7tBJwLO4yW3sKuiY6fUg51nD5Nn0Cd4cvUHfV9/PkhEwu vt6vw48RtCqTMxmGOcBJUqBQF+BVDMLwBzLQ0otFZbyEopsXzWL6/jOgxMZcpIGudDnNO8m1K YGSNoE8kzpo2qowOvmrYXCE11fGhdXz3UmACyP++QmvXsn8WLiD6KUf8GMAAjtcWlSZ94b/23 Nvh/HJ4cvgNyphQ1m/zXsMKpMlQ2jy6ZstnomwQTngId8Wq0bb1OnOp6lnvGAFVON893wZkPq 5Tz0lNOlE5S6w6Q4usEe8JONwHmVzO15UKlR021K31eMlnnEHclq+7tI5K9rhg1nsitWsWiUc J6OpGoVYRtFSavHJQHZp507I0iWPW/x3R1me86LF0ax0U88wHPUByEL9K1W2uNd18fbkCrpv Xref: news.gmane.org gmane.linux.lib.musl.general:14359 Archived-At: 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