Message ID | e661c73438b37a7c931089e6ba0421a5711d468d.1605283657.git.fweimer@redhat.com |
---|---|
State | Superseded |
Headers |
Return-Path: <libc-alpha-bounces@sourceware.org> 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 D8C7C393C85B; Fri, 13 Nov 2020 16:14:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8C7C393C85B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1605284062; bh=cO09LLVhS55vu+HV4yVzFqcK1Q0szmKchQDC7WNK10I=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=SrioTzX5tL+t5pJ3UG8Hh2xdQIwajlfxTI0p47SyyuMH7FB35a1C7qrapP48YM7QL 6/xgHUgBFBLHkV1hROR2mDANsAi8aUI0c+0CAxucixkTD1sLw5tKI8CGu+4ySme2Oy 1E0T6mqIeP/Q6sQqnmcSqEHxPGdaecw2bAJsrgIc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id E876B393C85A for <libc-alpha@sourceware.org>; Fri, 13 Nov 2020 16:14:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E876B393C85A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-8-hVHkuJB6OMqIh-OHN36fbQ-1; Fri, 13 Nov 2020 11:14:18 -0500 X-MC-Unique: hVHkuJB6OMqIh-OHN36fbQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B540E1009E33 for <libc-alpha@sourceware.org>; Fri, 13 Nov 2020 16:14:17 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-113-222.ams2.redhat.com [10.36.113.222]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3196F62A16 for <libc-alpha@sourceware.org>; Fri, 13 Nov 2020 16:14:17 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 2/2] malloc: Use __libc_type to detect an inner libc In-Reply-To: <7e89ec4dee33dd4eef6986dd0e790a9500c430b6.1605283657.git.fweimer@redhat.com> References: <7e89ec4dee33dd4eef6986dd0e790a9500c430b6.1605283657.git.fweimer@redhat.com> Message-Id: <e661c73438b37a7c931089e6ba0421a5711d468d.1605283657.git.fweimer@redhat.com> Date: Fri, 13 Nov 2020 17:14:15 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.2 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, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Florian Weimer via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Florian Weimer <fweimer@redhat.com> Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
[1/2] Replace __libc_multiple_libcs with tri-state __libc_type
|
|
Commit Message
Florian Weimer
Nov. 13, 2020, 4:14 p.m. UTC
The inner libc must not use sbrk. _dl_addr occasionally shows up in profiles, but had to be used before because __libc_multiple_libs was unreliable. --- malloc/arena.c | 7 +------ malloc/malloc.c | 2 ++ 2 files changed, 3 insertions(+), 6 deletions(-)
Comments
On 13/11/2020 13:14, Florian Weimer via Libc-alpha wrote: > The inner libc must not use sbrk. _dl_addr occasionally shows up > in profiles, but had to be used before because __libc_multiple_libs > was unreliable. LGTM. Is the performance the only advantage of using sbrk on the inner libc? > --- > malloc/arena.c | 7 +------ > malloc/malloc.c | 2 ++ > 2 files changed, 3 insertions(+), 6 deletions(-) > > diff --git a/malloc/arena.c b/malloc/arena.c > index 202daf15b0..865eaa1a84 100644 > --- a/malloc/arena.c > +++ b/malloc/arena.c > @@ -296,12 +296,7 @@ ptmalloc_init (void) > #ifdef SHARED > /* In case this libc copy is in a non-default namespace, never use brk. > Likewise if dlopened from statically linked program. */ > - Dl_info di; > - struct link_map *l; > - > - if (_dl_open_hook != NULL > - || (_dl_addr (ptmalloc_init, &di, &l, NULL) != 0 > - && l->l_ns != LM_ID_BASE)) > + if (__libc_type == libc_type_secondary) > __morecore = __failing_morecore; > #endif > > diff --git a/malloc/malloc.c b/malloc/malloc.c > index 5b87bdb081..0834e4181a 100644 > --- a/malloc/malloc.c > +++ b/malloc/malloc.c > @@ -247,6 +247,8 @@ > /* For SINGLE_THREAD_P. */ > #include <sysdep-cancel.h> > > +#include <libc-internal.h> > + > /* > Debugging: > >
* Adhemerval Zanella via Libc-alpha: > On 13/11/2020 13:14, Florian Weimer via Libc-alpha wrote: >> The inner libc must not use sbrk. _dl_addr occasionally shows up >> in profiles, but had to be used before because __libc_multiple_libs >> was unreliable. > > LGTM. Is the performance the only advantage of using sbrk on > the inner libc? Avoiding sbrk in the inner libc is required for correctness because sbrk is not thread-safe, and there is no external synchronization. The startup performance improvement comes from not calling _dl_addr. On POWER, it saves around 150,000 instructions, according to a quick test. Thanks, Florian
On 13/11/2020 16:05, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> On 13/11/2020 13:14, Florian Weimer via Libc-alpha wrote: >>> The inner libc must not use sbrk. _dl_addr occasionally shows up >>> in profiles, but had to be used before because __libc_multiple_libs >>> was unreliable. >> >> LGTM. Is the performance the only advantage of using sbrk on >> the inner libc? > > Avoiding sbrk in the inner libc is required for correctness because sbrk > is not thread-safe, and there is no external synchronization. > > The startup performance improvement comes from not calling _dl_addr. On > POWER, it saves around 150,000 instructions, according to a quick test. In fact I meant what is the gain of using sbrk on outer libc. I am asking because maybe an option would be to use the same strategy regardless whether it is a inner or outer libc.
* Adhemerval Zanella: > On 13/11/2020 16:05, Florian Weimer wrote: >> * Adhemerval Zanella via Libc-alpha: >> >>> On 13/11/2020 13:14, Florian Weimer via Libc-alpha wrote: >>>> The inner libc must not use sbrk. _dl_addr occasionally shows up >>>> in profiles, but had to be used before because __libc_multiple_libs >>>> was unreliable. >>> >>> LGTM. Is the performance the only advantage of using sbrk on >>> the inner libc? >> >> Avoiding sbrk in the inner libc is required for correctness because sbrk >> is not thread-safe, and there is no external synchronization. >> >> The startup performance improvement comes from not calling _dl_addr. On >> POWER, it saves around 150,000 instructions, according to a quick test. > > In fact I meant what is the gain of using sbrk on outer libc. I am asking > because maybe an option would be to use the same strategy regardless whether > it is a inner or outer libc. Oh, that's totally unclear. The main arena has a very different layout from the other arenas. The __morecore hook exposes the inner sbrk-based workings of our malloc as part of the ABI. I'm not sure if we can restructure the code so that __morecore is never called, or if that would break existing users (such as libhugetlbfs). Thanks, Florian
diff --git a/malloc/arena.c b/malloc/arena.c index 202daf15b0..865eaa1a84 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -296,12 +296,7 @@ ptmalloc_init (void) #ifdef SHARED /* In case this libc copy is in a non-default namespace, never use brk. Likewise if dlopened from statically linked program. */ - Dl_info di; - struct link_map *l; - - if (_dl_open_hook != NULL - || (_dl_addr (ptmalloc_init, &di, &l, NULL) != 0 - && l->l_ns != LM_ID_BASE)) + if (__libc_type == libc_type_secondary) __morecore = __failing_morecore; #endif diff --git a/malloc/malloc.c b/malloc/malloc.c index 5b87bdb081..0834e4181a 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -247,6 +247,8 @@ /* For SINGLE_THREAD_P. */ #include <sysdep-cancel.h> +#include <libc-internal.h> + /* Debugging: