From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 3A6473858D1E for ; Tue, 2 May 2023 23:09:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A6473858D1E Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=google.com Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1a7ff4a454eso149355ad.0 for ; Tue, 02 May 2023 16:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683068940; x=1685660940; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=QMU2AfwEfa3ThuWqMg71jQ3nP/W1q/4ZuJ6oRHh5Bmk=; b=aS9g19AIlCQgUlhufqWttvGAMgFWbiGPdN3s4Y45xv6EDBKHYjt2q8UbvlyIxWWeyq 56Ug8aRNwAWjLXe4TrK+d/XXSkfSFZ6ierDtpybBE8+fMkVp7ZeBFGqeEB4525djQy4f bG5sU6qiE8OS0hcCPJzIMEOYPN3AN3K2MIn+YmpaJD+NQtGxGXfx9w43tBTtGt8JE3pd 5oQN0SCFwVw44iSxLpZDeuOyk3izCq0O9A8QoYOnU/tfzF59KNPO3+1CXqiEmrFkcmKO U9Cl/uQjD8PA8nL3aerlvBgq3oiKWhz6ufAqrK302i1yxv5pIIpsO5u7D8RY7QbzF97U WfAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683068940; x=1685660940; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QMU2AfwEfa3ThuWqMg71jQ3nP/W1q/4ZuJ6oRHh5Bmk=; b=PENdsrNNNlDipU214gGNt8JfJOubLbSN5Ii9u2FSulWlxv/Y/8lIUavXewHfaJNOQL 4QDEQunwOSx3uMFhvpcHiGI4imEBo/Q71adgJhzcAE3QVZFVxsODtb942rAqMtuZ/oAS pnIZOoP9y5dXtolkmcrxY6K1UVikIH9ghWFDB78P+ovmjw4EN2zNIPO5mlXUFa1exNpL AlOlCb8dX2sm3F3EyYvaYh2yvJiz2fUReHETKZlA18DVUoY9I31F06aYd8wz/ZlP0z+i VYCKCA3O2uPlvqkiWIc2qZvM9G3gOPDlozfECjRdFfsA1ekvUyi/pALa8DEYzPArQeN+ hPRw== X-Gm-Message-State: AC+VfDwi8WdG7yqMy5lAiiPmjBmFTEOrq70yl+UjImtZhu32BgCNLk1O 6fwQcNC/gjnsxCUtSYg+5k7cG4QamssrEji5dGmuJ31TuSgqcf0yLtOdSptS X-Google-Smtp-Source: ACHHUZ52UbSFYV1MqCwTIIW9C+/RrgUJZLNk+pf7s+zmWteqro0aNFsRUCMYL8JohWpIcMnECO/1G9AfOmTP56d1Akg= X-Received: by 2002:a17:903:2804:b0:1a6:d776:9628 with SMTP id kp4-20020a170903280400b001a6d7769628mr23240plb.19.1683068940084; Tue, 02 May 2023 16:09:00 -0700 (PDT) MIME-Version: 1.0 References: <20230428062634.2152615-1-maskray@google.com> <87o7n89z3n.fsf@oldenburg.str.redhat.com> In-Reply-To: <87o7n89z3n.fsf@oldenburg.str.redhat.com> From: Fangrui Song Date: Tue, 2 May 2023 16:08:48 -0700 Message-ID: Subject: Re: [PATCH] elf: Add the soname to the libname_list eagerly on loading a library To: Florian Weimer Cc: Fangrui Song via Libc-alpha Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-24.9 required=5.0 tests=BAYES_00,DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Apr 28, 2023 at 1:42=E2=80=AFAM Florian Weimer = wrote: > > * Fangrui Song via Libc-alpha: > > > Original author is Ambrose Feinstein while working at Google. > > > > _dl_map_object iterates over loaded objects and calls _dl_name_match_p. > > If l->l_soname_added is 0, we incur two costs. > > > > First, loading l->l_info[DT_SONAME]->d_un.d_val has TLB pressure as > > every library's string table is in a different page. The cost will be > > avoided if the string is on the heap. > > > > Second, add_name_to_object repeats the l_libname comparison already don= e > > by the _dl_name_match_p call. > > > > To remove these costs, we eagerly add the SONAME to the libname_list. > > l_soname_added is typically 1, so laziness doesn't provide savings. > > --- > > elf/dl-load.c | 5 +++-- > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/elf/dl-load.c b/elf/dl-load.c > > index 9a0e40c0e9..1b17410ce0 100644 > > --- a/elf/dl-load.c > > +++ b/elf/dl-load.c > > @@ -1451,10 +1451,11 @@ cannot enable executable stack as shared object= requires"); > > > > /* When we profile the SONAME might be needed for something else but > > loading. Add it right away. */ > > - if (__glibc_unlikely (GLRO(dl_profile) !=3D NULL) > > - && l->l_info[DT_SONAME] !=3D NULL) > > + if (l->l_info[DT_SONAME] !=3D NULL) { > > add_name_to_object (l, ((const char *) D_PTR (l, l_info[DT_STRTAB]= ) > > + l->l_info[DT_SONAME]->d_un.d_val)); > > + l->l_soname_added =3D 1; > > + } > > > > /* If we have newly loaded libc.so, update the namespace > > description. */ > > The comment is now outdated. > > Not sure if this kind of micro-optimization makes sense. Maybe until we > add a hash table here =E2=80=A6 > > Thanks, > Florian > Perhaps just remove the comment? I think there is some merit replacing a tricky condition __glibc_unlikely (GLRO(dl_profile) !=3D NULL to a simple one ` l->l_soname_added =3D 1;`. This optimization matters for an executable with O(1000) shared object dependencies. The quadratic time DSO comparison multiplied by the strcmp dominates the load time. This patch removes one bottleneck.