mm/pageblock: improve readability of some pageblock handling
Subsystems (2)
cover mm/pageblock: improve readability of some pageblock handling
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: First we could use PB_migratetype_bits to define MIGRATETYPE_MASK. Second use MIGRATETYPE_MASK to define MIGRATETYPE_AND_ISO_MASK instead of duplicate the definition.
Wei Yang (2):
mm/page_alloc: use xxx_pageblock_isolate() for better reading mm/pageblock-flags: simplify MIGRATETYPE_MASK definition
include/linux/pageblock-flags.h | 5 ++--- mm/page_alloc.c | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 mm/page_alloc: use xxx_pageblock_isolate() for better reading
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.
--- mm/page_alloc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
mm/page_alloc.c +3 -4
@@ -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); }/**
Signature · 1 line
2.34.1
Zi Yan
reviewerRe: [PATCH 1/2] mm/page_alloc: use xxx_pageblock_isolate() for better reading
Quoted 7 lines · Wei Yang
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.
Quoted 8 lines
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>--- mm/page_alloc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
LGTM. Reviewed-by: Zi Yan <[email protected]>
--
Best Regards,
Yan, Zi
Re: [PATCH 1/2] mm/page_alloc: use xxx_pageblock_isolate() for better reading
In reply to Wei YangQuoted 5 lines · Wei Yang
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.
Quoted 7 lines
No functional change intended.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>---
Signature · 3 lines
Cheers David / dhildenb
PATCH 2/2 mm/pageblock-flags: simplify MIGRATETYPE_MASK definition
In reply to Wei YangMIGRATETYPE_MASK is defined to be the mask of possible migratetype.
Define it with PB_migratetype_bits directly would be more clear.
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.
--- include/linux/pageblock-flags.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
include/linux/pageblock-flags.h +2 -3
@@ -37,11 +37,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_migratetype_bits) - 1)#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
Signature · 1 line
2.34.1
Re: [PATCH 2/2] mm/pageblock-flags: simplify MIGRATETYPE_MASK definition
Quoted 26 lines · Wei Yang
MIGRATETYPE_MASKis defined to be the mask of possible migratetype.Define it with
PB_migratetype_bitsdirectly would be more clear.Also,
MIGRATETYPE_AND_ISO_MASKisMIGRATETYPE_MASKadd isolation bit. UseMIGRATETYPE_MASKin the definition ofMIGRATETYPE_AND_ISO_MASKlooks cleaner.No functional change intended.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>--- include/linux/pageblock-flags.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)include/linux/pageblock-flags.h +0
-0@@ -37,11 +37,10 @@ enum pageblock_bits {#define NR_PAGEBLOCK_BITS (roundup_pow_of_two(__NR_PAGEBLOCK_BITS))
include/linux/pageblock-flags.h enum pageblock_bits { · line 46
Quoted 10 lines
include/linux/pageblock-flags.h +2
-3-#define MIGRATETYPE_MASK ((1UL << (PB_migrate_end + 1)) - 1) +#define MIGRATETYPE_MASK (BIT(PB_migratetype_bits) - 1)#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
Hm, I wonder if we can get rid of PB_migratetype_bits
include/linux/pageblock-flags.h +3 -4
@@ -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
And then just work with the bits. No magical computations.
Signature · 3 lines
Cheers David / dhildenb
Re: [PATCH 2/2] mm/pageblock-flags: simplify MIGRATETYPE_MASK definition
Quoted 60 lines · David Hildenbrand
Quoted 23 lines · Wei Yang
MIGRATETYPE_MASKis defined to be the mask of possible migratetype.Define it with
PB_migratetype_bitsdirectly would be more clear.Also,
MIGRATETYPE_AND_ISO_MASKisMIGRATETYPE_MASKadd isolation bit. UseMIGRATETYPE_MASKin the definition ofMIGRATETYPE_AND_ISO_MASKlooks cleaner.No functional change intended.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>--- include/linux/pageblock-flags.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)include/linux/pageblock-flags.h +0
-0include/linux/pageblock-flags.h enum pageblock_bits { · line 43
Quoted 10 lines
include/linux/pageblock-flags.h +2
-3@@ -37,11 +37,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_migratetype_bits) - 1)#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 Hm, I wonder if we can get rid of
PB_migratetype_bitsinclude/linux/pageblock-flags.h +3
-4@@ -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
Quoted 1 line
And then just work with the bits. No magical computations.
Something like this?
include/linux/pageblock-flags.h +5 -7
@@ -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_2 + 1) - 1)#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
mm/page_alloc.c +1 -1
@@ -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 >=BIT (PB_migrate_2 +1 ));VM_BUG_ON_PAGE (!zone_spans_pfn (page_zone (page), pfn), page); bitmap =get_pageblock_bitmap (page, pfn);
Signature · 2 lines
Wei Yang Help you, Help me
Re: [PATCH 2/2] mm/pageblock-flags: simplify MIGRATETYPE_MASK definition
Quoted 86 lines · Wei Yang
Quoted 60 lines · David Hildenbrand
Quoted 23 lines · Wei Yang
MIGRATETYPE_MASKis defined to be the mask of possible migratetype.Define it with
PB_migratetype_bitsdirectly would be more clear.Also,
MIGRATETYPE_AND_ISO_MASKisMIGRATETYPE_MASKadd isolation bit. UseMIGRATETYPE_MASKin the definition ofMIGRATETYPE_AND_ISO_MASKlooks cleaner.No functional change intended.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>--- include/linux/pageblock-flags.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)include/linux/pageblock-flags.h +0
-0include/linux/pageblock-flags.h enum pageblock_bits { · line 43
Quoted 10 lines
include/linux/pageblock-flags.h +2
-3@@ -37,11 +37,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_migratetype_bits) - 1)#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 Hm, I wonder if we can get rid of
PB_migratetype_bitsinclude/linux/pageblock-flags.h +3
-4@@ -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 Quoted 1 line
And then just work with the bits. No magical computations.
Something like this?
include/linux/pageblock-flags.h +3
-4@@ -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
include/linux/pageblock-flags.h enum pageblock_bits { · line 39
Quoted 5 lines
include/linux/pageblock-flags.h +1
-1@@ -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_2 + 1) - 1)
I'd just do PB_migrate_0|PB_migrate_1|PB_migrate_2 and have code that is easier to parse.
Signature · 3 lines
Cheers David / dhildenb
Zi Yan
reviewerRe: [PATCH 2/2] mm/pageblock-flags: simplify MIGRATETYPE_MASK definition
In reply to Wei YangQuoted 23 lines · Wei Yang
MIGRATETYPE_MASKis defined to be the mask of possible migratetype.Define it with
PB_migratetype_bitsdirectly would be more clear.Also,
MIGRATETYPE_AND_ISO_MASKisMIGRATETYPE_MASKadd isolation bit. UseMIGRATETYPE_MASKin the definition ofMIGRATETYPE_AND_ISO_MASKlooks cleaner.No functional change intended.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>--- include/linux/pageblock-flags.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)include/linux/pageblock-flags.h +0
-0
include/linux/pageblock-flags.h enum pageblock_bits { · line 40
Quoted 5 lines
include/linux/pageblock-flags.h +1
-1@@ -37,11 +37,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_migratetype_bits) - 1)
I am not sure about this one, even if PB_migrate_end + 1 == PB_migratetype_bits. PB_migrate_end represents a bit index, where PB_migratetype_bits means the number of the bits.
David's suggestion in another email might be better.
include/linux/pageblock-flags.h enum pageblock_bits { · line 46
Quoted 8 lines
include/linux/pageblock-flags.h +1
-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
This one looks good to me.
--
Best Regards,
Yan, Zi