From patchwork Thu Feb 17 14:04:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 12750212 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82C3CC433FE for ; Thu, 17 Feb 2022 14:05:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 45DDA10EB6C; Thu, 17 Feb 2022 14:05:04 +0000 (UTC) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 09E2C10EB6C; Thu, 17 Feb 2022 14:05:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645106703; x=1676642703; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hKcMNiYsgJWI/tUBCVHZc6qZhjqO+LBrBiPvfP3KNy0=; b=Rdr7oD5fucqmvCKf9n+x03YsThJVn6pxYB0EF0S5ndi2Lu9R7m7DirYy 1Ah7Oeyy/mX5l3XOr+8AXgmYPzf2/yvmlh6BCSBPFstTH0hFqcCAVtX6n rsgLph2pus4qRzT+NLlULMB+MpnDmEz5M3EPtyUP7lkZoxX272fkMOKQo E+nAVZtPMPHuk9V4sXUW1DVURDP5eRRAj7Yq4yK4mtE1eHQ7VoHKjMNB7 EZqOlaeuMkZVT2wnKbOuJik5GUD60uARFqLS51bheyr6FYyHgDuFu1PpO NLmhAFNYbOFkfwjNccH6xLqX957giYdkrSJcmQ/zgP2xUqbDkgn/FSQbA Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10260"; a="230840810" X-IronPort-AV: E=Sophos;i="5.88,376,1635231600"; d="scan'208";a="230840810" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.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 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 Subject: [Intel-gfx] [PATCH 2/9] lib/ref_tracker: compact stacktraces before printing X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrzej Hajda , Lucas De Marchi , Chris Wilson , Eric Dumazet , Jakub Kicinski , Dmitry Vyukov Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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);