2023-06-02 10:35:37

by Andrzej Hajda

[permalink] [raw]
Subject: [PATCH v9 0/4] drm/i915: use ref_tracker library for tracking wakerefs

Hi Jakub,

This is reviewed series of ref_tracker patches, ready to merge
via network tree, rebased on net-next/main.
i915 patches will be merged later via intel-gfx tree.

Signed-off-by: Andrzej Hajda <[email protected]>
---
Changes in v9:
- removed i915 patches, just to merge network part
- added r-b-s
- Link to v8: https://lore.kernel.org/r/[email protected]

Changes in v8:
- addressed comments from Eric, Zhou and CI, thanks,
- added ref_tracker_dir_init name argument to all callers in one patch
- moved intel_wakeref_tracker_show to *.c
- s/intel_wakeref_tracker_show/intel_ref_tracker_show/
- removed 'default n' from Kconfig
- changed strlcpy to strscpy,
- removed assignement from if condition,
- removed long lines from patch description
- added tags
- Link to v7: https://lore.kernel.org/r/[email protected]

Changes in v7:
- removed 8th patch (hold wakeref), as it was already merged
- added tags (thx Andi)
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- rebased to solve minor conflict and allow CI testing
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5 (thx Andi for review):
- use *_locked convention instead of __*,
- improved commit messages,
- re-worked i915 patches, squashed separation and conversion patches,
- added tags,
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- split "Separate wakeref tracking" to smaller parts
- fixed typos,
- Link to v1-v3: https://patchwork.freedesktop.org/series/100327/

---
Andrzej Hajda (4):
lib/ref_tracker: add unlocked leak print helper
lib/ref_tracker: improve printing stats
lib/ref_tracker: add printing to memory buffer
lib/ref_tracker: remove warnings in case of allocation failure

include/linux/ref_tracker.h | 25 ++++++-
lib/ref_tracker.c | 179 ++++++++++++++++++++++++++++++++++++--------
lib/test_ref_tracker.c | 2 +-
net/core/dev.c | 2 +-
net/core/net_namespace.c | 4 +-
5 files changed, 176 insertions(+), 36 deletions(-)
---
base-commit: 23fcb62bc19c37adb72a585d5dc702ac55b74fb1
change-id: 20230224-track_gt-1b3da8bdacd7

Best regards,
--
Andrzej Hajda <[email protected]>



2023-06-02 10:35:52

by Andrzej Hajda

[permalink] [raw]
Subject: [PATCH v9 3/4] lib/ref_tracker: add printing to memory buffer

Similar to stack_(depot|trace)_snprint the patch
adds helper to printing stats to memory buffer.
It will be helpful in case of debugfs.

Signed-off-by: Andrzej Hajda <[email protected]>
Reviewed-by: Andi Shyti <[email protected]>
Reviewed-by: Eric Dumazet <[email protected]>
---
include/linux/ref_tracker.h | 8 +++++++
lib/ref_tracker.c | 56 ++++++++++++++++++++++++++++++++++++++-------
2 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/include/linux/ref_tracker.h b/include/linux/ref_tracker.h
index 19a69e7809d6c1..8eac4f3d52547c 100644
--- a/include/linux/ref_tracker.h
+++ b/include/linux/ref_tracker.h
@@ -46,6 +46,8 @@ void ref_tracker_dir_print_locked(struct ref_tracker_dir *dir,
void ref_tracker_dir_print(struct ref_tracker_dir *dir,
unsigned int display_limit);

+int ref_tracker_dir_snprint(struct ref_tracker_dir *dir, char *buf, size_t size);
+
int ref_tracker_alloc(struct ref_tracker_dir *dir,
struct ref_tracker **trackerp, gfp_t gfp);

@@ -74,6 +76,12 @@ static inline void ref_tracker_dir_print(struct ref_tracker_dir *dir,
{
}

+static inline int ref_tracker_dir_snprint(struct ref_tracker_dir *dir,
+ char *buf, size_t size)
+{
+ return 0;
+}
+
static inline int ref_tracker_alloc(struct ref_tracker_dir *dir,
struct ref_tracker **trackerp,
gfp_t gfp)
diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c
index 2ffe79c90c1771..cce4614b07940f 100644
--- a/lib/ref_tracker.c
+++ b/lib/ref_tracker.c
@@ -62,8 +62,27 @@ ref_tracker_get_stats(struct ref_tracker_dir *dir, unsigned int limit)
return stats;
}

-void ref_tracker_dir_print_locked(struct ref_tracker_dir *dir,
- unsigned int display_limit)
+struct ostream {
+ char *buf;
+ int size, used;
+};
+
+#define pr_ostream(stream, fmt, args...) \
+({ \
+ struct ostream *_s = (stream); \
+\
+ if (!_s->buf) { \
+ pr_err(fmt, ##args); \
+ } else { \
+ int ret, len = _s->size - _s->used; \
+ ret = snprintf(_s->buf + _s->used, len, pr_fmt(fmt), ##args); \
+ _s->used += min(ret, len); \
+ } \
+})
+
+static void
+__ref_tracker_dir_pr_ostream(struct ref_tracker_dir *dir,
+ unsigned int display_limit, struct ostream *s)
{
struct ref_tracker_dir_stats *stats;
unsigned int i = 0, skipped;
@@ -77,8 +96,8 @@ void ref_tracker_dir_print_locked(struct ref_tracker_dir *dir,

stats = ref_tracker_get_stats(dir, display_limit);
if (IS_ERR(stats)) {
- pr_err("%s@%pK: couldn't get stats, error %pe\n",
- dir->name, dir, stats);
+ pr_ostream(s, "%s@%pK: couldn't get stats, error %pe\n",
+ dir->name, dir, stats);
return;
}

@@ -88,19 +107,27 @@ void ref_tracker_dir_print_locked(struct ref_tracker_dir *dir,
stack = stats->stacks[i].stack_handle;
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,
- stats->stacks[i].count, stats->total, sbuf);
+ pr_ostream(s, "%s@%pK has %d/%d users at\n%s\n", dir->name, dir,
+ stats->stacks[i].count, stats->total, sbuf);
skipped -= stats->stacks[i].count;
}

if (skipped)
- pr_err("%s@%pK skipped reports about %d/%d users.\n",
- dir->name, dir, skipped, stats->total);
+ pr_ostream(s, "%s@%pK skipped reports about %d/%d users.\n",
+ dir->name, dir, skipped, stats->total);

kfree(sbuf);

kfree(stats);
}
+
+void ref_tracker_dir_print_locked(struct ref_tracker_dir *dir,
+ unsigned int display_limit)
+{
+ struct ostream os = {};
+
+ __ref_tracker_dir_pr_ostream(dir, display_limit, &os);
+}
EXPORT_SYMBOL(ref_tracker_dir_print_locked);

void ref_tracker_dir_print(struct ref_tracker_dir *dir,
@@ -114,6 +141,19 @@ void ref_tracker_dir_print(struct ref_tracker_dir *dir,
}
EXPORT_SYMBOL(ref_tracker_dir_print);

+int ref_tracker_dir_snprint(struct ref_tracker_dir *dir, char *buf, size_t size)
+{
+ struct ostream os = { .buf = buf, .size = size };
+ unsigned long flags;
+
+ spin_lock_irqsave(&dir->lock, flags);
+ __ref_tracker_dir_pr_ostream(dir, 16, &os);
+ spin_unlock_irqrestore(&dir->lock, flags);
+
+ return os.used;
+}
+EXPORT_SYMBOL(ref_tracker_dir_snprint);
+
void ref_tracker_dir_exit(struct ref_tracker_dir *dir)
{
struct ref_tracker *tracker, *n;

--
2.34.1


2023-06-02 10:36:06

by Andrzej Hajda

[permalink] [raw]
Subject: [PATCH v9 4/4] lib/ref_tracker: remove warnings in case of allocation failure

Library can handle allocation failures. To avoid allocation warnings
__GFP_NOWARN has been added everywhere. Moreover GFP_ATOMIC has been
replaced with GFP_NOWAIT in case of stack allocation on tracker free
call.

Signed-off-by: Andrzej Hajda <[email protected]>
Reviewed-by: Andi Shyti <[email protected]>
Reviewed-by: Eric Dumazet <[email protected]>
---
lib/ref_tracker.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/ref_tracker.c b/lib/ref_tracker.c
index cce4614b07940f..cf5609b1ca7936 100644
--- a/lib/ref_tracker.c
+++ b/lib/ref_tracker.c
@@ -189,7 +189,7 @@ int ref_tracker_alloc(struct ref_tracker_dir *dir,
unsigned long entries[REF_TRACKER_STACK_ENTRIES];
struct ref_tracker *tracker;
unsigned int nr_entries;
- gfp_t gfp_mask = gfp;
+ gfp_t gfp_mask = gfp | __GFP_NOWARN;
unsigned long flags;

WARN_ON_ONCE(dir->dead);
@@ -237,7 +237,8 @@ int ref_tracker_free(struct ref_tracker_dir *dir,
return -EEXIST;
}
nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 1);
- stack_handle = stack_depot_save(entries, nr_entries, GFP_ATOMIC);
+ stack_handle = stack_depot_save(entries, nr_entries,
+ GFP_NOWAIT | __GFP_NOWARN);

spin_lock_irqsave(&dir->lock, flags);
if (tracker->dead) {

--
2.34.1


2023-06-05 22:58:52

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH v9 0/4] drm/i915: use ref_tracker library for tracking wakerefs

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <[email protected]>:

On Fri, 02 Jun 2023 12:21:32 +0200 you wrote:
> Hi Jakub,
>
> This is reviewed series of ref_tracker patches, ready to merge
> via network tree, rebased on net-next/main.
> i915 patches will be merged later via intel-gfx tree.
>
> Signed-off-by: Andrzej Hajda <[email protected]>
>
> [...]

Here is the summary with links:
- [v9,1/4] lib/ref_tracker: add unlocked leak print helper
https://git.kernel.org/netdev/net-next/c/7a113ff63559
- [v9,2/4] lib/ref_tracker: improve printing stats
https://git.kernel.org/netdev/net-next/c/b6d7c0eb2dcb
- [v9,3/4] lib/ref_tracker: add printing to memory buffer
https://git.kernel.org/netdev/net-next/c/227c6c832303
- [v9,4/4] lib/ref_tracker: remove warnings in case of allocation failure
https://git.kernel.org/netdev/net-next/c/acd8f0e5d727

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



2023-06-05 23:01:09

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH v9 0/4] drm/i915: use ref_tracker library for tracking wakerefs

On Fri, 02 Jun 2023 12:21:32 +0200 Andrzej Hajda wrote:
> This is reviewed series of ref_tracker patches, ready to merge
> via network tree, rebased on net-next/main.
> i915 patches will be merged later via intel-gfx tree.

FWIW I'll try to merge these on top of the -rc4 tag so
with a bit of luck you should be able to cross merge cleanly
into another -next tree.

2023-06-06 06:28:22

by Andrzej Hajda

[permalink] [raw]
Subject: Re: [PATCH v9 0/4] drm/i915: use ref_tracker library for tracking wakerefs



On 06.06.2023 00:33, Jakub Kicinski wrote:
> On Fri, 02 Jun 2023 12:21:32 +0200 Andrzej Hajda wrote:
>> This is reviewed series of ref_tracker patches, ready to merge
>> via network tree, rebased on net-next/main.
>> i915 patches will be merged later via intel-gfx tree.
> FWIW I'll try to merge these on top of the -rc4 tag so
> with a bit of luck you should be able to cross merge cleanly
> into another -next tree.

Thanks.

Regards
Andrzej