netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrzej Hajda <andrzej.hajda@intel.com>
To: Eric Dumazet <edumazet@google.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	<intel-gfx@lists.freedesktop.org>,
	<dri-devel@lists.freedesktop.org>,
	netdev <netdev@vger.kernel.org>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	Daniel Vetter <daniel@ffwll.ch>,
	Lucas De Marchi <lucas.demarchi@intel.com>,
	Chris Wilson <chris.p.wilson@intel.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>
Subject: Re: [PATCH 3/9] lib/ref_tracker: __ref_tracker_dir_print improve printing
Date: Fri, 18 Feb 2022 11:11:24 +0100	[thread overview]
Message-ID: <be54417d-3fe2-9af6-a1e9-85d516b7fd87@intel.com> (raw)
In-Reply-To: <CANn89iJ3W3ioVUaBJikCpFdCa9o_APpqyb0FmK9AmYPtgOeC7w@mail.gmail.com>



On 17.02.2022 16:38, Eric Dumazet wrote:
> On Thu, Feb 17, 2022 at 6:05 AM Andrzej Hajda <andrzej.hajda@intel.com> 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 <andrzej.hajda@intel.com>
>> Reviewed-by: Chris Wilson <chris.p.wilson@intel.com>
>> ---
>>   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 <linux/export.h>
>>   #include <linux/list_sort.h>
>>   #include <linux/ref_tracker.h>
>> @@ -7,6 +10,7 @@
>>   #include <linux/stackdepot.h>
>>
>>   #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.

Skipped is already in 'count', but you are right with double looping> I 
can count total in the same loop,
just forgot to merge loops during code evolution.
Will be fixed.

Regards
Andrzej

> 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
>>


  reply	other threads:[~2022-02-18 10:11 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-17 14:04 [PATCH 0/9] drm/i915: use ref_tracker library for tracking wakerefs Andrzej Hajda
2022-02-17 14:04 ` [PATCH 1/9] lib/ref_tracker: add unlocked leak print helper Andrzej Hajda
2022-02-17 14:04 ` [PATCH 2/9] lib/ref_tracker: compact stacktraces before printing Andrzej Hajda
2022-02-17 15:23   ` Eric Dumazet
2022-02-17 15:25     ` Eric Dumazet
2022-02-18 10:54     ` Andrzej Hajda
2022-02-18 13:01       ` Eric Dumazet
2022-02-17 14:04 ` [PATCH 3/9] lib/ref_tracker: __ref_tracker_dir_print improve printing Andrzej Hajda
2022-02-17 15:38   ` Eric Dumazet
2022-02-18 10:11     ` Andrzej Hajda [this message]
2022-02-17 14:04 ` [PATCH 4/9] lib/ref_tracker: add printing to memory buffer Andrzej Hajda
2022-02-17 14:04 ` [PATCH 5/9] lib/ref_tracker: improve allocation flags Andrzej Hajda
2022-02-17 15:13   ` Eric Dumazet
2022-02-18 10:28     ` Andrzej Hajda
2022-02-18 13:05       ` Eric Dumazet
2022-02-17 14:04 ` [PATCH 6/9] drm/i915: Separate wakeref tracking Andrzej Hajda
2022-02-17 14:48   ` [Intel-gfx] " Ville Syrjälä
2022-02-18 10:32     ` Andrzej Hajda
2022-02-17 14:04 ` [PATCH 7/9] drm/i915: Track leaked gt->wakerefs Andrzej Hajda
2022-02-17 14:04 ` [PATCH 8/9] drm/i915: Correct type of wakeref variable Andrzej Hajda
2022-02-17 14:04 ` [PATCH 9/9] drm/i915: replace Intel internal tracker with kernel core ref_tracker Andrzej Hajda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=be54417d-3fe2-9af6-a1e9-85d516b7fd87@intel.com \
    --to=andrzej.hajda@intel.com \
    --cc=chris.p.wilson@intel.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=dvyukov@google.com \
    --cc=edumazet@google.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).