linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [Patch v3 0/2] mm/pageblock: improve readability of some pageblock handling
@ 2025-08-27  7:01 Wei Yang
  2025-08-27  7:01 ` [Patch v3 1/2] mm/page_alloc: use xxx_pageblock_isolate() for better reading Wei Yang
  2025-08-27  7:01 ` [Patch v3 2/2] mm/pageblock-flags: remove PB_migratetype_bits/PB_migrate_end Wei Yang
  0 siblings, 2 replies; 4+ messages in thread
From: Wei Yang @ 2025-08-27  7:01 UTC (permalink / raw)
  To: akpm, david, lorenzo.stoakes, vbabka; +Cc: linux-mm, Wei Yang

During code reading, found two possible points to improve the readability of
pageblock handling.

Patch 1: isolate bit is standalone and there are dedicated helpers. Instead of
check the bit directly, we could use the helper to do it.

Patch 2: remove PB_migratetype_bits and PB_migrate_end to reduce magical
computation.

v2->v3:
    fix the definition of MIGRATETYPE_MASK, thanks ziy

v1->v2:
    remove PB_migratetype_bits and PB_migrate_end

Wei Yang (2):
  mm/page_alloc: use xxx_pageblock_isolate() for better reading
  mm/pageblock-flags: remove PB_migratetype_bits/PB_migrate_end

 include/linux/pageblock-flags.h | 12 +++++-------
 mm/page_alloc.c                 | 11 +++++------
 2 files changed, 10 insertions(+), 13 deletions(-)

-- 
2.34.1



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

* [Patch v3 1/2] mm/page_alloc: use xxx_pageblock_isolate() for better reading
  2025-08-27  7:01 [Patch v3 0/2] mm/pageblock: improve readability of some pageblock handling Wei Yang
@ 2025-08-27  7:01 ` Wei Yang
  2025-08-27  7:01 ` [Patch v3 2/2] mm/pageblock-flags: remove PB_migratetype_bits/PB_migrate_end Wei Yang
  1 sibling, 0 replies; 4+ messages in thread
From: Wei Yang @ 2025-08-27  7:01 UTC (permalink / raw)
  To: akpm, david, lorenzo.stoakes, vbabka; +Cc: linux-mm, Wei Yang, Zi Yan

Since commit e904bce2d9d4 ("mm/page_isolation: make page isolation a
standalone bit"), it provides dedicated helper to handle isolation.

Change to use these helpers to be better reading.

No functional change intended.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Acked-by: David Hildenbrand <david@redhat.com>
---
 mm/page_alloc.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index baead29b3e67..e534f31a6b39 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -538,8 +538,7 @@ static void set_pageblock_migratetype(struct page *page,
 			"Use set_pageblock_isolate() for pageblock isolation");
 		return;
 	}
-	VM_WARN_ONCE(get_pfnblock_bit(page, page_to_pfn(page),
-				      PB_migrate_isolate),
+	VM_WARN_ONCE(get_pageblock_isolate(page),
 		     "Use clear_pageblock_isolate() to unisolate pageblock");
 	/* MIGRATETYPE_AND_ISO_MASK clears PB_migrate_isolate if it is set */
 #endif
@@ -2058,9 +2057,9 @@ static unsigned long find_large_buddy(unsigned long start_pfn)
 static inline void toggle_pageblock_isolate(struct page *page, bool isolate)
 {
 	if (isolate)
-		set_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate);
+		set_pageblock_isolate(page);
 	else
-		clear_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate);
+		clear_pageblock_isolate(page);
 }
 
 /**
-- 
2.34.1



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

* [Patch v3 2/2] mm/pageblock-flags: remove PB_migratetype_bits/PB_migrate_end
  2025-08-27  7:01 [Patch v3 0/2] mm/pageblock: improve readability of some pageblock handling Wei Yang
  2025-08-27  7:01 ` [Patch v3 1/2] mm/page_alloc: use xxx_pageblock_isolate() for better reading Wei Yang
@ 2025-08-27  7:01 ` Wei Yang
  2025-08-27 11:30   ` David Hildenbrand
  1 sibling, 1 reply; 4+ messages in thread
From: Wei Yang @ 2025-08-27  7:01 UTC (permalink / raw)
  To: akpm, david, lorenzo.stoakes, vbabka; +Cc: linux-mm, Wei Yang, Zi Yan

enum pageblock_bits defines the meaning of pageblock bits. Currently
PB_migratetype_bits says the lowest 3 bits represents migratetype and
PB_migrate_end/MIGRATETYPE_MASK's definition rely on it with magical
computation.

Remove the definition of PB_migratetype_bits/PB_migrate_end. Use
PB_migrate_[0|1|2] to represent lowest bits for migratetype. Then we can
simplify related definition.

Also, MIGRATETYPE_AND_ISO_MASK is MIGRATETYPE_MASK add isolation bit.
Use MIGRATETYPE_MASK in the definition of MIGRATETYPE_AND_ISO_MASK looks
cleaner.

No functional change intended.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: David Hildenbrand <david@redhat.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>

---
v3: fix MIGRATETYPE_MASK defition, thanks ziy
v2: remove PB_migratetype_bits and PB_migrate_end
---
 include/linux/pageblock-flags.h | 12 +++++-------
 mm/page_alloc.c                 |  4 ++--
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/include/linux/pageblock-flags.h b/include/linux/pageblock-flags.h
index 6a44be0f39f4..e046278a01fa 100644
--- a/include/linux/pageblock-flags.h
+++ b/include/linux/pageblock-flags.h
@@ -13,12 +13,11 @@
 
 #include <linux/types.h>
 
-#define PB_migratetype_bits 3
 /* Bit indices that affect a whole block of pages */
 enum pageblock_bits {
-	PB_migrate,
-	PB_migrate_end = PB_migrate + PB_migratetype_bits - 1,
-			/* 3 bits required for migrate types */
+	PB_migrate_0,
+	PB_migrate_1,
+	PB_migrate_2,
 	PB_compact_skip,/* If set the block is skipped by compaction */
 
 #ifdef CONFIG_MEMORY_ISOLATION
@@ -37,11 +36,10 @@ enum pageblock_bits {
 
 #define NR_PAGEBLOCK_BITS (roundup_pow_of_two(__NR_PAGEBLOCK_BITS))
 
-#define MIGRATETYPE_MASK ((1UL << (PB_migrate_end + 1)) - 1)
+#define MIGRATETYPE_MASK (BIT(PB_migrate_0)|BIT(PB_migrate_1)|BIT(PB_migrate_2))
 
 #ifdef CONFIG_MEMORY_ISOLATION
-#define MIGRATETYPE_AND_ISO_MASK \
-	(((1UL << (PB_migrate_end + 1)) - 1) | BIT(PB_migrate_isolate))
+#define MIGRATETYPE_AND_ISO_MASK (MIGRATETYPE_MASK | BIT(PB_migrate_isolate))
 #else
 #define MIGRATETYPE_AND_ISO_MASK MIGRATETYPE_MASK
 #endif
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index e534f31a6b39..c1a18aaf8b41 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -355,7 +355,7 @@ static inline int pfn_to_bitidx(const struct page *page, unsigned long pfn)
 
 static __always_inline bool is_standalone_pb_bit(enum pageblock_bits pb_bit)
 {
-	return pb_bit > PB_migrate_end && pb_bit < __NR_PAGEBLOCK_BITS;
+	return pb_bit >= PB_compact_skip && pb_bit < __NR_PAGEBLOCK_BITS;
 }
 
 static __always_inline void
@@ -370,7 +370,7 @@ get_pfnblock_bitmap_bitidx(const struct page *page, unsigned long pfn,
 #else
 	BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4);
 #endif
-	BUILD_BUG_ON(__MIGRATE_TYPE_END >= (1 << PB_migratetype_bits));
+	BUILD_BUG_ON(__MIGRATE_TYPE_END > MIGRATETYPE_MASK);
 	VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page);
 
 	bitmap = get_pageblock_bitmap(page, pfn);
-- 
2.34.1



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

* Re: [Patch v3 2/2] mm/pageblock-flags: remove PB_migratetype_bits/PB_migrate_end
  2025-08-27  7:01 ` [Patch v3 2/2] mm/pageblock-flags: remove PB_migratetype_bits/PB_migrate_end Wei Yang
@ 2025-08-27 11:30   ` David Hildenbrand
  0 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2025-08-27 11:30 UTC (permalink / raw)
  To: Wei Yang, akpm, lorenzo.stoakes, vbabka; +Cc: linux-mm, Zi Yan

On 27.08.25 09:01, Wei Yang wrote:
> enum pageblock_bits defines the meaning of pageblock bits. Currently
> PB_migratetype_bits says the lowest 3 bits represents migratetype and
> PB_migrate_end/MIGRATETYPE_MASK's definition rely on it with magical
> computation.
> 
> Remove the definition of PB_migratetype_bits/PB_migrate_end. Use
> PB_migrate_[0|1|2] to represent lowest bits for migratetype. Then we can
> simplify related definition.
> 
> Also, MIGRATETYPE_AND_ISO_MASK is MIGRATETYPE_MASK add isolation bit.
> Use MIGRATETYPE_MASK in the definition of MIGRATETYPE_AND_ISO_MASK looks
> cleaner.
> 
> No functional change intended.
> 
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> Cc: Zi Yan <ziy@nvidia.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: David Hildenbrand <david@redhat.com>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Reviewed-by: Zi Yan <ziy@nvidia.com>

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers

David / dhildenb



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

end of thread, other threads:[~2025-08-27 11:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27  7:01 [Patch v3 0/2] mm/pageblock: improve readability of some pageblock handling Wei Yang
2025-08-27  7:01 ` [Patch v3 1/2] mm/page_alloc: use xxx_pageblock_isolate() for better reading Wei Yang
2025-08-27  7:01 ` [Patch v3 2/2] mm/pageblock-flags: remove PB_migratetype_bits/PB_migrate_end Wei Yang
2025-08-27 11:30   ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).