linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] mm/slub: endless "No data" printing for alloc/free_traces attribute
@ 2021-11-17 19:39 Gerald Schaefer
  2021-11-17 19:39 ` [RFC PATCH 1/1] mm/slub: fix " Gerald Schaefer
  2021-11-19  9:43 ` [RFC PATCH 0/1] mm/slub: endless "No data" printing for alloc/free_traces attribute Vlastimil Babka
  0 siblings, 2 replies; 15+ messages in thread
From: Gerald Schaefer @ 2021-11-17 19:39 UTC (permalink / raw)
  To: Faiyaz Mohammed
  Cc: linux-mm, LKML, linux-s390, Vlastimil Babka, Greg Kroah-Hartman,
	Andrew Morton

Steffen reported endless printing of "No data" when reading from
alloc/free_traces attribute in /sys/kernel/debug/slab/, at least on
s390, but I don't see how this could be arch-specific.

I must admit that I am completely confused by the seq_file interface
in general, but even more so from this specific implementation.

First I suspected a bug in slab_debugfs_next(), because of its very
weird usage of the *v parameter, which seems totally useless, but not
responsible for this bug. Still, out of curiosity, does anybody have a
clue why it is done this way, and not e.g. like this?

diff --git a/mm/slub.c b/mm/slub.c
index f7368bfffb7a..0b1832b16f5b 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -6105,10 +6105,9 @@ static void *slab_debugfs_next(struct seq_file *seq, void *v, loff_t *ppos)
 {
        struct loc_track *t = seq->private;

-       v = ppos;
        ++*ppos;
        if (*ppos <= t->count)
-               return v;
+               return ppos;

        return NULL;
 }

Anyway, NULL is returned for the "*ppos > t->count" case, as described
in Documentation/filesystems/seq_file.rst, for "if the sequence is
complete", so that should be ok, but still very confusing. Unfortunately,
the documentation does not seem to explain that *v parameter at all, or
I missed it, but in this case here it seems to be simply ignored and
misused w/o any need.

The documentation does mention that "in most cases the start() function
should check for a "past end of file" condition and return NULL if need
be". So I just added a similar check to slab_debugfs_start() and return
NULL for "*ppos > t->count", which apparently fixed the bug. "No data"
is now only printed once, like it was before commit 64dd68497be7
("mm: slub: move sysfs slab alloc/free interfaces to debugfs").

However, since I obviously do not really understand the seq_file
documentation, and also not the alloc/free_traces stuff in general,
that fix might be wrong or incomplete. Comments are welcome.

Gerald Schaefer (1):
  mm/slub: fix endless "No data" printing for alloc/free_traces
    attribute

 mm/slub.c | 5 +++++
 1 file changed, 5 insertions(+)

-- 
2.25.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-11-29 14:28 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17 19:39 [RFC PATCH 0/1] mm/slub: endless "No data" printing for alloc/free_traces attribute Gerald Schaefer
2021-11-17 19:39 ` [RFC PATCH 1/1] mm/slub: fix " Gerald Schaefer
2021-11-19 10:41   ` Vlastimil Babka
2021-11-19 19:59     ` Gerald Schaefer
2021-11-22 15:02       ` Vlastimil Babka
2021-11-22 20:14         ` Gerald Schaefer
2021-11-22 20:33           ` Gerald Schaefer
2021-11-23 14:19             ` Vlastimil Babka
2021-11-25 16:13               ` Gerald Schaefer
2021-11-25 20:12                 ` Gerald Schaefer
2021-11-25 22:00                   ` Vlastimil Babka
2021-11-26 17:11                     ` Gerald Schaefer
2021-11-26 17:18                     ` [PATCH] mm/slub: fix endianness bug for alloc/free_traces attributes Gerald Schaefer
2021-11-29 14:26                       ` Vlastimil Babka
2021-11-19  9:43 ` [RFC PATCH 0/1] mm/slub: endless "No data" printing for alloc/free_traces attribute Vlastimil Babka

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