Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10443698rwd; Wed, 21 Jun 2023 23:24:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7oAC/MJwhyoptOXFn2mYGq9KQJRoOpmZYqAIU4emxrcuwNSYTYN4XXSW27o58/5X5vs2aE X-Received: by 2002:a05:620a:2b88:b0:762:5179:5d97 with SMTP id dz8-20020a05620a2b8800b0076251795d97mr14993266qkb.12.1687415090732; Wed, 21 Jun 2023 23:24:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687415090; cv=none; d=google.com; s=arc-20160816; b=W/noFVpEyKHkrYZBYQy74bJQfH5c9Qyy6YMJOCGO/6i67BP4NhPu/4IEXKJCQTAB1Q p8Pyx1mVWMCeV2mWI7bBgIi5BapcUcTW/h0Two5SHwGi9XdglTP1HrsQXhDW9HKxmFI6 5ZMQhI0dPGYJVP3cYy013vHYxxcUtWYNAtQIcG7JXycZDVzuR2ZOALRdhf/sUkFJNMOe VZmQla1YrMkL2GNT+PRQh3IartBGk84+uutP2na1rvWvelocVo5557GnGkMHEk8xg7wY J2mVv0MplADt5g/5OZukefZjTIM3Bd34ksItD4Z6RbnQ2wvCKHDX95b3f0QSKCfGACOM orKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=F3YNCvHVBh6f5985fs1PM5llxz1wl3G7BMCoa8Ui5Y4=; b=CGofWiduz98piiP8aTfwXin8Cq/Lq2yJxKiPf14cxCdaby4m+8j6elbPlaS+c4nBAJ GByxutd5XpD/vcbebI1QQFCQ075QDxU+2SzrgLhm554ahObNt46Cy6VYGpSxsuWSKy+2 z9hq5PD15FmmFg5yh9omwyfgkOuDSWS2zqrtg+IGzWp9H6NcjACkENcukjCdOPBGnOn+ G5fvRFcFBHePGO35fEVr79dXPKcCZTdjoa6uz7k8eih3MOQOZbOwt5owGJ+OLco9iELg EhpgifKwwDP7Hi7Iq6W83VcusbfQcVlDrexF6Q3dH57Uq8hipWnCpKUQOIHwkwAeNOsS 0aLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=jWAnJ3S4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 85-20020a630058000000b0053fe392ca3esi2105936pga.509.2023.06.21.23.24.39; Wed, 21 Jun 2023 23:24:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=jWAnJ3S4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231144AbjFVFyu (ORCPT + 99 others); Thu, 22 Jun 2023 01:54:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbjFVFyo (ORCPT ); Thu, 22 Jun 2023 01:54:44 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 626A310F0 for ; Wed, 21 Jun 2023 22:54:42 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id d75a77b69052e-3fde9bfb3c8so84061cf.0 for ; Wed, 21 Jun 2023 22:54:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687413281; x=1690005281; 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=F3YNCvHVBh6f5985fs1PM5llxz1wl3G7BMCoa8Ui5Y4=; b=jWAnJ3S40v/MJxJRmfuVpU9OaAQN2PgYBYv7/cd6zod/5Ict5iXkK8uPJ6ViEy7h/K NgGf8guh+Gkj1/e4t7WQSpfLX8V9u6QepA6BsTIKddtPnT+ueMeflAvSpVu/SSq5DeZS BYXDqVKycYzbkRodJG1mfHP84Qq3cR0JM1aEuHGn45m4iofCV+guz8VmR2vWoMINorCp E7HfvsVvzQJny96GLYkb+ALMzXcR0Y8nTBfToqwak6Hp8gNhgQ9nivnwud/1MFtYKitq zVFq7K72ZcARs8uznLNvuE0HqqurqhBm5Z8SmuSBnNQBjHUHIDVvSXgfzyqFQPEYmAKy te5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687413281; x=1690005281; 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=F3YNCvHVBh6f5985fs1PM5llxz1wl3G7BMCoa8Ui5Y4=; b=bBZ0QHZyB7S+7jM6ynbXCdWsahG8/TknhOWYOtnjknFkGyoh0t+JYp14VaZF2wGReh VwrnH4nEzsHT8KIDaDX7yUSQDXljUE0r02GN7/95uevCC7wo6ItoDXs2WYlZqi/cbTej wDxvEMnsnt358aB31oOtQ/8NOnEmIq5R+PGup2PXDac1oZ4HlzaOvxk+fuWd96i8IJ/N vBGUd16yf1NUOFJXdsZZRLD2Vut3ohNFIWEPBaZwGTI0uF4qLgelDCq8VD7ZUCpvS6hw FQxR/+jGxKNuep6sVN9htmFN1hVHk+MAheRtAfGgtagwyPF5i+SNfJAB0FJVikF/JNkk fPGw== X-Gm-Message-State: AC+VfDzCjrAcyiy9r4W2E+dcZ+O7ctIc+JNXx4LBuL111X28aLDqoGPs qUHIUY0z9w2dWN4XFA+podqmx9QhYzEZKUNl2EsoeA== X-Received: by 2002:ac8:7fcf:0:b0:3f3:75c2:7466 with SMTP id b15-20020ac87fcf000000b003f375c27466mr724316qtk.8.1687413281285; Wed, 21 Jun 2023 22:54:41 -0700 (PDT) MIME-Version: 1.0 References: <20230621063749.3358430-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Wed, 21 Jun 2023 22:54:30 -0700 Message-ID: Subject: Re: [PATCH v2 1/2] perf symbol: Remove symbol_name_rb_node To: Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Kan Liang , Yang Jihong , Carsten Haitzler , Changbin Du , Athira Rajeev , Christophe JAILLET , Jason Wang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-15.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URI_DOTEDU,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 21, 2023 at 10:21=E2=80=AFPM Namhyung Kim = wrote: > > On Wed, Jun 21, 2023 at 9:28=E2=80=AFPM Ian Rogers w= rote: > > > > On Wed, Jun 21, 2023 at 8:51=E2=80=AFPM Namhyung Kim wrote: > > > > > > Hi Ian, > > > > > > On Tue, Jun 20, 2023 at 11:37=E2=80=AFPM Ian Rogers wrote: > > > > > > > > Most perf commands want to sort symbols by name and this is done vi= a > > > > an invasive rbtree that on 64-bit systems costs 24 bytes. Sorting t= he > > > > symbols in a DSO by name is optional and not done by default, howev= er, > > > > if sorting is requested the 24 bytes is allocated for every > > > > symbol. > > > > > > > > This change removes the rbtree and uses a sorted array of symbol > > > > pointers instead (costing 8 bytes per symbol). As the array is crea= ted > > > > on demand then there are further memory savings. The complexity of > > > > sorting the array and using the rbtree are the same. > > > > > > > > To support going to the next symbol, the index of the current symbo= l > > > > needs to be passed around as a pair with the current symbol. This > > > > requires some API changes. > > > > > > > > Signed-off-by: Ian Rogers > > > > > > > > v2. map__find_symbol_by_name_idx so that map__find_symbol_by_name > > > > doesn't need an optional parameter. Separate out > > > > symbol_conf.sort_by_name removal. > > > > --- > > > > > > [SNIP] > > > > void dso__sort_by_name(struct dso *dso) > > > > { > > > > - dso__set_sorted_by_name(dso); > > > > - return symbols__sort_by_name(&dso->symbol_names, &dso->symb= ols); > > > > + mutex_lock(&dso->lock); > > > > + if (!dso__sorted_by_name(dso)) { > > > > + size_t len; > > > > + > > > > + dso->symbol_names =3D symbols__sort_by_name(&dso->s= ymbols, &len); > > > > + if (dso->symbol_names) { > > > > + dso->symbol_names_len =3D len; > > > > + dso__set_sorted_by_name(dso); > > > > + } > > > > + } > > > > + mutex_unlock(&dso->lock); > > > > > > I think this part deserves a separate commit. > > > > Using the mutex or the use of sorted_by_name? > > For the mutex originally, but might be better to split further. :) I can add the locks first. There's an obvious leak with the array approach if two threads are sorting. With the invasive rbtree a leak isn't possible but corruption could be. > And now it grabs the mutex unconditionally, I think > we can check the condition without the mutex first > and again with the mutex if not sorted. Is there a kernel pattern for double checked locking that isn't broken in the normal ways double checked locking is broken? https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html Thanks, Ian > Thanks, > Namhyung