[PATCH] mm: memcg: remove direct use of __memcg_kmem_uncharge_page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux