Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp442235pxb; Thu, 17 Feb 2022 07:21:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPpRHYPWc2C1yEyCGRVAEOkIHM5m+9ytB2lx2hXLDF9/EYhld98cfTTnbENb/eIvAWWGYw X-Received: by 2002:a17:906:3bcb:b0:6cf:cf86:28d7 with SMTP id v11-20020a1709063bcb00b006cfcf8628d7mr2729077ejf.274.1645111306856; Thu, 17 Feb 2022 07:21:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645111306; cv=none; d=google.com; s=arc-20160816; b=ar7+aTS92NSB0kJG3hVoHK2IfSOVAjReu6zRUceMo6/IsU63IuLl3eKicObwQqRaZA OIaDkvsQyM0y2yCqBCd5XufkxF4Ra4wSsISqfjFk1jON0UHMlRovmK7xlc00MX7a2aIW zAnD2KggI4f8tMGIolV0qaRZ7af89FN0khgHPiDPJ6GyutVBNL3KbvkkDzsOm6FqJuhe 8C1T/9qoD027vSdL4r72Zx68hxku1aSVHRhBVpV0oVFbFnVrAMdinim9BeQRnco/yIQp gV8iHbK11HMN5FeMfvsF+oUWSCQVwaST8wPAsOTbhp8rurwrqlZ9XUGYbZaFWSq0EsMB 4bnA== 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=DJpIcWZtwZoOKqw1ZjmwtGspRP+D6d+B+IaFaOLEzvo=; b=jxLY0Cs4wO456gxuvlxzY+AFhnRSOtxKz9l7l2VwrFCF01N7jrSnb0NMxfUfCBEMYc hLq9Ar4T5ul43giEhaIWpt/2T7Wjn6tGae0oe2hhQlD0tTdfNlQqbJysGWYuIreJCk3P bozdhzmLCly+lG7JYd7JqjkVc4xzWUTTfG/dcmco3BcLUK+MjFIefaYlIEBNz7gRuHvW mwbdSXojg5x0c1Q0lQhU8xksDrBN/2dfbyn/U2PFiKZA6SVJSbGi9TaEMexP0h7nRNgO n7V380rXRmvrjM8xpEjgS7iS1E3O2kN46i4ZPkCKZ0ZfGEqPlVjFRNj9Lp023M7Abl3q u7ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Eu0DY79J; 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 l15si3935975edr.56.2022.02.17.07.20.55; Thu, 17 Feb 2022 07:21:46 -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=Eu0DY79J; 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 S241651AbiBQOF2 (ORCPT + 99 others); Thu, 17 Feb 2022 09:05:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241582AbiBQOFU (ORCPT ); Thu, 17 Feb 2022 09:05:20 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 448919D049; Thu, 17 Feb 2022 06:05:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645106706; x=1676642706; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+ysWCOx8Qe0FgPrL7lCitOlIRN7GA/uTSmYciHcbFL0=; b=Eu0DY79JluxUYCKICrFz7YC2DIxV0CqJ3e1/X7zShpA/g4mIkm12QYrI ehAkLBHTqgDhbwRa7mEhuV+7FTXRPIghziG7ORS7iIeDG7FXGSJOrrv3I IdfS80/R5kO5CoO/9wYLefOCVdp212HWLDdNEajmN5npP7gyqb9S7Tuuz UZZ30Q3irT7ZIlurUWAaHiKNMtij/YjQihe6jLSlB6G5KPPj08Ye5NJHQ fT7yZZx7K9KVVu4/GqwdO9OTP2S+FxOdPEDb1fe0DCn8Vyhoefo+jVEwE nDr7S8iOXApnvwxw2NaUXlQk96WlAqFfkucJNQboZFWbOCnF7T2j/q6H9 A==; X-IronPort-AV: E=McAfee;i="6200,9189,10260"; a="231501861" X-IronPort-AV: E=Sophos;i="5.88,376,1635231600"; d="scan'208";a="231501861" 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:06 -0800 X-IronPort-AV: E=Sophos;i="5.88,376,1635231600"; d="scan'208";a="530241205" 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:05:02 -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 3/9] lib/ref_tracker: __ref_tracker_dir_print improve printing Date: Thu, 17 Feb 2022 15:04:35 +0100 Message-Id: <20220217140441.1218045-4-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 To improve readibility of ref_tracker printing following changes have been performed: - added display name for ref_tracker_dir, - stack trace is printed indented, in the same printk call, - total number of references is printed every time, - print info about dropped references. Signed-off-by: Andrzej Hajda Reviewed-by: Chris Wilson --- include/linux/ref_tracker.h | 15 ++++++++++++--- lib/ref_tracker.c | 28 ++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/include/linux/ref_tracker.h b/include/linux/ref_tracker.h index b9c968a716483..090230e5b485d 100644 --- a/include/linux/ref_tracker.h +++ b/include/linux/ref_tracker.h @@ -15,18 +15,26 @@ struct ref_tracker_dir { refcount_t untracked; struct list_head list; /* List of active trackers */ struct list_head quarantine; /* List of dead trackers */ + char name[32]; #endif }; #ifdef CONFIG_REF_TRACKER -static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir, - unsigned int quarantine_count) + +// Temporary allow two and three arguments, until consumers are converted +#define ref_tracker_dir_init(_d, _q, args...) _ref_tracker_dir_init(_d, _q, ##args, #_d) +#define _ref_tracker_dir_init(_d, _q, _n, ...) __ref_tracker_dir_init(_d, _q, _n) + +static inline void __ref_tracker_dir_init(struct ref_tracker_dir *dir, + unsigned int quarantine_count, + const char *name) { INIT_LIST_HEAD(&dir->list); INIT_LIST_HEAD(&dir->quarantine); spin_lock_init(&dir->lock); dir->quarantine_avail = quarantine_count; refcount_set(&dir->untracked, 1); + strlcpy(dir->name, name, sizeof(dir->name)); stack_depot_init(); } @@ -47,7 +55,8 @@ int ref_tracker_free(struct ref_tracker_dir *dir, #else /* CONFIG_REF_TRACKER */ static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir, - unsigned int quarantine_count) + unsigned int quarantine_count, + ...) { } diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c index 0e9c7d2828ccb..943cff08110e3 100644 --- a/lib/ref_tracker.c +++ b/lib/ref_tracker.c @@ -1,4 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later + +#define pr_fmt(fmt) "ref_tracker: " fmt + #include #include #include @@ -7,6 +10,7 @@ #include #define REF_TRACKER_STACK_ENTRIES 16 +#define STACK_BUF_SIZE 1024 struct ref_tracker { struct list_head head; /* anchor into dir->list or dir->quarantine */ @@ -26,31 +30,43 @@ static int ref_tracker_cmp(void *priv, const struct list_head *a, const struct l void __ref_tracker_dir_print(struct ref_tracker_dir *dir, unsigned int display_limit) { - unsigned int i = 0, count = 0; + unsigned int i = 0, count = 0, total = 0; struct ref_tracker *tracker; depot_stack_handle_t stack; + char *sbuf; lockdep_assert_held(&dir->lock); if (list_empty(&dir->list)) return; + sbuf = kmalloc(STACK_BUF_SIZE, GFP_NOWAIT); + + list_for_each_entry(tracker, &dir->list, head) + ++total; + list_sort(NULL, &dir->list, ref_tracker_cmp); list_for_each_entry(tracker, &dir->list, head) { - 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; + if (i++ >= display_limit) + continue; - pr_err("leaked %d references.\n", count); - if (stack) - stack_depot_print(stack); + if (sbuf && !stack_depot_snprint(stack, sbuf, STACK_BUF_SIZE, 4)) + sbuf[0] = 0; + pr_err("%s@%pK has %d/%d users at\n%s\n", + dir->name, dir, count, total, sbuf); count = 0; } + if (i > display_limit) + pr_err("%s@%pK skipped %d/%d reports with %d unique stacks.\n", + dir->name, dir, count, total, i - display_limit); + + kfree(sbuf); } EXPORT_SYMBOL(__ref_tracker_dir_print); -- 2.25.1