linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: memcg: remove direct use of __memcg_kmem_uncharge_page
@ 2023-12-13 13:04 Yosry Ahmed
  2023-12-13 14:26 ` Muchun Song
  2023-12-13 15:01 ` Matthew Wilcox
  0 siblings, 2 replies; 18+ messages in thread
From: Yosry Ahmed @ 2023-12-13 13:04 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
	Muchun Song, Matthew Wilcox (Oracle),
	cgroups, linux-mm, Yosry Ahmed

memcg_kmem_uncharge_page() is an inline wrapper around
__memcg_kmem_uncharge_page() that checks memcg_kmem_online() before
making the function call. Internally, __memcg_kmem_uncharge_page() has a
folio_memcg_kmem() check.

The only direct user of __memcg_kmem_uncharge_page(),
free_pages_prepare(), checks PageMemcgKmem() before calling it to avoid
the function call if possible. Move the folio_memcg_kmem() check from
__memcg_kmem_uncharge_page() to memcg_kmem_uncharge_page() as
PageMemcgKmem() -- which does the same thing under the hood. Now
free_pages_prepare() can also use memcg_kmem_uncharge_page().

No functional change intended.

Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
---
 include/linux/memcontrol.h | 2 +-
 mm/memcontrol.c            | 3 ---
 mm/page_alloc.c            | 3 +--
 3 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index a308c8eacf20d..2009ca508271a 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1844,7 +1844,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);
 }
 
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 69b0ad4552425..09efbfa2733e8 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3301,9 +3301,6 @@ void __memcg_kmem_uncharge_page(struct page *page, int order)
 	struct obj_cgroup *objcg;
 	unsigned int nr_pages = 1 << order;
 
-	if (!folio_memcg_kmem(folio))
-		return;
-
 	objcg = __folio_objcg(folio);
 	obj_cgroup_uncharge_pages(objcg, nr_pages);
 	folio->memcg_data = 0;
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 7ea9c33320bf1..f72693d91ac22 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1086,8 +1086,7 @@ static __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))
-		__memcg_kmem_uncharge_page(page, order);
+	memcg_kmem_uncharge_page(page, order);
 
 	if (unlikely(PageHWPoison(page)) && !order) {
 		/* Do not let hwpoison pages hit pcplists/buddy */
-- 
2.43.0.472.g3155946c3a-goog



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

end of thread, other threads:[~2023-12-14  1:46 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-13 13:04 [PATCH] mm: memcg: remove direct use of __memcg_kmem_uncharge_page Yosry Ahmed
2023-12-13 14:26 ` Muchun Song
2023-12-13 15:01 ` Matthew Wilcox
2023-12-13 15:08   ` Yosry Ahmed
2023-12-13 15:38     ` Matthew Wilcox
2023-12-13 15:42       ` Yosry Ahmed
2023-12-13 16:23         ` Matthew Wilcox
2023-12-13 16:24           ` Yosry Ahmed
2023-12-13 16:27             ` Matthew Wilcox
2023-12-13 16:31               ` Yosry Ahmed
2023-12-13 20:23                 ` Shakeel Butt
2023-12-13 20:27                   ` Matthew Wilcox
2023-12-13 20:41                     ` Shakeel Butt
2023-12-13 20:58                       ` Shakeel Butt
2023-12-13 22:04                         ` Yosry Ahmed
2023-12-13 22:12                           ` Shakeel Butt
2023-12-13 22:15                             ` Yosry Ahmed
2023-12-14  1:46                             ` Roman Gushchin

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