Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp683017pxb; Thu, 17 Feb 2022 12:20:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzikn/POhheZ6mQsFuCqB0gitwY7w+LRPiwTmpwZ6xaiu3wnh2Pq+/SM3dkgGrtrSqNHb1V X-Received: by 2002:a63:4913:0:b0:373:cf7f:6cd1 with SMTP id w19-20020a634913000000b00373cf7f6cd1mr769147pga.296.1645129240577; Thu, 17 Feb 2022 12:20:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645129240; cv=none; d=google.com; s=arc-20160816; b=aK8TTSW94d70gsimYU9fW0AW8y7dJaY7lj0pKynCeMD9roWW8IKWcaGk8+ngEyxDEG l83J9VxyUYFH7Lnm1Mql8AAgTDMRcrb4Iv8IplC9HYsHusB3IzqjMfboQDZKjmLDopLv EkOik4O3BdrCdE05Xduoj2fEaDzZA44BtYEVq7GvG+9qDRRXMtG9kVJfPAYbQlt27zd2 Q79RJmJe+YaVdvpuv2E/NYAgPAmdfSJ9xgSPvnxQUZwlwPx6HVVIfALy07r972ADzixS zbSvsKGcvwoUzp3Jo1jqIjySPwfvF/xxnWiHzYhAUyCraShE4HdWhhIauNbH4yD7Dtpz zf/Q== 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=4hk+t9STd/ohkaxKw6p1lqAArc9u/s8Q8z69HF6aLfE=; b=twzfsj9afFLufMWc4rl4a2KalGyqoKwu6riqE5I2h7tgv5WAiIXjRzjbpz/oqQW8PX tcs3yDrMMvfdI+b42vT8F1X4xjp8D3ikYaRSoOwrvjXPBU0MQajFnbvZQX3wnTlOAcyx 5qpylCMN5/4Hs8TWywy5qreqPB6zlB1ZiG9/d6ozfuH4UkdVEBYAlsKqoCQe2U1vYle2 vYry1rop9MgQYu3ZHQF24jlFqWy+SBxY9YMDJM9uUFnS27zYdxnfv3lRN8K9jOYNpsVE EjBnTKxA4aM6159OTQTGSwhwZi7dB3X9UdMDLHpeSIFOfXWv4yk39zEg9WN6EWRpuXTF GZJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dBmphIBT; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id na2si1784255pjb.134.2022.02.17.12.20.24; Thu, 17 Feb 2022 12:20:40 -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=@google.com header.s=20210112 header.b=dBmphIBT; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242578AbiBQPjA (ORCPT + 99 others); Thu, 17 Feb 2022 10:39:00 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233981AbiBQPi6 (ORCPT ); Thu, 17 Feb 2022 10:38:58 -0500 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C304A2B2E11 for ; Thu, 17 Feb 2022 07:38:43 -0800 (PST) Received: by mail-yb1-xb2a.google.com with SMTP id e140so13798638ybh.9 for ; Thu, 17 Feb 2022 07:38: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=4hk+t9STd/ohkaxKw6p1lqAArc9u/s8Q8z69HF6aLfE=; b=dBmphIBTKJBbLyOdiwSe3VTvN12HETj4nWMgwdynneUZO8D6nWfrB0f/GBiBA+3Bxp KF+/tApD9j+7MjLO3Ima8cJs2VlPrUd+bMIOWVDaUKtszaSMlEIYrw48DABbvIYL682H LD3Re5r4ZXG6jQyafj0JwoDngXYlOewmr0UptZZQLVEVKpRXF4dO5Q3Fr9x91aj6oUXd 96t9ShajgD7echn30nWeEsEzrNMv7O0d1/NniWqwsF6bsxZCyVn/SdWtu7ldYpWcF8mJ knB2bt7Gwyyutk12bI8gZwTL++yweig6tJrG/t4tq1ZgywAGwg/HukZsUJV77AyM7/eP Sv3g== 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=4hk+t9STd/ohkaxKw6p1lqAArc9u/s8Q8z69HF6aLfE=; b=AH0LlJSpGOafRyrTYgOx4TUicRIa3Yg+DT65s91NAVfxbajthGAug45L70r+QPMKx0 0a1WYEpekhHaTt1/D3vk4b/0H/+Lu4FXRWrDH5GbUq5BGe9rpmp1YQdcv7b8Rk/zqBF5 8IU/3Y7ln9VvhHs0o7Zt7YIUhZ3K7T9UCfnVLxCrIiI+J3/03qQ/xKOZCliQd6kxtG+L lnAhUWaEqc1bbDRJLeNwP872lMEYVtF+OO5SeOuYaJkU1KpMi1svNR4U6Zn1Vb1PKPtV QIPXg1McGehuCLuAgKQYSdyswDsMbE1dSLBvtXc3VTswoUgQW6oyNcmpMdFatkfYG52r 4wQQ== X-Gm-Message-State: AOAM5329uuod/MB7BdZ7/WLEJg0aE1txfwsyTP8WuRRYIbFMumYhIID1 d43KYS8jftflO8YCPp1NwBm8n6r+9dhgCtYtSV/bHQ== X-Received: by 2002:a25:a28d:0:b0:623:fa1b:3eb7 with SMTP id c13-20020a25a28d000000b00623fa1b3eb7mr2918043ybi.387.1645112322577; Thu, 17 Feb 2022 07:38:42 -0800 (PST) MIME-Version: 1.0 References: <20220217140441.1218045-1-andrzej.hajda@intel.com> <20220217140441.1218045-4-andrzej.hajda@intel.com> In-Reply-To: <20220217140441.1218045-4-andrzej.hajda@intel.com> From: Eric Dumazet Date: Thu, 17 Feb 2022 07:38:31 -0800 Message-ID: Subject: Re: [PATCH 3/9] lib/ref_tracker: __ref_tracker_dir_print improve 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=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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: > > 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; Another iteration over a potential long list. You can count the @skipped number in the following iteration just fine. int skipped = 0; > + > 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) skipped++; > + 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 >