All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ye Liu <ye.liu@linux.dev>
To: akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Markus.Elfring@web.de, Ye Liu <liuye@kylinos.cn>,
	Sidhartha Kumar <sidhartha.kumar@oracle.com>,
	Anshuman Khandual <anshuman.khandual@arm.com>
Subject: [PATCH v4] mm/page_alloc: Consolidate unlikely handling in page_expected_state
Date: Fri, 28 Mar 2025 09:47:57 +0800	[thread overview]
Message-ID: <20250328014757.1212737-1-ye.liu@linux.dev> (raw)

From: Ye Liu <liuye@kylinos.cn>

Consolidate the handling of unlikely conditions in the 
page_expected_state() function to reduce code duplication and improve 
readability.

Move the logic for handling __PG_HWPOISON flags from the 
check_new_page_bad() function to the page_expected_state() function, 
and remove check_new_page_bad().

Call bad_page() directly from the check_new_page() function if the page has
unexpected flags.

Simplify the code by reducing the number of functions and centralizing the
handling of unlikely conditions.

Signed-off-by: Ye Liu <liuye@kylinos.cn>
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>

---
V4: Use "imperative mood" to modify the commit and append parentheses 
to all function names.
V3: Delete 'This patch'.
V2: return true instead of false in the PageHWPoison branch.
---
 mm/page_alloc.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 2842da893eea..e8b95c6a96c2 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -903,6 +903,12 @@ static inline bool page_expected_state(struct page *page,
 			(page->flags & check_flags)))
 		return false;
 
+	if (unlikely(PageHWPoison(page))) {
+		/* Don't complain about hwpoisoned pages */
+		if (PageBuddy(page))
+			__ClearPageBuddy(page);
+	}
+
 	return true;
 }
 
@@ -1586,29 +1592,15 @@ static __always_inline void page_del_and_expand(struct zone *zone,
 	account_freepages(zone, -nr_pages, migratetype);
 }
 
-static void check_new_page_bad(struct page *page)
-{
-	if (unlikely(PageHWPoison(page))) {
-		/* Don't complain about hwpoisoned pages */
-		if (PageBuddy(page))
-			__ClearPageBuddy(page);
-		return;
-	}
-
-	bad_page(page,
-		 page_bad_reason(page, PAGE_FLAGS_CHECK_AT_PREP));
-}
-
 /*
  * This page is about to be returned from the page allocator
  */
 static bool check_new_page(struct page *page)
 {
-	if (likely(page_expected_state(page,
-				PAGE_FLAGS_CHECK_AT_PREP|__PG_HWPOISON)))
+	if (likely(page_expected_state(page, PAGE_FLAGS_CHECK_AT_PREP)))
 		return false;
 
-	check_new_page_bad(page);
+	bad_page(page, page_bad_reason(page, PAGE_FLAGS_CHECK_AT_PREP));
 	return true;
 }
 
-- 
2.25.1



             reply	other threads:[~2025-03-28  1:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-28  1:47 Ye Liu [this message]
2025-03-28  9:44 ` [PATCH v4] mm/page_alloc: Consolidate unlikely handling in page_expected_state Markus Elfring
2025-03-28 14:29 ` Matthew Wilcox
2025-03-31 12:08   ` Ye Liu
2025-03-31 12:21     ` [v4] " Markus Elfring
2025-03-31 12:51       ` Ye Liu
2025-03-31 13:15         ` Markus Elfring
2025-03-31 15:53         ` Matthew Wilcox
2025-04-02  2:51           ` Ye Liu
2025-03-31 15:59     ` [PATCH v4] " Matthew Wilcox
2025-04-02  2:49       ` Ye Liu
2025-04-03  3:55         ` Vishal Moola (Oracle)
2025-04-03  5:58           ` Ye Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250328014757.1212737-1-ye.liu@linux.dev \
    --to=ye.liu@linux.dev \
    --cc=Markus.Elfring@web.de \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liuye@kylinos.cn \
    --cc=sidhartha.kumar@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.