From: Harry Yoo <harry.yoo@oracle.com>
To: vbabka@suse.cz, rientjes@google.com, cl@gentwo.org,
akpm@linux-foundation.org
Cc: roman.gushchin@linux.dev, willy@infradead.org,
linux-mm@kvack.org, Harry Yoo <harry.yoo@oracle.com>
Subject: [PATCH] mm/slab: fix folio_test_{anon,ksm}() false positive on slabs
Date: Mon, 9 Jun 2025 22:27:23 +0900 [thread overview]
Message-ID: <20250609132723.13118-1-harry.yoo@oracle.com> (raw)
When running tools/mm/page-types (with flags, page-counts, MB omitted),
it reports that some slabs have KPF_ANON and KPF_KSM set:
$ sudo ./page-types | grep slab
_______S___________________________________ slab
_______S____a________x_____________________ slab,anonymous,ksm
This is unexpected, as slab memory should never be treated as anonymous
memory. This is because slab->slabs shares the same offset as
page->mapping and setting the lower two bits of ->slabs field means
folio_test_anon() and folio_test_ksm() will return true on the slab:
[ field ] [ offset ] [ size ]
page->mapping 24 8
page->lru 8 16
slab->next 16 8
slab->slabs 24 4
Reorder ->slabs and ->next, so that the layout will be:
slab->slabs 16 4
slab->next 24 8
After reordering, slab->slabs shares its offset with page->lru.prev,
which is not a problem. slab->next now shares the offset with
page->mapping, but that's fine, as a slab is double-word aligned.
With the change, the nonsense slab pages disappear:
$ sudo ./page-types | grep slab
_______S___________________________________ slab
Fixes: 130d4df57390 ("mm/sl[au]b: rearrange struct slab fields to allow larger rcu_head")
Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
---
No Cc: stable because we don't usually check folio_test_anon() on slabs.
mm/slab.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/slab.h b/mm/slab.h
index 05a21dc796e0..2e7064f7709e 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -59,8 +59,8 @@ struct slab {
struct list_head slab_list;
#ifdef CONFIG_SLUB_CPU_PARTIAL
struct {
- struct slab *next;
int slabs; /* Nr of slabs left */
+ struct slab *next;
};
#endif
};
--
2.43.0
next reply other threads:[~2025-06-09 13:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 13:27 Harry Yoo [this message]
2025-06-09 14:12 ` Harry Yoo
2025-06-09 14:22 ` Vlastimil Babka
2025-06-10 12:38 ` Harry Yoo
2025-06-10 13:03 ` Vlastimil Babka
2025-06-10 13:17 ` Harry Yoo
2025-06-12 12:44 ` David Hildenbrand
2025-06-09 16:06 ` Christoph Lameter (Ampere)
2025-06-10 12:39 ` Harry Yoo
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=20250609132723.13118-1-harry.yoo@oracle.com \
--to=harry.yoo@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--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