mm/page_alloc: Dedupe some memcg uncharging logic

Message ID 20231027132213.3817924-1-jackmanb@google.com
State New
Headers
Series mm/page_alloc: Dedupe some memcg uncharging logic |

Commit Message

Brendan Jackman Oct. 27, 2023, 1:22 p.m. UTC
  The duplication makes it seem like some work is required before
uncharging in the !PageHWPoison case. But it isn't, so we can simplify
the code a little.

Note the PageMemcgKmem check is redundant, but I've left it in as it
avoids an unnecessary function call.

Signed-Off-By: Brendan Jackman <jackmanb@google.com>
Change-Id: Ibe0f9941b6b24fc98ea2510a75d0a0d1066a2a2e
---
 mm/page_alloc.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
  

Comments

Brendan Jackman Oct. 31, 2023, 9:55 a.m. UTC | #1
On Fri, 27 Oct 2023 at 15:22, Brendan Jackman <jackmanb@google.com> wrote:

> Signed-Off-By: Brendan Jackman <jackmanb@google.com>
> Change-Id: Ibe0f9941b6b24fc98ea2510a75d0a0d1066a2a2e

Agh, sorry, it just jumped into my head that I neglected to run
checkpatch and of course the commit message is garbage. I will leave
this a few days in case there are other comments before I send a v2.

FWIW I did at least run the mm kselftests via QEMU, results are the
same with and without the patch.
  

Patch

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 85741403948f..b9e81e416e73 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1084,13 +1084,11 @@  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);
+
 	if (unlikely(PageHWPoison(page)) && !order) {
-		/*
-		 * Do not let hwpoison pages hit pcplists/buddy
-		 * Untie memcg state and reset page's owner
-		 */
-		if (memcg_kmem_online() && PageMemcgKmem(page))
-			__memcg_kmem_uncharge_page(page, order);
+		/* Do not let hwpoison pages hit pcplists/buddy */
 		reset_page_owner(page, order);
 		page_table_check_free(page, order);
 		return false;
@@ -1122,8 +1120,6 @@  static __always_inline bool free_pages_prepare(struct page *page,
 	}
 	if (PageMappingFlags(page))
 		page->mapping = NULL;
-	if (memcg_kmem_online() && PageMemcgKmem(page))
-		__memcg_kmem_uncharge_page(page, order);
 	if (is_check_pages_enabled()) {
 		if (free_page_is_bad(page))
 			bad++;