linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Remove redundant PageMemcgKmem(page) call
@ 2025-02-12  2:06 Shengken Lin
  2025-02-12  4:28 ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Shengken Lin @ 2025-02-12  2:06 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, Shengken Lin

The function of PageMemcgKmem(page) is the same as that of
folio_memcg_kmem(folio).

Since __memcg_kmem_uncharge_page already uses folio_memcg_kmem to check
if a folio has been uncharged, calling PageMemcgKmem(page) before
__memcg_kmem_uncharge_page is redundant.

Signed-off-by: Shengken Lin <shengken.lin@amlogic.com>
---
 mm/page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 579789600a3c..5a76760de495 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1055,7 +1055,7 @@ __always_inline bool free_pages_prepare(struct page *page,
 	trace_mm_page_free(page, order);
 	kmsan_free_page(page, order);

-	if (memcg_kmem_online() && PageMemcgKmem(page))
+	if (memcg_kmem_online())
 		__memcg_kmem_uncharge_page(page, order);

 	/*
--
2.34.1



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

* Re: [PATCH] mm: Remove redundant PageMemcgKmem(page) call
  2025-02-12  2:06 [PATCH] mm: Remove redundant PageMemcgKmem(page) call Shengken Lin
@ 2025-02-12  4:28 ` Matthew Wilcox
  2025-02-20  9:47   ` Shengken.Lin
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2025-02-12  4:28 UTC (permalink / raw)
  To: Shengken Lin; +Cc: akpm, linux-mm, linux-kernel

On Wed, Feb 12, 2025 at 10:06:27AM +0800, Shengken Lin wrote:
> The function of PageMemcgKmem(page) is the same as that of
> folio_memcg_kmem(folio).
> 
> Since __memcg_kmem_uncharge_page already uses folio_memcg_kmem to check
> if a folio has been uncharged, calling PageMemcgKmem(page) before
> __memcg_kmem_uncharge_page is redundant.

But it saves a function call.  NAK.


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

* Re: Re: [PATCH] mm: Remove redundant PageMemcgKmem(page) call
  2025-02-12  4:28 ` Matthew Wilcox
@ 2025-02-20  9:47   ` Shengken.Lin
  2025-02-20 13:22     ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Shengken.Lin @ 2025-02-20  9:47 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: akpm, linux-mm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1073 bytes --]

On Wed, 12 Feb 2025 04:28PM +0000, Matthew Wilcox wrote:
>On Wed, Feb 12, 2025 at 10:06:27AM +0800, Shengken Lin wrote:
>> The function of PageMemcgKmem(page) is the same as that of
>> folio_memcg_kmem(folio).
>> 
>> Since __memcg_kmem_uncharge_page already uses folio_memcg_kmem to check
>> if a folio has been uncharged, calling PageMemcgKmem(page) before
>> __memcg_kmem_uncharge_page is redundant.
>
>But it saves a function call.  NAK.
Hi Matthew Wilcox,
If it can save a function call, then adding PageMemcgKmem(page)
in include/linux/memcontrol.h would make the code more consistent.
If this is considered more reasonable, I can submit a new patch.
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1707,7 +1707,7 @@ static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp,
 
 static inline void memcg_kmem_uncharge_page(struct page *page, int order)
 {
-       if (memcg_kmem_online())
+       if (memcg_kmem_online() && PageMemcgKmem(page))
                __memcg_kmem_uncharge_page(page, order);
 }
--
Best regards,
Shengken Lin

[-- Attachment #2: Type: text/html, Size: 1718 bytes --]

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

* Re: Re: [PATCH] mm: Remove redundant PageMemcgKmem(page) call
  2025-02-20  9:47   ` Shengken.Lin
@ 2025-02-20 13:22     ` Matthew Wilcox
  0 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2025-02-20 13:22 UTC (permalink / raw)
  To: Shengken.Lin; +Cc: akpm, linux-mm, linux-kernel

On Thu, Feb 20, 2025 at 05:47:56PM +0800, Shengken.Lin@amlogic.com wrote:
> If it can save a function call, then adding PageMemcgKmem(page)
> in include/linux/memcontrol.h would make the code more consistent.

The code is fine the way it is.


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

end of thread, other threads:[~2025-02-20 13:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-12  2:06 [PATCH] mm: Remove redundant PageMemcgKmem(page) call Shengken Lin
2025-02-12  4:28 ` Matthew Wilcox
2025-02-20  9:47   ` Shengken.Lin
2025-02-20 13:22     ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox