Linux Power Management development
 help / color / mirror / Atom feed
From: Brendan Jackman <jackmanb@google.com>
To: vbabka@kernel.org
Cc: akpm@linux-foundation.org, axelrasmussen@google.com,
	baohua@kernel.org,  david@kernel.org, hannes@cmpxchg.org,
	jackmanb@google.com, kasong@tencent.com,  lenb@kernel.org,
	liam@infradead.org, linux-kernel@vger.kernel.org,
	 linux-mm@kvack.org, linux-pm@vger.kernel.org, ljs@kernel.org,
	mhocko@suse.com,  pavel@kernel.org, qi.zheng@linux.dev,
	rafael@kernel.org, rppt@kernel.org,  shakeel.butt@linux.dev,
	surenb@google.com, weixugc@google.com,  yuanchu@google.com,
	ziy@nvidia.com
Subject: [PATCH v2] mm/page_alloc: tidy up pindex helpers
Date: Sun, 17 May 2026 23:05:56 +0000	[thread overview]
Message-ID: <20260517230556.590677-1-jackmanb@google.com> (raw)
In-Reply-To: <4074a816-9e75-45a6-8141-25459bcc106b@kernel.org>

The ifdefs are not technically needed here, everything used here is
always defined, so switch to IS_ENABLED() to make things a little less
tiresome to read.

Also, Vlastimil pointed out that the VM_BUG_ON()s have fallen out of
favour, so remove them.

Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Signed-off-by: Brendan Jackman <jackmanb@google.com>
---

>> And it's all internal to page alloc so I'd just drop those checks
>> completely at this point.
>
> But, I won't die on the above hill, if people really hate BUG that much
> happy to go with the flow.
>
> In that case, I'd suggest we drop them as a separate patch.

Oh, actually no, the VM_BUG_ONs were the main thing making the ifdefs
awkward, it makes sense to drop them together. Here's a combined patch.

 mm/page_alloc.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 5d6144c8860ed..76d5d9464e2ef 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -650,19 +650,12 @@ static void bad_page(struct page *page, const char *reason)
 
 static inline unsigned int order_to_pindex(int migratetype, int order)
 {
+	if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
+		bool movable = migratetype == MIGRATE_MOVABLE;
 
-#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-	bool movable;
-	if (order > PAGE_ALLOC_COSTLY_ORDER) {
-		VM_BUG_ON(!is_pmd_order(order));
-
-		movable = migratetype == MIGRATE_MOVABLE;
-
-		return NR_LOWORDER_PCP_LISTS + movable;
+		if (order > PAGE_ALLOC_COSTLY_ORDER)
+			return NR_LOWORDER_PCP_LISTS + movable;
 	}
-#else
-	VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER);
-#endif
 
 	return (MIGRATE_PCPTYPES * order) + migratetype;
 }
@@ -671,12 +664,10 @@ static inline int pindex_to_order(unsigned int pindex)
 {
 	int order = pindex / MIGRATE_PCPTYPES;
 
-#ifdef CONFIG_TRANSPARENT_HUGEPAGE
-	if (pindex >= NR_LOWORDER_PCP_LISTS)
-		order = HPAGE_PMD_ORDER;
-#else
-	VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER);
-#endif
+	if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
+		if (pindex >= NR_LOWORDER_PCP_LISTS)
+			order = HPAGE_PMD_ORDER;
+	}
 
 	return order;
 }
-- 
2.51.2


  parent reply	other threads:[~2026-05-17 23:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13 12:35 [PATCH 0/4] mm: misc cleanups from __GFP_UNMAPPED series Brendan Jackman
2026-05-13 12:35 ` [PATCH 1/4] mm: introduce for_each_free_list() Brendan Jackman
2026-05-13 14:44   ` Mike Rapoport
2026-05-13 17:07   ` Vlastimil Babka (SUSE)
2026-05-13 12:35 ` [PATCH 2/4] mm/page_alloc: don't overload migratetype in find_suitable_fallback() Brendan Jackman
2026-05-13 12:35 ` [PATCH 3/4] mm: rejig pageblock mask definitions Brendan Jackman
2026-05-13 12:35 ` [PATCH 4/4] mm/page_alloc: remove ifdefs from pindex helpers Brendan Jackman
2026-05-13 17:19   ` Vlastimil Babka (SUSE)
2026-05-15 13:15     ` Brendan Jackman
2026-05-15 15:29       ` Vlastimil Babka (SUSE)
2026-05-17 23:05     ` Brendan Jackman [this message]
2026-05-18 18:15 ` [PATCH 0/4] mm: misc cleanups from __GFP_UNMAPPED series Andrew Morton
2026-05-18 20:20   ` Brendan Jackman
2026-05-18 20:48     ` Andrew Morton
2026-05-18 20:58       ` Brendan Jackman
2026-05-22  7:59         ` Vlastimil Babka (SUSE)
2026-05-23  3:11           ` Andrew Morton
2026-05-26 11:13             ` Brendan Jackman

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=20260517230556.590677-1-jackmanb@google.com \
    --to=jackmanb@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=lenb@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=pavel@kernel.org \
    --cc=qi.zheng@linux.dev \
    --cc=rafael@kernel.org \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.com \
    --cc=ziy@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox