linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Improve dump_page() output for slab pages
@ 2024-05-22  7:46 Sukrit Bhatnagar
  2024-05-22  7:46 ` [PATCH 1/2] mm: printk: introduce new format %pGs for slab flags Sukrit Bhatnagar
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Sukrit Bhatnagar @ 2024-05-22  7:46 UTC (permalink / raw)
  To: Petr Mladek, Steven Rostedt, Andy Shevchenko, Rasmus Villemoes,
	Sergey Senozhatsky, Jonathan Corbet, Christoph Lameter,
	Pekka Enberg, David Rientjes, Joonsoo Kim, Andrew Morton,
	Vlastimil Babka, Roman Gushchin, Hyeonggon Yoo, Masami Hiramatsu,
	Mathieu Desnoyers, Matthew Wilcox (Oracle)
  Cc: linux-doc, linux-kernel, linux-mm, linux-trace-kernel,
	Sukrit.Bhatnagar

While using dump_page() on a range of pages, I noticed that there were some
PG_slab pages that were also showing as PG_anon pages, according to the
function output.

[    7.071985] page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x102768
[    7.072602] head: order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
[    7.073085] anon flags: 0x8000000000000840(slab|head|zone=2)
[    7.073777] raw: 8000000000000840 ffff8881000419c0 0000000000000000 dead000000000001

It was also printing the "page_type" field for slab pages, but that was fixed in
a very recent commit:
    8f790d0c7cfe (mm: improve dumping of mapcount and page_type)

Given that the slab pages cannot be mapped to userspace, this output seems
misleading.

In dump_page(), folio_test_anon() is used, which checks the "mapping" field.
But the struct slab was separated from struct page.
So accessing the mapping field through a struct page pointer, which actually
points to a struct slab, will result in garbage memory access and the PG_anon
test can return true.

It seems that other parts of the kernel MM make the check for slab before
checking for anon, but dump_page() is not doing that.

On the other hand, the struct slab has kmem_cache which maintains another set
of flags. It would be nice to have these flags added as a part of the debug
output, and to have a convenient way to print them.

(The long chain of pointer dereferences for cache flags looks messy, but I
assume it should be fine for a debug function.)

Sukrit Bhatnagar (2):
  mm: printk: introduce new format %pGs for slab flags
  mm: debug: print correct information for slab folios

 Documentation/core-api/printk-formats.rst |  2 +
 include/linux/slab.h                      |  5 ++
 include/trace/events/mmflags.h            | 67 +++++++++++++++++++++++
 lib/test_printf.c                         | 13 +++++
 lib/vsprintf.c                            | 22 ++++++++
 mm/debug.c                                | 12 +++-
 mm/internal.h                             |  1 +
 7 files changed, 121 insertions(+), 1 deletion(-)

-- 
2.34.1


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

end of thread, other threads:[~2024-05-27 11:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-22  7:46 [PATCH 0/2] Improve dump_page() output for slab pages Sukrit Bhatnagar
2024-05-22  7:46 ` [PATCH 1/2] mm: printk: introduce new format %pGs for slab flags Sukrit Bhatnagar
2024-05-22 20:25   ` kernel test robot
2024-05-22  7:46 ` [PATCH 2/2] mm: debug: print correct information for slab folios Sukrit Bhatnagar
2024-05-22 12:32   ` Matthew Wilcox
2024-05-27 10:46     ` Sukrit.Bhatnagar
2024-05-22 14:11 ` [PATCH 0/2] Improve dump_page() output for slab pages Matthew Wilcox
2024-05-27 10:48   ` Sukrit.Bhatnagar

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