From patchwork Mon Jul 5 17:08:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 44148 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 02A81386480C for ; Mon, 5 Jul 2021 17:11:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02A81386480C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625505113; bh=OjUFJ0lf7EkEZLaSS1fo4q3B2KRw1oSxntPasdU09ys=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=xw3pkY5FRMxfYffyEYOIdSnQKUBeZp8pcR/8vU1GEyXSLGmULIySrBzKDHfgh+NW8 5N3t9X9Y1bGpQzA7G+QKR+EbNh7jxwZ5ooo+qcP08C98QHJsP/oMsn6kYEb8r/eQYc 7ziarDyVzZfNKPsDOoNwb2g+WSvxneRizQclAsYY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from beige.elm.relay.mailchannels.net (beige.elm.relay.mailchannels.net [23.83.212.16]) by sourceware.org (Postfix) with ESMTPS id BA861385503D for ; Mon, 5 Jul 2021 17:09:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BA861385503D X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id E1A457E239E; Mon, 5 Jul 2021 17:09:07 +0000 (UTC) Received: from pdx1-sub0-mail-a29.g.dreamhost.com (100-101-162-64.trex.outbound.svc.cluster.local [100.101.162.64]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 20E0E7E2E7D; Mon, 5 Jul 2021 17:09:07 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a29.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.101.162.64 (trex/6.3.3); Mon, 05 Jul 2021 17:09:07 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Shoe-Decisive: 746b84c62340e2ef_1625504947455_752551726 X-MC-Loop-Signature: 1625504947453:1632682146 X-MC-Ingress-Time: 1625504947452 Received: from pdx1-sub0-mail-a29.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a29.g.dreamhost.com (Postfix) with ESMTP id BB9BA7E509; Mon, 5 Jul 2021 10:09:06 -0700 (PDT) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a29.g.dreamhost.com (Postfix) with ESMTPSA id EE80F7E4A5; Mon, 5 Jul 2021 10:09:03 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a29 To: libc-alpha@sourceware.org Subject: [PATCH v5 3/8] Simplify __malloc_initialized Date: Mon, 5 Jul 2021 22:38:09 +0530 Message-Id: <20210705170814.4132997-4-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210705170814.4132997-1-siddhesh@sourceware.org> References: <20210705170814.4132997-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: fweimer@redhat.com Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Now that mcheck no longer needs to check __malloc_initialized (and no other third party hook can since the symbol is not exported), make the variable boolean and static so that it is used strictly within malloc. --- include/malloc.h | 6 ------ malloc/arena.c | 12 ++++++------ malloc/malloc.c | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/include/malloc.h b/include/malloc.h index b77761f74d..f9c9610548 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -5,12 +5,6 @@ # ifndef _ISOMAC # include -/* In the GNU libc we rename the global variable - `__malloc_initialized' to `__libc_malloc_initialized'. */ -#define __malloc_initialized __libc_malloc_initialized -/* Nonzero if the malloc is already initialized. */ -extern int __malloc_initialized attribute_hidden; - struct malloc_state; typedef struct malloc_state *mstate; diff --git a/malloc/arena.c b/malloc/arena.c index 8f890d5ff0..cae3387db0 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -97,7 +97,7 @@ static mstate free_list; __libc_lock_define_initialized (static, list_lock); /* Already initialized? */ -int __malloc_initialized = -1; +static bool __malloc_initialized = false; /**************************************************************************/ @@ -143,7 +143,7 @@ int __malloc_initialized = -1; void __malloc_fork_lock_parent (void) { - if (__malloc_initialized < 1) + if (!__malloc_initialized) return; /* We do not acquire free_list_lock here because we completely @@ -163,7 +163,7 @@ __malloc_fork_lock_parent (void) void __malloc_fork_unlock_parent (void) { - if (__malloc_initialized < 1) + if (!__malloc_initialized) return; for (mstate ar_ptr = &main_arena;; ) @@ -179,7 +179,7 @@ __malloc_fork_unlock_parent (void) void __malloc_fork_unlock_child (void) { - if (__malloc_initialized < 1) + if (!__malloc_initialized) return; /* Push all arenas to the free list, except thread_arena, which is @@ -290,10 +290,10 @@ libc_hidden_proto (_dl_open_hook); static void ptmalloc_init (void) { - if (__malloc_initialized >= 0) + if (__malloc_initialized) return; - __malloc_initialized = 0; + __malloc_initialized = true; #ifdef USE_MTAG if ((TUNABLE_GET_FULL (glibc, mem, tagging, int32_t, NULL) & 1) != 0) diff --git a/malloc/malloc.c b/malloc/malloc.c index d2e45664b1..595dd8bbdb 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3195,7 +3195,7 @@ __libc_malloc (size_t bytes) _Static_assert (PTRDIFF_MAX <= SIZE_MAX / 2, "PTRDIFF_MAX is not more than half of SIZE_MAX"); - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); #if USE_TCACHE /* int_free also calls request2size, be careful to not pad twice. */ @@ -3308,7 +3308,7 @@ __libc_realloc (void *oldmem, size_t bytes) void *newp; /* chunk to return */ - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); #if REALLOC_ZERO_BYTES_FREES @@ -3444,7 +3444,7 @@ libc_hidden_def (__libc_realloc) void * __libc_memalign (size_t alignment, size_t bytes) { - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); void *address = RETURN_ADDRESS (0); @@ -3515,7 +3515,7 @@ libc_hidden_def (__libc_memalign) void * __libc_valloc (size_t bytes) { - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); void *address = RETURN_ADDRESS (0); @@ -3526,7 +3526,7 @@ __libc_valloc (size_t bytes) void * __libc_pvalloc (size_t bytes) { - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); void *address = RETURN_ADDRESS (0); @@ -3565,7 +3565,7 @@ __libc_calloc (size_t n, size_t elem_size) sz = bytes; - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); MAYBE_INIT_TCACHE (); @@ -5022,7 +5022,7 @@ __malloc_trim (size_t s) { int result = 0; - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); mstate ar_ptr = &main_arena; @@ -5157,7 +5157,7 @@ __libc_mallinfo2 (void) struct mallinfo2 m; mstate ar_ptr; - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); memset (&m, 0, sizeof (m)); @@ -5208,7 +5208,7 @@ __malloc_stats (void) mstate ar_ptr; unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b; - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); _IO_flockfile (stderr); int old_flags2 = stderr->_flags2; @@ -5377,7 +5377,7 @@ __libc_mallopt (int param_number, int value) mstate av = &main_arena; int res = 1; - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); __libc_lock_lock (av->mutex); @@ -5595,7 +5595,7 @@ __posix_memalign (void **memptr, size_t alignment, size_t size) { void *mem; - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); /* Test whether the SIZE argument is valid. It must be a power of @@ -5639,7 +5639,7 @@ __malloc_info (int options, FILE *fp) - if (__malloc_initialized < 0) + if (!__malloc_initialized) ptmalloc_init (); fputs ("\n", fp);