linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sukrit Bhatnagar <Sukrit.Bhatnagar@sony.com>
To: Petr Mladek <pmladek@suse.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Hyeonggon Yoo <42.hyeyoo@gmail.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org,
	Sukrit.Bhatnagar@sony.com
Subject: [PATCH 0/2] Improve dump_page() output for slab pages
Date: Wed, 22 May 2024 16:46:27 +0900	[thread overview]
Message-ID: <20240522074629.2420423-1-Sukrit.Bhatnagar@sony.com> (raw)

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



             reply	other threads:[~2024-05-22  7:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-22  7:46 Sukrit Bhatnagar [this message]
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

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=20240522074629.2420423-1-Sukrit.Bhatnagar@sony.com \
    --to=sukrit.bhatnagar@sony.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=cl@linux.com \
    --cc=corbet@lwn.net \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=penberg@kernel.org \
    --cc=pmladek@suse.com \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.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