Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4439369pxb; Mon, 21 Feb 2022 21:39:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzwHGYaqLa0Gu1oBmGx1AV2+pGXXvkYDUtuYNgEBEpi11/pW27cXap9k07iqDz6M8utlT7A X-Received: by 2002:a17:903:1c1:b0:14f:dad3:e7dd with SMTP id e1-20020a17090301c100b0014fdad3e7ddmr2456594plh.130.1645508387061; Mon, 21 Feb 2022 21:39:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645508387; cv=none; d=google.com; s=arc-20160816; b=0sUHrafD6A5cm+WpSfyvWzfwUDaDs2Lwqaqn99OH4s7wfFR+McC2XOtBB16mQ6LaMr wnIeHHmHtnfuEeWMwQBjPlLiT2upWoHc9kCHt4EL1AYJUOV5kOYNhmFmK1b3d39CSTwc XX6z/MnaJX4lCnhX4kY+k+FBf4IiekwyQQC0B5SOGKlr0KJDARZce8NyQDxqftV13fWR bAx2JGiZ/j0inL8Uwn/XD7LcXEtPAVpb/4DK+zatmFjqnl7ziDlXWung64BjD9OBo/gX 8xhv2KDcPVAfMfHGDjfEycL92Sw5dXYKAN7NcpH9U0XAPPPdr1MxY3ST5TnQE/Fo2QnT 2fbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sPdcaSFVX5RibpW3t7N5gy/LOvTohTD9jaf8vNLzIJA=; b=Uq/oO5H8BWOY1NBein0mjUiHx2wZT+79S32XyS2eYwQbfAdnCWh3veh8Am6bjoArFa Pa1+HcZ7ORkQ5KAzxKfDEf6kKBn/HGbi/rBeZ+i8S9rxn+i/0gSnyyNyC45gHdnAv2ti x4jP8vaRNHn4/T0XFOTgYgBEPv1RXIdI7qGSWCGew+/2S6zKwGUlIVLGkioyukXGmmJl WgtDyAY8J1hh1nLGM3Q7GjV+7Oe+Hr4TdYWEPU6k/rQXCDNmYPddZO2+4KO/Dl3GeRAx MrnBBaXFQCj3AQAG3jwA4JdJ0mmTJ6LqlWC6FG51j2Nx82YLO1+gyW8zvNYbcyT7K9fs NpPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eiuylxvo; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t14si21275606pgs.469.2022.02.21.21.39.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:39:47 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eiuylxvo; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7394B12A759; Mon, 21 Feb 2022 21:06:31 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236123AbiBUXSF (ORCPT + 99 others); Mon, 21 Feb 2022 18:18:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:32994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236111AbiBUXR7 (ORCPT ); Mon, 21 Feb 2022 18:17:59 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 469FA2458C; Mon, 21 Feb 2022 15:17:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645485455; x=1677021455; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hKcMNiYsgJWI/tUBCVHZc6qZhjqO+LBrBiPvfP3KNy0=; b=eiuylxvohcefrmbZjrk0rkrhxxfPkDJ59lV/fVVflPT4Cjy5LIDlcIJK KEnmHz3ErJ531cAkbuR+Ws4uqukpzy36mRmqjnoNMWnTIpmWZUE01e9ZS DkZ93H5ohJXb4q+xZcifFmsoGYOsgRTpo06v5BMN9SmAuKClvveB7pvxr CF7sl4852lyyAtg8c3n83f27Np4V9McEGxgNaSXDgECXP+cTCe4+0fNnG 2oYi5FQ30AaQ/wh95Rsa/AZiKQc/Je7UWaAWeFr9x0lMSofsPuB12zpoN bDYVVqzPNat3WZjI8W6n0l/6eHQHOCrzI2iSo7ez4/UDIj0Hmhv5FtONO Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10265"; a="251530372" X-IronPort-AV: E=Sophos;i="5.88,386,1635231600"; d="scan'208";a="251530372" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2022 15:17:34 -0800 X-IronPort-AV: E=Sophos;i="5.88,386,1635231600"; d="scan'208";a="638694396" Received: from lab-ah.igk.intel.com ([10.91.215.196]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2022 15:17:30 -0800 From: Andrzej Hajda To: linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, netdev Cc: Andrzej Hajda , Jani Nikula , Daniel Vetter , Lucas De Marchi , Chris Wilson , Eric Dumazet , Dmitry Vyukov , Jakub Kicinski Subject: [PATCH v2 2/9] lib/ref_tracker: compact stacktraces before printing Date: Tue, 22 Feb 2022 00:16:47 +0100 Message-Id: <20220221231705.1481059-6-andrzej.hajda@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220221231705.1481059-1-andrzej.hajda@intel.com> References: <20220221231705.1481059-1-andrzej.hajda@intel.com> MIME-Version: 1.0 Organization: Intel Technology Poland sp. z o.o. - ul. Slowackiego 173, 80-298 Gdansk - KRS 101882 - NIP 957-07-52-316 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 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); + 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