public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: DJ Delorie via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH v2 1/1] memalign: Support scanning for aligned chunks.
Date: Tue, 19 Jul 2022 11:19:09 +0200	[thread overview]
Message-ID: <878ropa29e.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <xnr12hbvqa.fsf@greed.delorie.com> (DJ Delorie via Libc-alpha's message of "Mon, 18 Jul 2022 23:57:17 -0400")

* DJ Delorie via Libc-alpha:

> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 12908b8f97..14ee98dfa2 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -3557,6 +3557,30 @@ _mid_memalign (size_t alignment, size_t bytes, void *address)
>        alignment = a;
>      }
>  
> +#if USE_TCACHE
> +  {
> +    size_t tbytes;
> +    tbytes = checked_request2size (bytes);
> +    if (tbytes == 0)
> +      {
> +	__set_errno (ENOMEM);
> +	return NULL;
> +      }
> +    size_t tc_idx = csize2tidx (tbytes);
> +
> +    MAYBE_INIT_TCACHE ();
> +
> +    if (tc_idx < mp_.tcache_bins
> +	&& tcache
> +	&& tcache->counts[tc_idx] > 0
> +	&& ((intptr_t)tcache->entries[tc_idx] & (alignment - 1)) == 0)
> +      {
> +	void *victim = tcache_get (tc_idx);
> +	return tag_new_usable (victim);
> +      }
> +  }
> +#endif

MAYBE_INIT_TCACHE does not seem necessary.  If the tcache is empty,
there's no need to initialize it and scane it.  And why not scan the
entire chain here?  It's another source of missed chunk reuse.

The tcache null check should be written as tcache != NULL.

Thanks,
Florian


  reply	other threads:[~2022-07-19  9:19 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14  3:58 [PATCH v1 " DJ Delorie
2022-07-19  2:54 ` Carlos O'Donell
2022-07-19  3:57   ` [PATCH v2 " DJ Delorie
2022-07-19  9:19     ` Florian Weimer [this message]
2022-07-19 17:32       ` DJ Delorie
2022-07-20  0:32       ` [PATCH v3 " DJ Delorie
2022-07-22 20:21         ` DJ Delorie
2022-07-22 20:28         ` Joseph Myers
2022-07-28 19:50           ` [PATCH v4 " DJ Delorie
2022-08-17 19:00             ` DJ Delorie
2022-11-10 21:40               ` Ping^2: " DJ Delorie
2023-03-20 21:49                 ` Ping^3: " DJ Delorie
2023-03-28 19:07             ` Adhemerval Zanella Netto
2023-03-29  4:20               ` [PATCH v5 " DJ Delorie
2023-03-29 19:41                 ` Adhemerval Zanella Netto
2023-03-29 20:36                   ` DJ Delorie
2023-03-30 10:04                     ` Cristian Rodríguez
2023-03-30 10:50                       ` Adhemerval Zanella Netto
2023-03-30 21:43                         ` Cristian Rodríguez
2023-04-12 17:04                           ` Xi Ruoyao
2023-04-12 17:16                             ` DJ Delorie
2023-04-12 17:26                               ` Xi Ruoyao
2023-04-13  1:52                                 ` [PATCH v6 " DJ Delorie
2023-04-13  5:51                                   ` Xi Ruoyao
2023-04-17 21:48                                   ` Carlos O'Donell
2023-04-18  1:25                                     ` [PATCH v7] " DJ Delorie
2023-04-18 13:58                                       ` Carlos O'Donell
2023-04-18 15:02                                         ` DJ Delorie
2023-04-12 17:33                             ` [PATCH v5 1/1] " Adhemerval Zanella Netto
2023-04-12 17:40                               ` DJ Delorie
2023-04-12 18:01                                 ` Adhemerval Zanella Netto
2023-04-13  1:57                                   ` DJ Delorie
2023-04-13 10:46                                     ` Adhemerval Zanella Netto
2023-04-05 14:07                     ` Stefan Liebler
2023-04-05 17:58                       ` DJ Delorie
2023-04-11 11:40                         ` Stefan Liebler
2023-04-12 11:23                           ` Stefan Liebler
2023-03-31 15:39                 ` Adhemerval Zanella Netto

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=878ropa29e.fsf@oldenburg.str.redhat.com \
    --to=fweimer@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).