Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp806100pxb; Thu, 17 Feb 2022 15:24:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOuZ/SbjKYU5y5DoyNjb8Sx0ONaGHYwaH8yAJG2pKBYWNlM9Xt5uFXS1vgf5tWPJnUiZEO X-Received: by 2002:a62:7c41:0:b0:4e1:3185:cb21 with SMTP id x62-20020a627c41000000b004e13185cb21mr5264922pfc.82.1645140263598; Thu, 17 Feb 2022 15:24:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645140263; cv=none; d=google.com; s=arc-20160816; b=m0H5EALcIQ4ftzqHO8+cE+hjm51ZBnFfY6xrvO6FHA7Uk165ySD2lS7A0s2YywzAI5 p+rx9IoseoyRYyydpc9+YSBCLMZzt/TKtKCll6ftUC8+PlJCrBRfJfaq72k52YuFLcYz BkoOzpU/Q+CqGPBDGnsiI9wc6crMT9ZLsTka2yzhyEFiiip7V1wL4/9xHvlzqvG0QkJX 9/CUiAA6kCsaceBWKKDqFalGE/Cnb4/+aOgz0C3K38MBzbrJYLtpJY6BKfhTP2qv6K/i YEJaiAG+OuZ8FUz5gBrddHx1whOm3DOn71UdvQZwbK/me8oWIRNcgObWAYiPWfJbAauJ 6W2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=eHgl2T651ZUAY0dUPlPE7t+ZMJITI1iQLNfhsdAOi9A=; b=MTE0weqmzNSlOZjzxhQsmEt9cY52m44SKDpudVdwvqd8L8yB0HQfViC8Urb/wunIxn h4sPis8lCext5BVgi9Y3F28D2o8BSQlo7E8upL6USMbPPf5sIHd5H1re1ahfO3ww800S NlCTNgMLoWOjQOwA1JDVwvMNDtP4N6/4sPxtZutCO6rpYVwks0OuaAR8R12j/QmyR+f3 rrQuOspa9+9Uy0urcorypAm2N6tRVfurNg4EdnxfWGv69NjqODqGy78m7kUtwy/rDv+6 b/+QavVzRo6oo6JMRZ/CEDFdw9v2Isx5hIxb2NeuJI26TvxAyT+2mirv7KZ1mx32CUxT DErw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OyyGSpGs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y1si20478544pll.463.2022.02.17.15.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 15:24:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OyyGSpGs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C342655759; Thu, 17 Feb 2022 15:09:57 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242438AbiBQPYK (ORCPT + 99 others); Thu, 17 Feb 2022 10:24:10 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242426AbiBQPYD (ORCPT ); Thu, 17 Feb 2022 10:24:03 -0500 Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FB932B103D for ; Thu, 17 Feb 2022 07:23:43 -0800 (PST) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-2d62593ad9bso35432887b3.8 for ; Thu, 17 Feb 2022 07:23:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eHgl2T651ZUAY0dUPlPE7t+ZMJITI1iQLNfhsdAOi9A=; b=OyyGSpGsXoRUMe1+VpsE32Jzw9pC/T/sEcDlrwAfqTzFtyGDBuqSpPNuEl6SeVR0Qs AFKDV5ZQ+hSEpEmAZEquWsQhiHVRa+51dPltVToyoWlHiWM3F05pRItVl0UKT0SKGTD6 Gnd0oITi7nX9dnvZedukOqsSj7dQH0gNGnogTJVu7dGl1enSylVzxd6sIOsMS/AB86YP A/Bue505Xt+429q5JQ96dXyKTLgWr3e0sJXowp398lVnEJS7amIKej8Lhrr6MbHdPkmV V1EDN4J9TgejynO66RlqTRvfaiuXkOCZFK/K+elmI9ZrPXgNaVLtbF1hH+O9ZN5vseEv BpKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eHgl2T651ZUAY0dUPlPE7t+ZMJITI1iQLNfhsdAOi9A=; b=TOarCXMpHuHKSETr6gA6gY5gTNgICgQigYgz6UAw3Jb/x9xc2zIfO1AIYZkualTlKf 5Lb9bRAM90cPVdTH9S++TnGrTO0dPhSrdx1hFXDb6CWG8LVluUFbxeuDPYQK4c4Mw1As ltfaXV/3MqTjQSMh3BU611tmyZ5dTXmiiXEj/9vjkn29rgW9h8a/h3SmRkhOJhfThYU+ fQhkvt/m3NHKv8oEV2esl+1Sz2wrxJhhntHAxySVZxpMBnv96EoIswrxBvUhnwPLa74P fA4UH76tJL6GPBSD1VzHsxEsK9taE22db8rf21R9C59FopS1+jKI1pC9zQmP8XwkjMbS n+Ug== X-Gm-Message-State: AOAM531m3Q6IYH9xPGoEw4eSu3zms8+Crhib9afKQ81Omcil3FooNAqT uDEHWzNwWUkkeF3/2EqxFEzEDPRDnqfCWYlExUjPKA== X-Received: by 2002:a81:91d2:0:b0:2d6:af3d:c93 with SMTP id i201-20020a8191d2000000b002d6af3d0c93mr1481740ywg.467.1645111422161; Thu, 17 Feb 2022 07:23:42 -0800 (PST) MIME-Version: 1.0 References: <20220217140441.1218045-1-andrzej.hajda@intel.com> <20220217140441.1218045-3-andrzej.hajda@intel.com> In-Reply-To: <20220217140441.1218045-3-andrzej.hajda@intel.com> From: Eric Dumazet Date: Thu, 17 Feb 2022 07:23:31 -0800 Message-ID: Subject: Re: [PATCH 2/9] lib/ref_tracker: compact stacktraces before printing To: Andrzej Hajda Cc: LKML , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, netdev , Jani Nikula , Daniel Vetter , Lucas De Marchi , Chris Wilson , Dmitry Vyukov , Jakub Kicinski Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_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 Thu, Feb 17, 2022 at 6:05 AM Andrzej Hajda wrote: > > In cases references are taken alternately on multiple exec paths leak > report can grow substantially, sorting and grouping leaks by stack_handle > allows to compact it. > > Signed-off-by: Andrzej Hajda > Reviewed-by: Chris Wilson > --- > lib/ref_tracker.c | 35 +++++++++++++++++++++++++++-------- > 1 file changed, 27 insertions(+), 8 deletions(-) > > diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c > index 1b0c6d645d64a..0e9c7d2828ccb 100644 > --- a/lib/ref_tracker.c > +++ b/lib/ref_tracker.c > @@ -1,5 +1,6 @@ > // SPDX-License-Identifier: GPL-2.0-or-later > #include > +#include > #include > #include > #include > @@ -14,23 +15,41 @@ struct ref_tracker { > depot_stack_handle_t free_stack_handle; > }; > > +static int ref_tracker_cmp(void *priv, const struct list_head *a, const struct list_head *b) > +{ > + const struct ref_tracker *ta = list_entry(a, const struct ref_tracker, head); > + const struct ref_tracker *tb = list_entry(b, const struct ref_tracker, head); > + > + return ta->alloc_stack_handle - tb->alloc_stack_handle; > +} > + > void __ref_tracker_dir_print(struct ref_tracker_dir *dir, > unsigned int display_limit) > { > + unsigned int i = 0, count = 0; > struct ref_tracker *tracker; > - unsigned int i = 0; > + depot_stack_handle_t stack; > > lockdep_assert_held(&dir->lock); > > + if (list_empty(&dir->list)) > + return; > + > + list_sort(NULL, &dir->list, ref_tracker_cmp); What is going to be the cost of sorting a list with 1,000,000 items in it ? I just want to make sure we do not trade printing at most ~10 references (from netdev_wait_allrefs()) to a soft lockup :/ with no useful info if something went terribly wrong. I suggest that you do not sort a potential big list, and instead attempt to allocate an array of @display_limits 'struct stack_counts' I suspect @display_limits will always be kept to a reasonable value (less than 100 ?) struct stack_counts { depot_stack_handle_t stack_handle; unsigned int count; } Then, iterating the list and update the array (that you can keep sorted by ->stack_handle) Then after iterating, print the (at_most) @display_limits handles found in the temp array. > + > list_for_each_entry(tracker, &dir->list, head) { > - if (i < display_limit) { > - pr_err("leaked reference.\n"); > - if (tracker->alloc_stack_handle) > - stack_depot_print(tracker->alloc_stack_handle); > - i++; > - } else { > + if (i++ >= display_limit) > break; > - } > + if (!count++) > + stack = tracker->alloc_stack_handle; > + if (stack == tracker->alloc_stack_handle && > + !list_is_last(&tracker->head, &dir->list)) > + continue; > + > + pr_err("leaked %d references.\n", count); > + if (stack) > + stack_depot_print(stack); > + count = 0; > } > } > EXPORT_SYMBOL(__ref_tracker_dir_print); > -- > 2.25.1 >