public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: Szabolcs Nagy <Szabolcs.Nagy@arm.com>, "dj@redhat.com" <dj@redhat.com>
Cc: 'GNU C Library' <libc-alpha@sourceware.org>
Subject: [PATCH 00/16] memory tagging improvements
Date: Fri, 5 Mar 2021 21:36:46 +0000	[thread overview]
Message-ID: <VE1PR08MB5599E15BF7D9237DA52E9A1083969@VE1PR08MB5599.eurprd08.prod.outlook.com> (raw)

Hi,

> - request2size and checked_request2size are not consistent which looks
>   wrong (likely works in practice other than some sizes don't end up in
>   fastbin or tcache that one might expected to, but i think this can
>   break easily). Fixing it is not obvious because of assumptions about
>   the chunk layout that is no longer true with mtag enabled.

It's better to change request2size to round up differently if tagging is
required. That avoids dynamically changing how chunks are rounded up.

> Other possible optimizations:
> - ifunc malloc apis
>   good: near zero overhead for runtime dispatch.
>   bad: malloc has to be built twice or larger refactoring is needed.

Using ifuncs is a good idea for the future - it allows removing the old
hooks and other terrible hacks like DUMPED_MAIN_ARENA_CHUNK.
Also it allows more modern malloc implementations to be added while
keeping backwards compatibility if needed (for eg. emacs).

> - unconditional top byte zero
>   internal data is tagged 0, only user allocation is tagged non-zero

That's a great idea! Many chunk2mem can be changed into chunk2rawmem
approximately halving the overhead. And mem2chunk can unconditionally mask
out the tag (note all this could be made target-dependent if needed).

> - unconditional layout
>   padding up to tag granule can be done unconditionally
>   good: no runtime check, same layout with and without heap tagging.
>   bad: wasting space with small allocations, design change.

This is unconditionally good for performance and avoids the request2size oddities.
If we're worried about memory usage, we need to talk about modern malloc
implementations that don't add a 16-byte header to every block.

> Benchmarked using bench-malloc-thread glibc ubenchmark on Neoverse N1.
> For size=16 the runtime check overhead is
>   ~ 32% before the patch set
>   ~ 16% after the patch set.
> On a practical workload or for large sizes the overhead should be tiny.

This is a huge improvement, but still far from being practical given malloc is already
slow, so making it this much slower is a non-starter. For this to be usable for distros,
we really need to get the overhead below 5% (and it looks like that is feasible - with
the optimizations mentioned I get ~3.2% overhead).

Cheers,
Wilco

             reply	other threads:[~2021-03-05 21:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-05 21:36 Wilco Dijkstra [this message]
2021-03-08  9:34 ` Szabolcs Nagy
  -- strict thread matches above, loose matches on Subject: below --
2021-03-04 16:30 Szabolcs Nagy

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=VE1PR08MB5599E15BF7D9237DA52E9A1083969@VE1PR08MB5599.eurprd08.prod.outlook.com \
    --to=wilco.dijkstra@arm.com \
    --cc=Szabolcs.Nagy@arm.com \
    --cc=dj@redhat.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).