* [PATCH] mm/slub: Use folio_nr_pages() in __free_slab()
@ 2025-09-09 7:48 Hu Song
2025-09-09 8:00 ` Oscar Salvador
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Hu Song @ 2025-09-09 7:48 UTC (permalink / raw)
To: Vlastimil Babka, Andrew Morton
Cc: Hu Song, Christoph Lameter, David Rientjes, Roman Gushchin,
Harry Yoo, linux-mm, linux-kernel
Use folio_nr_pages() helper instead of manual calculation (1 << order)
for better code readability and maintainability.
Signed-off-by: Hu Song <husong@kylinos.cn>
---
mm/slub.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/slub.c b/mm/slub.c
index d257141896c9..eba25461641a 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2719,7 +2719,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab)
{
struct folio *folio = slab_folio(slab);
int order = folio_order(folio);
- int pages = 1 << order;
+ int pages = folio_nr_pages(folio);
__slab_clear_pfmemalloc(slab);
folio->mapping = NULL;
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm/slub: Use folio_nr_pages() in __free_slab()
2025-09-09 7:48 [PATCH] mm/slub: Use folio_nr_pages() in __free_slab() Hu Song
@ 2025-09-09 8:00 ` Oscar Salvador
2025-09-09 8:30 ` Ye Liu
2025-09-09 8:46 ` Dev Jain
2025-09-09 14:29 ` Matthew Wilcox
2 siblings, 1 reply; 7+ messages in thread
From: Oscar Salvador @ 2025-09-09 8:00 UTC (permalink / raw)
To: Hu Song
Cc: Vlastimil Babka, Andrew Morton, Christoph Lameter,
David Rientjes, Roman Gushchin, Harry Yoo, linux-mm,
linux-kernel
On Tue, Sep 09, 2025 at 03:48:11PM +0800, Hu Song wrote:
> Use folio_nr_pages() helper instead of manual calculation (1 << order)
> for better code readability and maintainability.
>
> Signed-off-by: Hu Song <husong@kylinos.cn>
> ---
> mm/slub.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index d257141896c9..eba25461641a 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2719,7 +2719,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab)
> {
> struct folio *folio = slab_folio(slab);
> int order = folio_order(folio);
> - int pages = 1 << order;
> + int pages = folio_nr_pages(folio);
Sure nothing might happen, but I find a bit weird that folio_nr_pages()
returns a 'long' and we store it in an 'int' type.
And then sure we handle that to mm_account_reclaimed_pages() which gets
'unsigned long', but that's another story.
--
Oscar Salvador
SUSE Labs
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm/slub: Use folio_nr_pages() in __free_slab()
2025-09-09 8:00 ` Oscar Salvador
@ 2025-09-09 8:30 ` Ye Liu
0 siblings, 0 replies; 7+ messages in thread
From: Ye Liu @ 2025-09-09 8:30 UTC (permalink / raw)
To: Oscar Salvador, Hu Song
Cc: Vlastimil Babka, Andrew Morton, Christoph Lameter,
David Rientjes, Roman Gushchin, Harry Yoo, linux-mm,
linux-kernel
在 2025/9/9 16:00, Oscar Salvador 写道:
> On Tue, Sep 09, 2025 at 03:48:11PM +0800, Hu Song wrote:
>> Use folio_nr_pages() helper instead of manual calculation (1 << order)
>> for better code readability and maintainability.
>>
>> Signed-off-by: Hu Song <husong@kylinos.cn>
>> ---
>> mm/slub.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/slub.c b/mm/slub.c
>> index d257141896c9..eba25461641a 100644
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -2719,7 +2719,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab)
>> {
>> struct folio *folio = slab_folio(slab);
>> int order = folio_order(folio);
>> - int pages = 1 << order;
>> + int pages = folio_nr_pages(folio);
> Sure nothing might happen, but I find a bit weird that folio_nr_pages()
> returns a 'long' and we store it in an 'int' type.
> And then sure we handle that to mm_account_reclaimed_pages() which gets
> 'unsigned long', but that's another story.
>
>
Maybe also correct the int->unsigned long conversion.:)
>
--
Thanks,
Ye Liu
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm/slub: Use folio_nr_pages() in __free_slab()
2025-09-09 7:48 [PATCH] mm/slub: Use folio_nr_pages() in __free_slab() Hu Song
2025-09-09 8:00 ` Oscar Salvador
@ 2025-09-09 8:46 ` Dev Jain
2025-09-09 8:59 ` Ye Liu
2025-09-09 14:29 ` Matthew Wilcox
2 siblings, 1 reply; 7+ messages in thread
From: Dev Jain @ 2025-09-09 8:46 UTC (permalink / raw)
To: Hu Song, Vlastimil Babka, Andrew Morton
Cc: Christoph Lameter, David Rientjes, Roman Gushchin, Harry Yoo,
linux-mm, linux-kernel
On 09/09/25 1:18 pm, Hu Song wrote:
> Use folio_nr_pages() helper instead of manual calculation (1 << order)
> for better code readability and maintainability.
>
> Signed-off-by: Hu Song <husong@kylinos.cn>
> ---
> mm/slub.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index d257141896c9..eba25461641a 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2719,7 +2719,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab)
> {
> struct folio *folio = slab_folio(slab);
> int order = folio_order(folio);
> - int pages = 1 << order;
> + int pages = folio_nr_pages(folio);
>
> __slab_clear_pfmemalloc(slab);
> folio->mapping = NULL;
I don't know, the current version is more readable to me. We literally
compute the order before, so we do a simple 1 << order. I'll leave it
to the rest.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm/slub: Use folio_nr_pages() in __free_slab()
2025-09-09 8:46 ` Dev Jain
@ 2025-09-09 8:59 ` Ye Liu
2025-09-09 14:52 ` Pedro Falcato
0 siblings, 1 reply; 7+ messages in thread
From: Ye Liu @ 2025-09-09 8:59 UTC (permalink / raw)
To: Dev Jain, Hu Song, Vlastimil Babka, Andrew Morton
Cc: Christoph Lameter, David Rientjes, Roman Gushchin, Harry Yoo,
linux-mm, linux-kernel
在 2025/9/9 16:46, Dev Jain 写道:
>
> On 09/09/25 1:18 pm, Hu Song wrote:
>> Use folio_nr_pages() helper instead of manual calculation (1 << order)
>> for better code readability and maintainability.
>>
>> Signed-off-by: Hu Song <husong@kylinos.cn>
>> ---
>> mm/slub.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/slub.c b/mm/slub.c
>> index d257141896c9..eba25461641a 100644
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -2719,7 +2719,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab)
>> {
>> struct folio *folio = slab_folio(slab);
>> int order = folio_order(folio);
>> - int pages = 1 << order;
>> + int pages = folio_nr_pages(folio);
>> __slab_clear_pfmemalloc(slab);
>> folio->mapping = NULL;
>
> I don't know, the current version is more readable to me. We literally
> compute the order before, so we do a simple 1 << order. I'll leave it
> to the rest.
>
>
Is the reason for calculating 'order' first because it's needed later.
I suggest using folio_nr_pages to replace the calculation of pages,
unifying the retrieval of pages in the folio and also highlighting
the significance of folio_nr_pages.
--
Thanks,
Ye Liu
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] mm/slub: Use folio_nr_pages() in __free_slab()
2025-09-09 8:59 ` Ye Liu
@ 2025-09-09 14:52 ` Pedro Falcato
0 siblings, 0 replies; 7+ messages in thread
From: Pedro Falcato @ 2025-09-09 14:52 UTC (permalink / raw)
To: Ye Liu
Cc: Dev Jain, Hu Song, Vlastimil Babka, Andrew Morton,
Christoph Lameter, David Rientjes, Roman Gushchin, Harry Yoo,
linux-mm, linux-kernel
On Tue, Sep 09, 2025 at 04:59:37PM +0800, Ye Liu wrote:
>
> 在 2025/9/9 16:46, Dev Jain 写道:
> >
> > On 09/09/25 1:18 pm, Hu Song wrote:
> >> Use folio_nr_pages() helper instead of manual calculation (1 << order)
> >> for better code readability and maintainability.
> >>
> >> Signed-off-by: Hu Song <husong@kylinos.cn>
> >> ---
> >> mm/slub.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/mm/slub.c b/mm/slub.c
> >> index d257141896c9..eba25461641a 100644
> >> --- a/mm/slub.c
> >> +++ b/mm/slub.c
> >> @@ -2719,7 +2719,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab)
> >> {
> >> struct folio *folio = slab_folio(slab);
> >> int order = folio_order(folio);
> >> - int pages = 1 << order;
> >> + int pages = folio_nr_pages(folio);
> >> __slab_clear_pfmemalloc(slab);
> >> folio->mapping = NULL;
> >
> > I don't know, the current version is more readable to me. We literally
> > compute the order before, so we do a simple 1 << order. I'll leave it
> > to the rest.
> >
> >
> Is the reason for calculating 'order' first because it's needed later.
Yes, we use it 6 lines down.
--
Pedro
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm/slub: Use folio_nr_pages() in __free_slab()
2025-09-09 7:48 [PATCH] mm/slub: Use folio_nr_pages() in __free_slab() Hu Song
2025-09-09 8:00 ` Oscar Salvador
2025-09-09 8:46 ` Dev Jain
@ 2025-09-09 14:29 ` Matthew Wilcox
2 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox @ 2025-09-09 14:29 UTC (permalink / raw)
To: Hu Song
Cc: Vlastimil Babka, Andrew Morton, Christoph Lameter,
David Rientjes, Roman Gushchin, Harry Yoo, linux-mm,
linux-kernel
On Tue, Sep 09, 2025 at 03:48:11PM +0800, Hu Song wrote:
> Use folio_nr_pages() helper instead of manual calculation (1 << order)
> for better code readability and maintainability.
https://lore.kernel.org/linux-mm/20250829154728.3397606-10-willy@infradead.org/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-09-09 14:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-09 7:48 [PATCH] mm/slub: Use folio_nr_pages() in __free_slab() Hu Song
2025-09-09 8:00 ` Oscar Salvador
2025-09-09 8:30 ` Ye Liu
2025-09-09 8:46 ` Dev Jain
2025-09-09 8:59 ` Ye Liu
2025-09-09 14:52 ` Pedro Falcato
2025-09-09 14:29 ` Matthew Wilcox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox