From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2D6EF3858439 for ; Tue, 19 Jul 2022 09:19:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2D6EF3858439 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-582-K9XT_RiZOM-jEuuztO6fIg-1; Tue, 19 Jul 2022 05:19:11 -0400 X-MC-Unique: K9XT_RiZOM-jEuuztO6fIg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A6FD738149A7 for ; Tue, 19 Jul 2022 09:19:11 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.173]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7F8F492C3B; Tue, 19 Jul 2022 09:19:10 +0000 (UTC) From: Florian Weimer To: DJ Delorie via Libc-alpha Subject: Re: [PATCH v2 1/1] memalign: Support scanning for aligned chunks. References: Date: Tue, 19 Jul 2022 11:19:09 +0200 In-Reply-To: (DJ Delorie via Libc-alpha's message of "Mon, 18 Jul 2022 23:57:17 -0400") Message-ID: <878ropa29e.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jul 2022 09:19:18 -0000 * 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