public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: DJ Delorie <dj@redhat.com>
To: Szabolcs Nagy <szabolcs.nagy@arm.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH 1/6] malloc: Use memsize instead of CHUNK_AVAILABLE_SIZE
Date: Tue, 23 Mar 2021 16:01:35 -0400	[thread overview]
Message-ID: <xnblb9k5b4.fsf@rhel8.vm> (raw)
In-Reply-To: <4af59f688a0c79487187441c3257466037164221.1616155129.git.szabolcs.nagy@arm.com> (message from Szabolcs Nagy on Fri, 19 Mar 2021 13:26:09 +0000)

Szabolcs Nagy <szabolcs.nagy@arm.com> writes:
> This is a pure refactoring change that does not affect behaviour.

You hope :-)

LGTM.
Reviewed-by: DJ Delorie <dj@redhat.com>

> -  for (size = CHUNK_AVAILABLE_SIZE (p) - 1;
> +  for (size = CHUNK_HDR_SZ + memsize (p) - 1;

Ok.

> -  max_sz = CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ;
> +  max_sz = memsize (p);

Ok.

> -      for (sz = CHUNK_AVAILABLE_SIZE (p) - 1;
> +      for (sz = CHUNK_HDR_SZ + memsize (p) - 1;

Ok.  Odd that it's not chunksize() but that would affect behavior ;-)

> -      for (sz = CHUNK_AVAILABLE_SIZE (p) - 1;
> +      for (sz = CHUNK_HDR_SZ + memsize (p) - 1;

Ok.

> -      (void)tag_region (chunk2rawmem (p), CHUNK_AVAILABLE_SIZE (p)
> -                                         - CHUNK_HDR_SZ);
> +      (void)tag_region (chunk2rawmem (p), memsize (p));

Ok.

> -/* Available size of chunk.  This is the size of the real usable data
> -   in the chunk, plus the chunk header.  Note: If memory tagging is
> -   enabled the layout changes to accomodate the granule size, this is
> -   wasteful for small allocations so not done by default.  The logic
> -   does not work if chunk headers are not granule aligned.  */
> -_Static_assert (__MTAG_GRANULE_SIZE <= CHUNK_HDR_SZ,
> -		"memory tagging is not supported with large granule.");
> -#define CHUNK_AVAILABLE_SIZE(p)                                       \
> -  (__MTAG_GRANULE_SIZE > SIZE_SZ && __glibc_unlikely (mtag_enabled) ? \
> -    chunksize (p) :                                                   \
> -    chunksize (p) + (chunk_is_mmapped (p) ? 0 : SIZE_SZ))
> -

Dropped, ok.

> +/* This is the size of the real usable data in the chunk.  Not valid for
> +   dumped heap chunks.  */
> +#define memsize(p)                                                    \
> +  (__MTAG_GRANULE_SIZE > SIZE_SZ && __glibc_unlikely (mtag_enabled) ? \
> +    chunksize (p) - CHUNK_HDR_SZ :                                    \
> +    chunksize (p) - CHUNK_HDR_SZ + (chunk_is_mmapped (p) ? 0 : SIZE_SZ))
> +
> +/* If memory tagging is enabled the layout changes to accomodate the granule
> +   size, this is wasteful for small allocations so not done by default.
> +   Both the chunk header and user data has to be granule aligned.  */
> +_Static_assert (__MTAG_GRANULE_SIZE <= CHUNK_HDR_SZ,
> +		"memory tagging is not supported with large granule.");
> +

New, ok.

> -      ptr = __libc_mtag_tag_region (__libc_mtag_new_tag (ptr),
> -				    CHUNK_AVAILABLE_SIZE (cp) - CHUNK_HDR_SZ);
> +      ptr = __libc_mtag_tag_region (__libc_mtag_new_tag (ptr), memsize (cp));

Ok.

> -      (void)tag_region (chunk2rawmem (p),
> -			CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
> +      (void)tag_region (chunk2rawmem (p), memsize (p));

Ok.

> -	  size_t sz = CHUNK_AVAILABLE_SIZE (oldp) - CHUNK_HDR_SZ;
> +	  size_t sz = memsize (oldp);

Ok.

> -    return tag_new_zero_region (mem, CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ);
> +    return tag_new_zero_region (mem, memsize (p));

Ok.

> -	      size_t sz = CHUNK_AVAILABLE_SIZE (oldp) - CHUNK_HDR_SZ;
> +	      size_t sz = memsize (oldp);

Ok.

> -	result = CHUNK_AVAILABLE_SIZE (p) - CHUNK_HDR_SZ;
> +	result = memsize (p);

Ok.


  reply	other threads:[~2021-03-23 20:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-19 13:25 [PATCH 0/6] malloc: more memory tagging optimizations Szabolcs Nagy
2021-03-19 13:26 ` [PATCH 1/6] malloc: Use memsize instead of CHUNK_AVAILABLE_SIZE Szabolcs Nagy
2021-03-23 20:01   ` DJ Delorie [this message]
2021-03-19 13:26 ` [PATCH 2/6] malloc: Use different tag after mremap Szabolcs Nagy
2021-03-23 20:03   ` DJ Delorie
2021-03-19 13:26 ` [PATCH 3/6] malloc: Use chunk2rawmem throughout Szabolcs Nagy
2021-03-23 20:25   ` DJ Delorie
2021-03-19 13:27 ` [PATCH 4/6] malloc: Rename chunk2rawmem Szabolcs Nagy
2021-03-23 20:43   ` DJ Delorie
2021-03-19 13:27 ` [PATCH 5/6] malloc: Remove unnecessary tagging around _mid_memalign Szabolcs Nagy
2021-03-23 20:44   ` DJ Delorie
2021-03-19 13:27 ` [PATCH 6/6] malloc: Ensure mtag code path in checked_request2size is cold Szabolcs Nagy
2021-03-23 20:46   ` DJ Delorie

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=xnblb9k5b4.fsf@rhel8.vm \
    --to=dj@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=szabolcs.nagy@arm.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.
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).