Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp735396pxb; Thu, 17 Feb 2022 13:37:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0yiRHXvZbEkHJeL4xqNEza9aQM/pceq2SDFNaWrZjjp3za+i8VZ+7rYFX7of10/euUyDC X-Received: by 2002:a17:903:2288:b0:14d:7f2d:a39d with SMTP id b8-20020a170903228800b0014d7f2da39dmr4593426plh.80.1645133823627; Thu, 17 Feb 2022 13:37:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645133823; cv=none; d=google.com; s=arc-20160816; b=PNyS2ZZQVeK87xogVRlqJtwfrFtC9v12CDxFiQpZ2M5/Ca0GeOqFK3xg7S8v3cG4Qg DiaZcoKl2kjplulGMX1/OR4uIBFUx+ZRCErx9cZcOuRiic6mUZB7drQ9jxc5C563tvjV dnh6sEvo28W0gLHVHEV4or3jyFOuJAZo4OMyXHn1Xm2PvZavTGQh31BVHybZ616PpPUJ A1nbYKv/AvvjVhnyU3AOJpJzORKjTsdjQdA4A2MjRUQt6+YuW24/fXraQw5/oZyj9adJ bCUDF/LChLMEs+FIbphCJr4ZTTtlzCGlt+epSfPLOlXWMt2p9FObLxlIHSAtaG9QQ6sb GGcA== 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=S15ghz7B2c6GXi0u4t2rIQbTK1XmfLBOxmtqat/hl15KufnopOne9AMl8nSisffwdi a0bk2xQQJ3+vucd4jCraT9T/JOZEHQk7MH/TR+6aRaMUNBflkOb5iq4U7Qy/WUm4LIXq vaRvW+0Fbu73wY7XtrJ0CYeREeZBWVzu3gXF++vJjQ8svGtSxrSlI5I4leUBpO6e3x8u C1bNAtX1nA4zraq5LNss3WzTj9Z5M3de+hcIPb4BE+923+75vgzmtEWSZ+gY4uw58OaC b0CeSMT00XjApu+LfMWTbclZGwMFjG36THBnkCU7/vUDj/+J7D7VZmWUy6r5iSEa1hXC r/xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QZgoHPTk; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5si8828149pgq.736.2022.02.17.13.36.47; Thu, 17 Feb 2022 13:37:03 -0800 (PST) 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=@intel.com header.s=Intel header.b=QZgoHPTk; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241626AbiBQOFZ (ORCPT + 99 others); Thu, 17 Feb 2022 09:05:25 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229938AbiBQOFR (ORCPT ); Thu, 17 Feb 2022 09:05:17 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00943BD2C3; Thu, 17 Feb 2022 06:05:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645106702; x=1676642702; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hKcMNiYsgJWI/tUBCVHZc6qZhjqO+LBrBiPvfP3KNy0=; b=QZgoHPTkcBhTw8KIvy0qtpJQsngBiJMW2xwU9/m4NaPm8P47m5Mz6C9f u5jakao1vbXs/sq6yd0QBYusWvDbPEqc+7xtPDEOBXuMg/MgFR1AxLvVd WnnhoQlJ2a+ak7D8QNx07L+TmkU9a6vZQoim0NZCLxjBVoA1nEcvml8jL qA8GLbyYfOmm6tJOLWb+Rtqyu3t+ZjhNBquY5zip0INTDAzQt/N2dYezq GD0l2E1b+R7NhxPPrZgFwAwlJ0otRWSPI9Nh8DzNqb5DHkdsWeBV5KQtU tE7fHSOlBAnJ2NxQYWaXPI0zu1NZ4Y2kTxRBXwpZ0imM21VOxK4O2/C5r w==; X-IronPort-AV: E=McAfee;i="6200,9189,10260"; a="231501843" X-IronPort-AV: E=Sophos;i="5.88,376,1635231600"; d="scan'208";a="231501843" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 06:05:02 -0800 X-IronPort-AV: E=Sophos;i="5.88,376,1635231600"; d="scan'208";a="530241142" Received: from lab-ah.igk.intel.com ([10.91.215.196]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 06:04:59 -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 2/9] lib/ref_tracker: compact stacktraces before printing Date: Thu, 17 Feb 2022 15:04:34 +0100 Message-Id: <20220217140441.1218045-3-andrzej.hajda@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220217140441.1218045-1-andrzej.hajda@intel.com> References: <20220217140441.1218045-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=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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