* [PATCH] slab: Remove slab_folio()
@ 2026-09-23 18:36 Matthew Wilcox (Oracle)
2026-09-23 19:19 ` Gregory Price
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Matthew Wilcox (Oracle) @ 2026-09-23 18:36 UTC (permalink / raw)
To: Vlastimil Babka
Cc: Matthew Wilcox (Oracle), Harry Yoo, Andrew Morton, Hao Li,
Christoph Lameter, David Rientjes, Roman Gushchin, linux-mm
This is the final step of divorcing struct slab from struct folio.
It's still tied to struct page, but there are no more mentions of folios
in the slab code.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/slab.h | 28 +++++++---------------------
1 file changed, 7 insertions(+), 21 deletions(-)
diff --git a/mm/slab.h b/mm/slab.h
index 8fd6835e4235..3ae7e70c27ff 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -149,21 +149,6 @@ static_assert(sizeof(struct slab) <= sizeof(struct page));
static_assert(IS_ALIGNED(offsetof(struct slab, freelist), sizeof(struct freelist_counters)));
#endif
-/**
- * slab_folio - The folio allocated for a slab
- * @s: The slab.
- *
- * Slabs are allocated as folios that contain the individual objects and are
- * using some fields in the first struct page of the folio - those fields are
- * now accessed by struct slab. It is occasionally necessary to convert back to
- * a folio in order to communicate with the rest of the mm. Please use this
- * helper function instead of casting yourself, as the implementation may change
- * in the future.
- */
-#define slab_folio(s) (_Generic((s), \
- const struct slab *: (const struct folio *)s, \
- struct slab *: (struct folio *)s))
-
/**
* page_slab - Converts from struct page to its slab.
* @page: A page which may or may not belong to a slab.
@@ -184,15 +169,16 @@ static inline struct slab *page_slab(const struct page *page)
* slab_page - The first struct page allocated for a slab
* @s: The slab.
*
- * A convenience wrapper for converting slab to the first struct page of the
- * underlying folio, to communicate with code not yet converted to folio or
- * struct slab.
+ * A convenience wrapper for returning the first page allocated to this slab.
+ * to communicate with code not yet converted to struct slab.
*/
-#define slab_page(s) folio_page(slab_folio(s), 0)
+#define slab_page(s) (_Generic((s), \
+ const struct slab *: (const struct page *)s, \
+ struct slab *: (struct page *)s))
static inline void *slab_address(const struct slab *slab)
{
- return folio_address(slab_folio(slab));
+ return page_address(slab_page(slab));
}
static inline int slab_nid(const struct slab *slab)
@@ -212,7 +198,7 @@ static inline struct slab *virt_to_slab(const void *addr)
static inline int slab_order(const struct slab *slab)
{
- return folio_order(slab_folio(slab));
+ return compound_order(slab_page(slab));
}
static inline size_t slab_size(const struct slab *slab)
--
2.47.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] slab: Remove slab_folio()
2026-09-23 18:36 [PATCH] slab: Remove slab_folio() Matthew Wilcox (Oracle)
@ 2026-09-23 19:19 ` Gregory Price
2026-09-23 19:45 ` Harry Yoo
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Gregory Price @ 2026-09-23 19:19 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: Vlastimil Babka, Harry Yoo, Andrew Morton, Hao Li,
Christoph Lameter, David Rientjes, Roman Gushchin, linux-mm
On Wed, Sep 23, 2026 at 07:36:51PM +0100, Matthew Wilcox (Oracle) wrote:
> This is the final step of divorcing struct slab from struct folio.
> It's still tied to struct page, but there are no more mentions of folios
> in the slab code.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] slab: Remove slab_folio()
2026-09-23 18:36 [PATCH] slab: Remove slab_folio() Matthew Wilcox (Oracle)
2026-09-23 19:19 ` Gregory Price
@ 2026-09-23 19:45 ` Harry Yoo
2026-09-23 20:11 ` Vlastimil Babka (SUSE)
2026-09-24 17:43 ` Harry Yoo (Meta)
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Harry Yoo @ 2026-09-23 19:45 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: Vlastimil Babka, Andrew Morton, Hao Li, Christoph Lameter,
David Rientjes, Roman Gushchin, linux-mm
On Wed, Sep 23, 2026 at 07:36:51PM +0100, Matthew Wilcox (Oracle) wrote:
> This is the final step of divorcing struct slab from struct folio.
> It's still tied to struct page, but there are no more mentions of folios
> in the slab code.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
Looks good to me,
Reviewed-by: Harry Yoo (Meta) <harry@kernel.org>
With a tiny little nit:
> @@ -184,15 +169,16 @@ static inline struct slab *page_slab(const struct page *page)
> * slab_page - The first struct page allocated for a slab
> * @s: The slab.
> *
> - * A convenience wrapper for converting slab to the first struct page of the
> - * underlying folio, to communicate with code not yet converted to folio or
> - * struct slab.
> + * A convenience wrapper for returning the first page allocated to this slab.
> + * to communicate with code not yet converted to struct slab.
* A convenience wrapper for returning the first "struct" page allocated to this
* "slab" to communicate with code not yet converted to struct slab.
> */
Perhaps you meant this?
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] slab: Remove slab_folio()
2026-09-23 19:45 ` Harry Yoo
@ 2026-09-23 20:11 ` Vlastimil Babka (SUSE)
2026-09-23 20:41 ` Matthew Wilcox
0 siblings, 1 reply; 9+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-09-23 20:11 UTC (permalink / raw)
To: Harry Yoo, Matthew Wilcox (Oracle)
Cc: Andrew Morton, Hao Li, Christoph Lameter, David Rientjes,
Roman Gushchin, linux-mm
On 9/23/26 21:45, Harry Yoo wrote:
> On Wed, Sep 23, 2026 at 07:36:51PM +0100, Matthew Wilcox (Oracle) wrote:
>> This is the final step of divorcing struct slab from struct folio.
>> It's still tied to struct page, but there are no more mentions of folios
>> in the slab code.
>>
>> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
>> ---
>
> Looks good to me,
> Reviewed-by: Harry Yoo (Meta) <harry@kernel.org>
>
> With a tiny little nit:
>
>> @@ -184,15 +169,16 @@ static inline struct slab *page_slab(const struct page *page)
>> * slab_page - The first struct page allocated for a slab
>> * @s: The slab.
>> *
>> - * A convenience wrapper for converting slab to the first struct page of the
>> - * underlying folio, to communicate with code not yet converted to folio or
>> - * struct slab.
>> + * A convenience wrapper for returning the first page allocated to this slab.
>> + * to communicate with code not yet converted to struct slab.
> * A convenience wrapper for returning the first "struct" page allocated to this
> * "slab" to communicate with code not yet converted to struct slab.
>> */
>
> Perhaps you meant this?
Yeah, and I wonder about the "code not yet converted" part, and if there's
anything we can still convert right now. What I can see among slab_page() users:
- slab_order() - we could probably add order (aliasing page's order for now)
to struct slab right now and that would be future-proof
But:
- slab_address() - I guess can only be converted once slab is divorced from
page?
- __kasan_poison_slab - same as above?
- several VM_BUG_ON_PAGE() usages - same?
- validate_slab_ptr() - same?
__free_slab() - same, obviously
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] slab: Remove slab_folio()
2026-09-23 20:11 ` Vlastimil Babka (SUSE)
@ 2026-09-23 20:41 ` Matthew Wilcox
2026-09-24 7:41 ` Vlastimil Babka (SUSE)
0 siblings, 1 reply; 9+ messages in thread
From: Matthew Wilcox @ 2026-09-23 20:41 UTC (permalink / raw)
To: Vlastimil Babka (SUSE)
Cc: Harry Yoo, Andrew Morton, Hao Li, Christoph Lameter,
David Rientjes, Roman Gushchin, linux-mm
On Wed, Sep 23, 2026 at 10:11:06PM +0200, Vlastimil Babka (SUSE) wrote:
> On 9/23/26 21:45, Harry Yoo wrote:
> > With a tiny little nit:
> >
> >> @@ -184,15 +169,16 @@ static inline struct slab *page_slab(const struct page *page)
> >> * slab_page - The first struct page allocated for a slab
> >> * @s: The slab.
> >> *
> >> - * A convenience wrapper for converting slab to the first struct page of the
> >> - * underlying folio, to communicate with code not yet converted to folio or
> >> - * struct slab.
> >> + * A convenience wrapper for returning the first page allocated to this slab.
> >> + * to communicate with code not yet converted to struct slab.
> > * A convenience wrapper for returning the first "struct" page allocated to this
> > * "slab" to communicate with code not yet converted to struct slab.
> >> */
> >
> > Perhaps you meant this?
My eyes are old and don't notice punctuation as well as they used to.
What I meant was:
* A convenience wrapper for returning the first page allocated to this slab.
* This is for the benefit of code not yet converted to struct slab.
> Yeah, and I wonder about the "code not yet converted" part, and if there's
> anything we can still convert right now. What I can see among slab_page() users:
>
> - slab_order() - we could probably add order (aliasing page's order for now)
> to struct slab right now and that would be future-proof
That's trickier than you think because it's stored in the ->flags of
the second page when PG_head is set. When divorcing slab and page,
it moves into struct slab, but we can't do that in advance.
> But:
> - slab_address() - I guess can only be converted once slab is divorced from
> page?
Yeah, it becomes slab->virtual.
> - __kasan_poison_slab - same as above?
The loop calling page_kasan_tag_reset() makes me think kasan really
wants a page here.
> - several VM_BUG_ON_PAGE() usages - same?
We could probably introduce a VM_BUG_ON_SLAB if you're interested.
> - validate_slab_ptr() - same?
That'll change dramatically -- if we want to validate that a pointer
really points to a slab object, we'll want to, er, ask if
virt_to_slab() belongs to the slab slab.
> __free_slab() - same, obviously
Right.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] slab: Remove slab_folio()
2026-09-23 20:41 ` Matthew Wilcox
@ 2026-09-24 7:41 ` Vlastimil Babka (SUSE)
0 siblings, 0 replies; 9+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-09-24 7:41 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Harry Yoo, Andrew Morton, Hao Li, Christoph Lameter,
David Rientjes, Roman Gushchin, linux-mm
On 9/23/26 22:41, Matthew Wilcox wrote:
> On Wed, Sep 23, 2026 at 10:11:06PM +0200, Vlastimil Babka (SUSE) wrote:
>> On 9/23/26 21:45, Harry Yoo wrote:
>> > With a tiny little nit:
>> >
>> >> @@ -184,15 +169,16 @@ static inline struct slab *page_slab(const struct page *page)
>> >> * slab_page - The first struct page allocated for a slab
>> >> * @s: The slab.
>> >> *
>> >> - * A convenience wrapper for converting slab to the first struct page of the
>> >> - * underlying folio, to communicate with code not yet converted to folio or
>> >> - * struct slab.
>> >> + * A convenience wrapper for returning the first page allocated to this slab.
>> >> + * to communicate with code not yet converted to struct slab.
>> > * A convenience wrapper for returning the first "struct" page allocated to this
>> > * "slab" to communicate with code not yet converted to struct slab.
>> >> */
>> >
>> > Perhaps you meant this?
>
> My eyes are old and don't notice punctuation as well as they used to.
> What I meant was:
>
> * A convenience wrapper for returning the first page allocated to this slab.
> * This is for the benefit of code not yet converted to struct slab.
>
>> Yeah, and I wonder about the "code not yet converted" part, and if there's
>> anything we can still convert right now. What I can see among slab_page() users:
>>
>> - slab_order() - we could probably add order (aliasing page's order for now)
>> to struct slab right now and that would be future-proof
>
> That's trickier than you think because it's stored in the ->flags of
> the second page when PG_head is set. When divorcing slab and page,
> it moves into struct slab, but we can't do that in advance.
Ah, I see.
>> But:
>> - slab_address() - I guess can only be converted once slab is divorced from
>> page?
>
> Yeah, it becomes slab->virtual.
>
>> - __kasan_poison_slab - same as above?
>
> The loop calling page_kasan_tag_reset() makes me think kasan really
> wants a page here.
>
>> - several VM_BUG_ON_PAGE() usages - same?
>
> We could probably introduce a VM_BUG_ON_SLAB if you're interested.
Maybe not worth the effort.
>> - validate_slab_ptr() - same?
>
> That'll change dramatically -- if we want to validate that a pointer
> really points to a slab object, we'll want to, er, ask if
> virt_to_slab() belongs to the slab slab.
>
>> __free_slab() - same, obviously
>
> Right.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] slab: Remove slab_folio()
2026-09-23 18:36 [PATCH] slab: Remove slab_folio() Matthew Wilcox (Oracle)
2026-09-23 19:19 ` Gregory Price
2026-09-23 19:45 ` Harry Yoo
@ 2026-09-24 17:43 ` Harry Yoo (Meta)
2026-09-25 8:08 ` Vlastimil Babka (SUSE)
2026-09-25 8:35 ` Hao Li
4 siblings, 0 replies; 9+ messages in thread
From: Harry Yoo (Meta) @ 2026-09-24 17:43 UTC (permalink / raw)
To: Vlastimil Babka, Matthew Wilcox (Oracle)
Cc: kernel-team, Andrew Morton, Hao Li, Christoph Lameter,
David Rientjes, Roman Gushchin, linux-mm
On Wed, 23 Sep 2026 19:36:51 +0100, Matthew Wilcox (Oracle) wrote:
> This is the final step of divorcing struct slab from struct folio.
> It's still tied to struct page, but there are no more mentions of folios
> in the slab code.
Applied to mm/slab.git slab/for-next, thanks!
(Adjusted "What I meant was:" part)
[1/1] slab: Remove slab_folio()
commit: 662d8eb097ec7514091bbcf5d0d776890c3d1be4
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] slab: Remove slab_folio()
2026-09-23 18:36 [PATCH] slab: Remove slab_folio() Matthew Wilcox (Oracle)
` (2 preceding siblings ...)
2026-09-24 17:43 ` Harry Yoo (Meta)
@ 2026-09-25 8:08 ` Vlastimil Babka (SUSE)
2026-09-25 8:35 ` Hao Li
4 siblings, 0 replies; 9+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-09-25 8:08 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: Harry Yoo, Andrew Morton, Hao Li, Christoph Lameter,
David Rientjes, Roman Gushchin, linux-mm
On 9/23/26 20:36, Matthew Wilcox (Oracle) wrote:
> This is the final step of divorcing struct slab from struct folio.
> It's still tied to struct page, but there are no more mentions of folios
> in the slab code.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] slab: Remove slab_folio()
2026-09-23 18:36 [PATCH] slab: Remove slab_folio() Matthew Wilcox (Oracle)
` (3 preceding siblings ...)
2026-09-25 8:08 ` Vlastimil Babka (SUSE)
@ 2026-09-25 8:35 ` Hao Li
4 siblings, 0 replies; 9+ messages in thread
From: Hao Li @ 2026-09-25 8:35 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: Vlastimil Babka, Harry Yoo, Andrew Morton, Christoph Lameter,
David Rientjes, Roman Gushchin, linux-mm
On Wed, Sep 23, 2026 at 07:36:51PM +0100, Matthew Wilcox (Oracle) wrote:
> This is the final step of divorcing struct slab from struct folio.
> It's still tied to struct page, but there are no more mentions of folios
> in the slab code.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
> mm/slab.h | 28 +++++++---------------------
> 1 file changed, 7 insertions(+), 21 deletions(-)
Reviewed-by: Hao Li <hao.li@linux.dev>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-09-25 8:35 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-23 18:36 [PATCH] slab: Remove slab_folio() Matthew Wilcox (Oracle)
2026-09-23 19:19 ` Gregory Price
2026-09-23 19:45 ` Harry Yoo
2026-09-23 20:11 ` Vlastimil Babka (SUSE)
2026-09-23 20:41 ` Matthew Wilcox
2026-09-24 7:41 ` Vlastimil Babka (SUSE)
2026-09-24 17:43 ` Harry Yoo (Meta)
2026-09-25 8:08 ` Vlastimil Babka (SUSE)
2026-09-25 8:35 ` Hao Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox