mm: reuse pageblock_start/end_pfn() macro
Subsystems (4)
PATCH 1/2 mm: reuse pageblock_start/end_pfn() macro
Move pageblock_start_pfn/pageblock_end_pfn() into pageblock-flags.h, then they could be used somewhere else, not only in compaction.
--- include/linux/pageblock-flags.h | 2 ++ mm/compaction.c | 2 -- mm/memblock.c | 2 +- mm/page_alloc.c | 13 ++++++------- mm/page_isolation.c | 2 +- mm/page_owner.c | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-)
include/linux/pageblock-flags.h +2 -0
@@ -53,6 +53,8 @@ extern unsigned int pageblock_order;#endif /* CONFIG_HUGETLB_PAGE */ #define pageblock_nr_pages (1UL << pageblock_order) +#define pageblock_start_pfn (pfn) round_down(pfn, pageblock_nr_pages) +#define pageblock_end_pfn (pfn) ALIGN((pfn + 1), pageblock_nr_pages)/* Forward declaration */ struct page ;
mm/compaction.c +0 -2
@@ -52,8 +52,6 @@ static inline void count_compact_events(enum vm_event_item item, long delta)#define block_start_pfn (pfn, order) round_down(pfn, 1UL << (order))#define block_end_pfn (pfn, order) ALIGN((pfn) + 1, 1UL << (order)) -#define pageblock_start_pfn (pfn) block_start_pfn(pfn, pageblock_order) -#define pageblock_end_pfn (pfn) block_end_pfn(pfn, pageblock_order)/* * Page order with-respect-to which proactive compaction
mm/memblock.c +1 -1
@@ -2000,7 +2000,7 @@ static void __init free_unused_memmap(void)* presume that there are no holes in the memory map inside * a pageblock */ - start =round_down (start, pageblock_nr_pages); + start =pageblock_start_pfn (start);/* * If we had a previous bank, and there is a space
mm/page_alloc.c +6 -7
@@ -544,7 +544,7 @@ static inline int pfn_to_bitidx(const struct page *page, unsigned long pfn)#ifdef CONFIG_SPARSEMEM pfn &= (PAGES_PER_SECTION -1 );#else - pfn = pfn -round_down (page_zone (page)->zone_start_pfn, pageblock_nr_pages); + pfn = pfn -pageblock_start_pfn (page_zone (page)->zone_start_pfn);#endif /* CONFIG_SPARSEMEM */ return (pfn >> pageblock_order) *NR_PAGEBLOCK_BITS ; }
@@ -1857,7 +1857,7 @@ void set_zone_contiguous(struct zone *zone)unsigned long block_start_pfn = zone->zone_start_pfn;unsigned long block_end_pfn; - block_end_pfn =ALIGN (block_start_pfn +1 , pageblock_nr_pages); + block_end_pfn =pageblock_end_pfn (block_start_pfn);for (; block_start_pfn <zone_end_pfn (zone); block_start_pfn = block_end_pfn, block_end_pfn += pageblock_nr_pages) {
@@ -2653,8 +2653,8 @@ int move_freepages_block(struct zone *zone, struct page *page, *num_movable =0 ; pfn =page_to_pfn (page); - start_pfn = pfn & ~(pageblock_nr_pages -1 ); - end_pfn = start_pfn + pageblock_nr_pages -1 ; + start_pfn =pageblock_start_pfn (pfn); + end_pfn =pageblock_end_pfn (pfn) -1 ;/* Do not cross zone boundaries */ if (!zone_spans_pfn (zone, start_pfn))
@@ -6939,9 +6939,8 @@ static void __init init_unavailable_range(unsigned long spfn,u64 pgcnt =0 ;for (pfn = spfn; pfn < epfn; pfn++) { -if (!pfn_valid (ALIGN_DOWN (pfn, pageblock_nr_pages))) { - pfn =ALIGN_DOWN (pfn, pageblock_nr_pages) - + pageblock_nr_pages -1 ; +if (!pfn_valid (pageblock_start_pfn (pfn))) { + pfn =pageblock_end_pfn (pfn) -1 ;continue ; }__init_single_page (pfn_to_page (pfn), pfn, zone, node);
mm/page_isolation.c +1 -1
@@ -172,7 +172,7 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_* to avoid redundant checks. */ check_unmovable_start =max (page_to_pfn (page), start_pfn); - check_unmovable_end =min (ALIGN (page_to_pfn (page) +1 , pageblock_nr_pages), + check_unmovable_end =min (pageblock_end_pfn (page_to_pfn (page)), end_pfn); unmovable = has_unmovable_pages(check_unmovable_start, check_unmovable_end,
mm/page_owner.c +2 -2
@@ -297,7 +297,7 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m,continue ; } - block_end_pfn =ALIGN (pfn +1 , pageblock_nr_pages); + block_end_pfn =pageblock_end_pfn (pfn); block_end_pfn =min (block_end_pfn, end_pfn); pageblock_mt =get_pageblock_migratetype (page);
@@ -637,7 +637,7 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)continue ; } - block_end_pfn =ALIGN (pfn +1 , pageblock_nr_pages); + block_end_pfn =pageblock_end_pfn (pfn); block_end_pfn =min (block_end_pfn, end_pfn);for (; pfn < block_end_pfn; pfn++) {
Signature · 1 line
2.35.3
PATCH 2/2 mm: add pageblock_aligned() macro
Add pageblock_aligned() and use it to simplify code.
--- include/linux/pageblock-flags.h | 1 + mm/compaction.c | 8 ++++---- mm/memory_hotplug.c | 6 ++---- mm/page_alloc.c | 17 +++++++---------- mm/page_isolation.c | 2 +- 5 files changed, 15 insertions(+), 19 deletions(-)
include/linux/pageblock-flags.h +1 -0
@@ -53,6 +53,7 @@ extern unsigned int pageblock_order;#endif /* CONFIG_HUGETLB_PAGE */ #define pageblock_nr_pages (1UL << pageblock_order) +#define pageblock_aligned (pfn) IS_ALIGNED((unsigned long)(pfn), pageblock_nr_pages)#define pageblock_start_pfn (pfn) round_down(pfn, pageblock_nr_pages)#define pageblock_end_pfn (pfn) ALIGN((pfn + 1), pageblock_nr_pages)
mm/compaction.c +4 -4
@@ -402,7 +402,7 @@ static bool test_and_set_skip(struct compact_control *cc, struct page *page,if (cc->ignore_skip_hint)return false; -if (!IS_ALIGNED (pfn, pageblock_nr_pages)) +if (!pageblock_aligned (pfn))return false; skip =get_pageblock_skip (page);
@@ -884,7 +884,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,* COMPACT_CLUSTER_MAX at a time so the second call must * not falsely conclude that the block should be skipped. */ -if (!valid_page &&IS_ALIGNED (low_pfn, pageblock_nr_pages)) { +if (!valid_page &&pageblock_aligned (low_pfn)) {if (!isolation_suitable (cc, page)) { low_pfn = end_pfn; page =NULL ;
@@ -1936,7 +1936,7 @@ static isolate_migrate_t isolate_migratepages(struct compact_control *cc)* before making it "skip" so other compaction instances do * not scan the same block. */ -if (IS_ALIGNED (low_pfn, pageblock_nr_pages) && +if (pageblock_aligned (low_pfn) && !fast_find_block && !isolation_suitable (cc, page))continue ;
@@ -2122,7 +2122,7 @@ static enum compact_result __compact_finished(struct compact_control *cc)* migration source is unmovable/reclaimable but it's not worth * special casing. */ -if (!IS_ALIGNED (cc->migrate_pfn, pageblock_nr_pages)) +if (!pageblock_aligned (cc->migrate_pfn))return COMPACT_CONTINUE ;/* Direct compactor: Is a suitable page free? */
mm/memory_hotplug.c +2 -4
@@ -1085,8 +1085,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages,* of the physical memory space for vmemmaps. That space is pageblock * aligned. */ -if (WARN_ON_ONCE (!nr_pages || - !IS_ALIGNED (pfn, pageblock_nr_pages) || +if (WARN_ON_ONCE (!nr_pages || !pageblock_aligned (pfn) || !IS_ALIGNED (pfn + nr_pages,PAGES_PER_SECTION )))return -EINVAL ;
@@ -1806,8 +1805,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages,* of the physical memory space for vmemmaps. That space is pageblock * aligned. */ -if (WARN_ON_ONCE (!nr_pages || - !IS_ALIGNED (start_pfn, pageblock_nr_pages) || +if (WARN_ON_ONCE (!nr_pages || !pageblock_aligned (start_pfn) || !IS_ALIGNED (start_pfn + nr_pages,PAGES_PER_SECTION )))return -EINVAL ;
mm/page_alloc.c +7 -10
@@ -1892,15 +1892,14 @@ static void __init deferred_free_range(unsigned long pfn, page =pfn_to_page (pfn);/* Free a large naturally-aligned chunk if possible */ -if (nr_pages == pageblock_nr_pages && - (pfn & (pageblock_nr_pages -1 )) ==0 ) { +if (nr_pages == pageblock_nr_pages &&pageblock_aligned (pfn)) {set_pageblock_migratetype (page,MIGRATE_MOVABLE );__free_pages_core (page, pageblock_order);return ; }for (i =0 ; i < nr_pages; i++, page++, pfn++) { -if ((pfn & (pageblock_nr_pages -1 )) ==0 ) +if (pageblock_aligned (pfn))set_pageblock_migratetype (page,MIGRATE_MOVABLE );__free_pages_core (page,0 ); }
@@ -1928,7 +1927,7 @@ static inline void __init pgdat_init_report_one_done(void)*/ static inline bool __init deferred_pfn_valid (unsigned long pfn) { -if (!(pfn & (pageblock_nr_pages -1 )) && !pfn_valid (pfn)) +if (!pageblock_aligned (pfn) && !pfn_valid (pfn))return false;return true; }
@@ -1940,14 +1939,13 @@ static inline bool __init deferred_pfn_valid(unsigned long pfn)static void __init deferred_free_pages (unsigned long pfn,unsigned long end_pfn) { -unsigned long nr_pgmask = pageblock_nr_pages -1 ;unsigned long nr_free =0 ;for (; pfn < end_pfn; pfn++) {if (!deferred_pfn_valid (pfn)) {deferred_free_range (pfn - nr_free, nr_free); nr_free =0 ; - }else if (!(pfn & nr_pgmask)) { + }else if (!pageblock_aligned (pfn)) {deferred_free_range (pfn - nr_free, nr_free); nr_free =1 ; }else {
@@ -1967,7 +1965,6 @@ static unsigned long __init deferred_init_pages(struct zone *zone,unsigned long pfn, unsigned long end_pfn) { -unsigned long nr_pgmask = pageblock_nr_pages -1 ; int nid = zone_to_nid(zone);unsigned long nr_pages =0 ;int zid =zone_idx (zone);
@@ -1977,7 +1974,7 @@ static unsigned long __init deferred_init_pages(struct zone *zone,if (!deferred_pfn_valid (pfn)) { page =NULL ;continue ; - }else if (!page || !(pfn & nr_pgmask)) { + }else if (!page || !pageblock_aligned (pfn)) { page =pfn_to_page (pfn); }else { page++;
@@ -6759,7 +6756,7 @@ void __meminit memmap_init_range(unsigned long size, int nid, unsigned long zone* such that unmovable allocations won't be scattered all * over the place during system boot. */ -if (IS_ALIGNED (pfn, pageblock_nr_pages)) { +if (pageblock_aligned (pfn)) {set_pageblock_migratetype (page, migratetype);cond_resched (); }
@@ -6802,7 +6799,7 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn,* Please note that MEMINIT_HOTPLUG path doesn't clear memmap * because this is done early in section_activate() */ -if (IS_ALIGNED (pfn, pageblock_nr_pages)) { +if (pageblock_aligned (pfn)) {set_pageblock_migratetype (page,MIGRATE_MOVABLE );cond_resched (); }
mm/page_isolation.c +1 -1
@@ -311,7 +311,7 @@ static int isolate_single_pageblock(unsigned long boundary_pfn, int flags,struct zone *zone;int ret; -VM_BUG_ON (!IS_ALIGNED (boundary_pfn, pageblock_nr_pages)); +VM_BUG_ON (!pageblock_aligned (boundary_pfn));if (isolate_before) isolate_pageblock = boundary_pfn - pageblock_nr_pages;
Signature · 1 line
2.35.3
Re: [PATCH 2/2] mm: add pageblock_aligned() macro
Quoted 4 lines · Kefeng Wang
Add
pageblock_aligned()and use it to simplify code.Signed-off-by Kefeng Wang <[email protected]>---
[...]
mm/page_alloc.c static unsigned long __init deferred_init_pages(struct zone *zone, · line 1980
Quoted 9 lines
mm/page_alloc.c +0
-2-unsigned long nr_pgmask = pageblock_nr_pages -1 ;int nid =zone_to_nid (zone);unsigned long nr_pages =0 ;int zid =zone_idx (zone);@@ -1977,7 +1974,7 @@ static unsigned long __init deferred_init_pages(struct zone *zone,if (!deferred_pfn_valid (pfn)) { page =NULL ;continue ; - }else if (!page || !(pfn & nr_pgmask)) {
I didn't sleep too well this night and am tired, please tell me why I'm wrong :)
"pfn & (pageblock_nr_pages - 1)" is true if the pageblock is not aligned
E.g., pfn = 1, pageblock_nr_pages = 512
pfn & (pageblock_nr_pages - 1)
-> 1 & (512 - 1)
-> 1 & 511
-> true
"!(pfn & (pageblock_nr_pages - 1))" is true if the pageblock is aligned -> !(true)
-> false
However, "!pageblock_aligned(1)" = true
mm/page_alloc.c static unsigned long __init deferred_init_pages(struct zone *zone, · line 1977
Quoted 1 line
mm/page_alloc.c +1
-0+ }else if (!page || !pageblock_aligned (pfn)) {
So shouldn't this be "pageblock_aligned(pfn)"
?
Quoted 3 lines
mm/page_alloc.c +0
-0page =pfn_to_page (pfn); }else { page++;
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH 2/2] mm: add pageblock_aligned() macro
Quoted 7 lines · David Hildenbrand
Quoted 4 lines · Kefeng Wang
Add
pageblock_aligned()and use it to simplify code.Signed-off-by Kefeng Wang<[email protected]>---
[...]
Quoted 12 lines
mm/page_alloc.c static unsigned long __init deferred_init_pages(struct zone *zone, · line 1980
Quoted 9 lines
mm/page_alloc.c +0
-2-unsigned long nr_pgmask = pageblock_nr_pages -1 ;int nid =zone_to_nid (zone);unsigned long nr_pages =0 ;int zid =zone_idx (zone);@@ -1977,7 +1974,7 @@ static unsigned long __init deferred_init_pages(struct zone *zone,if (!deferred_pfn_valid (pfn)) { page =NULL ;continue ; - }else if (!page || !(pfn & nr_pgmask)) {I didn't sleep too well this night and am tired, please tell me why I'm wrong :)
Wish you have a good reset :)
Quoted 15 lines
"pfn & (
pageblock_nr_pages- 1)" is true if the pageblock is not alignedE.g., pfn = 1,
pageblock_nr_pages= 512pfn & (
pageblock_nr_pages- 1)
-> 1 & (512 - 1)
-> 1 & 511
-> true"!(pfn & (
pageblock_nr_pages- 1))" is true if the pageblock is aligned -> !(true)
-> false
Quoted 4 lines
However, "!pageblock_aligned(1)" = true
mm/page_alloc.c static unsigned long __init deferred_init_pages(struct zone *zone, · line 1977
Quoted 1 line
mm/page_alloc.c +1
-0+ }else if (!page || !pageblock_aligned (pfn)) {
pageblock_aligned(pfn) IS_ALIGNED((unsigned long)(pfn), pageblock_nr_pages)
#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) (((pfn) & (pageblock_nr_pages - 1)) == 0) -> ((1 & 512 -1) == 0) -> ((1 & 511) == 0) -> ((511) == 0) -> false right ?
Quoted 10 lines
So shouldn't this be "
pageblock_aligned(pfn)"?
Quoted 3 lines
mm/page_alloc.c +0
-0page =pfn_to_page (pfn); }else { page++;
Re: [PATCH 2/2] mm: add pageblock_aligned() macro
Quoted 20 lines · Kefeng Wang
Quoted 7 lines · David Hildenbrand
Quoted 4 lines · Kefeng Wang
Add
pageblock_aligned()and use it to simplify code.Signed-off-by Kefeng Wang <[email protected]>---
[...]
Quoted 11 lines
mm/page_alloc.c static unsigned long __init deferred_init_pages(struct zone *zone, · line 1980
Quoted 9 lines
mm/page_alloc.c +0
-2-unsigned long nr_pgmask = pageblock_nr_pages -1 ;int nid =zone_to_nid (zone);unsigned long nr_pages =0 ;int zid =zone_idx (zone);@@ -1977,7 +1974,7 @@ static unsigned long __init deferred_init_pages(struct zone *zone,if (!deferred_pfn_valid (pfn)) { page =NULL ;continue ; - }else if (!page || !(pfn & nr_pgmask)) {I didn't sleep too well this night and am tired, please tell me why I'm wrong :)
Quoted 1 line
Wish you have a good reset :)
Thanks, the headache isn't helping :D
Quoted 17 lines
Quoted 17 lines
"pfn & (
pageblock_nr_pages- 1)" is true if the pageblock is not alignedE.g., pfn = 1,
pageblock_nr_pages= 512pfn & (
pageblock_nr_pages- 1)
-> 1 & (512 - 1)
-> 1 & 511
-> true"!(pfn & (
pageblock_nr_pages- 1))" is true if the pageblock is aligned -> !(true)
-> falseHowever, "!pageblock_aligned(1)" = true
Quoted 8 lines
Quoted 1 line
mm/page_alloc.c static unsigned long __init deferred_init_pages(struct zone *zone, · line 1977
Quoted 1 line
mm/page_alloc.c +1
-0+ }else if (!page || !pageblock_aligned (pfn)) {
pageblock_aligned(pfn)IS_ALIGNED((unsigned long)(pfn), pageblock_nr_pages)#define
IS_ALIGNED(x, a)(((x) & ((typeof(x))(a) - 1)) == 0) (((pfn) & (pageblock_nr_pages- 1)) == 0) -> ((1 & 512 -1) == 0) -> ((1 & 511) ==
0) -> ((511) == 0) -> false
right ?
yes ... and inverting that would give you "true", which is not what we want?
Again, sorry if I'm wrong ...
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH 2/2] mm: add pageblock_aligned() macro
Quoted 40 lines · David Hildenbrand
Quoted 19 lines · Kefeng Wang
Quoted 7 lines · David Hildenbrand
Quoted 4 lines · Kefeng Wang
Add
pageblock_aligned()and use it to simplify code.Signed-off-by Kefeng Wang <[email protected]>---
[...]
Quoted 11 lines
mm/page_alloc.c static unsigned long __init deferred_init_pages(struct zone *zone, · line 1980
Quoted 9 lines
mm/page_alloc.c +0
-2-unsigned long nr_pgmask = pageblock_nr_pages -1 ;int nid =zone_to_nid (zone);unsigned long nr_pages =0 ;int zid =zone_idx (zone);@@ -1977,7 +1974,7 @@ static unsigned long __init deferred_init_pages(struct zone *zone,if (!deferred_pfn_valid (pfn)) { page =NULL ;continue ; - }else if (!page || !(pfn & nr_pgmask)) {I didn't sleep too well this night and am tired, please tell me why I'm wrong :)
Quoted 1 line
Wish you have a good reset :)
Thanks, the headache isn't helping :D
Quoted 17 lines
Quoted 17 lines
"pfn & (
pageblock_nr_pages- 1)" is true if the pageblock is not alignedE.g., pfn = 1,
pageblock_nr_pages= 512pfn & (
pageblock_nr_pages- 1)
-> 1 & (512 - 1)
-> 1 & 511
-> true"!(pfn & (
pageblock_nr_pages- 1))" is true if the pageblock is aligned -> !(true)
-> falseHowever, "!pageblock_aligned(1)" = true
Quoted 9 lines
Quoted 7 lines
Quoted 1 line
mm/page_alloc.c static unsigned long __init deferred_init_pages(struct zone *zone, · line 1977
Quoted 1 line
mm/page_alloc.c +1
-0+ }else if (!page || !pageblock_aligned (pfn)) {
pageblock_aligned(pfn)IS_ALIGNED((unsigned long)(pfn), pageblock_nr_pages)#define
IS_ALIGNED(x, a)(((x) & ((typeof(x))(a) - 1)) == 0) (((pfn) & (pageblock_nr_pages- 1)) == 0) -> ((1 & 512 -1) == 0) -> ((1 & 511) ==
0) -> ((511) == 0) -> false
right ?yes ... and inverting that would give you "true", which is not what we want?
oops... it's my fault, looks like I need to have a reset to save my brain...
Quoted 2 lines
Again, sorry if I'm wrong ...
Quoted 18 lines · Kefeng Wang
Move pageblock_start_pfn/pageblock_end_pfn() into
pageblock-flags.h, then they could be used somewhere else, not only in compaction.Signed-off-by Kefeng Wang <[email protected]>--- include/linux/pageblock-flags.h | 2 ++ mm/compaction.c | 2 -- mm/memblock.c | 2 +- mm/page_alloc.c | 13 ++++++------- mm/page_isolation.c | 2 +- mm/page_owner.c | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-)include/linux/pageblock-flags.h +0
-0
include/linux/pageblock-flags.h extern unsigned int pageblock_order; · line 58
Quoted 6 lines
include/linux/pageblock-flags.h +2
-0@@ -53,6 +53,8 @@ extern unsigned int pageblock_order;#endif /* CONFIG_HUGETLB_PAGE */ #define pageblock_nr_pages (1UL << pageblock_order) +#define pageblock_start_pfn (pfn) round_down(pfn, pageblock_nr_pages) +#define pageblock_end_pfn (pfn) ALIGN((pfn + 1), pageblock_nr_pages)
I'd naturally have paired ALIGN with ALIGN_DOWN -- or round_up with round_down. (You're replacing one instance where ALIGN_DOWN was used at least.)
But maybe there is an obvious reason that I am missing :)
Quoted 78 lines
include/linux/pageblock-flags.h +0
-0/* Forward declaration */ struct page ;mm/compaction.c +0
-2@@ -52,8 +52,6 @@ static inline void count_compact_events(enum vm_event_item item, long delta)#define block_start_pfn (pfn, order) round_down(pfn, 1UL << (order))#define block_end_pfn (pfn, order) ALIGN((pfn) + 1, 1UL << (order)) -#define pageblock_start_pfn (pfn) block_start_pfn(pfn, pageblock_order) -#define pageblock_end_pfn (pfn) block_end_pfn(pfn, pageblock_order)/* * Page order with-respect-to which proactive compaction mm/memblock.c +1
-1@@ -2000,7 +2000,7 @@ static void __init free_unused_memmap(void)* presume that there are no holes in the memory map inside * a pageblock */ - start =round_down (start, pageblock_nr_pages); + start =pageblock_start_pfn (start);/* * If we had a previous bank, and there is a space mm/page_alloc.c +6
-7@@ -544,7 +544,7 @@ static inline int pfn_to_bitidx(const struct page *page, unsigned long pfn)#ifdef CONFIG_SPARSEMEM pfn &= (PAGES_PER_SECTION -1 );#else - pfn = pfn -round_down (page_zone (page)->zone_start_pfn, pageblock_nr_pages); + pfn = pfn -pageblock_start_pfn (page_zone (page)->zone_start_pfn);#endif /* CONFIG_SPARSEMEM */ return (pfn >> pageblock_order) *NR_PAGEBLOCK_BITS ; }@@ -1857,7 +1857,7 @@ void set_zone_contiguous(struct zone *zone)unsigned long block_start_pfn = zone->zone_start_pfn;unsigned long block_end_pfn; - block_end_pfn =ALIGN (block_start_pfn +1 , pageblock_nr_pages); + block_end_pfn =pageblock_end_pfn (block_start_pfn);for (; block_start_pfn <zone_end_pfn (zone); block_start_pfn = block_end_pfn, block_end_pfn += pageblock_nr_pages) {@@ -2653,8 +2653,8 @@ int move_freepages_block(struct zone *zone, struct page *page, *num_movable =0 ; pfn =page_to_pfn (page); - start_pfn = pfn & ~(pageblock_nr_pages -1 ); - end_pfn = start_pfn + pageblock_nr_pages -1 ; + start_pfn =pageblock_start_pfn (pfn); + end_pfn =pageblock_end_pfn (pfn) -1 ;/* Do not cross zone boundaries */ if (!zone_spans_pfn (zone, start_pfn))@@ -6939,9 +6939,8 @@ static void __init init_unavailable_range(unsigned long spfn,u64 pgcnt =0 ;for (pfn = spfn; pfn < epfn; pfn++) { -if (!pfn_valid (ALIGN_DOWN (pfn, pageblock_nr_pages))) { - pfn =ALIGN_DOWN (pfn, pageblock_nr_pages) - + pageblock_nr_pages -1 ; +if (!pfn_valid (pageblock_start_pfn (pfn))) { + pfn =pageblock_end_pfn (pfn) -1 ;continue ; }__init_single_page (pfn_to_page (pfn), pfn, zone, node);mm/page_isolation.c +0
-0
mm/page_isolation.c static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ · line 177
Quoted 7 lines
mm/page_isolation.c +1
-1@@ -172,7 +172,7 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_* to avoid redundant checks. */ check_unmovable_start =max (page_to_pfn (page), start_pfn); - check_unmovable_end =min (ALIGN (page_to_pfn (page) +1 , pageblock_nr_pages), + check_unmovable_end =min (pageblock_end_pfn (page_to_pfn (page)), end_pfn);
There are some more cases that might need care as well:
mm/memblock.c: prev_end = ALIGN(end, pageblock_nr_pages); mm/memblock.c: prev_end = ALIGN(end, pageblock_nr_pages); mm/page_isolation.c: VM_BUG_ON(ALIGN_DOWN(start_pfn, pageblock_nr_pages) != mm/page_isolation.c: ALIGN_DOWN(end_pfn - 1, pageblock_nr_pages)); mm/page_isolation.c: unsigned long isolate_start = ALIGN_DOWN(start_pfn, pageblock_nr_pages); mm/page_isolation.c: unsigned long isolate_end = ALIGN(end_pfn, pageblock_nr_pages); mm/page_isolation.c: unsigned long isolate_start = ALIGN_DOWN(start_pfn, pageblock_nr_pages); mm/page_isolation.c: unsigned long isolate_end = ALIGN(end_pfn, pageblock_nr_pages);
Signature · 3 lines
Thanks, David / dhildenb
Quoted 21 lines · David Hildenbrand
Quoted 20 lines · Kefeng Wang
Move pageblock_start_pfn/pageblock_end_pfn() into
pageblock-flags.h, then they could be used somewhere else, not only in compaction.Signed-off-by Kefeng Wang <[email protected]>--- include/linux/pageblock-flags.h | 2 ++ mm/compaction.c | 2 -- mm/memblock.c | 2 +- mm/page_alloc.c | 13 ++++++------- mm/page_isolation.c | 2 +- mm/page_owner.c | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-)include/linux/pageblock-flags.h +0
-0@@ -53,6 +53,8 @@ extern unsigned int pageblock_order;#endif /* CONFIG_HUGETLB_PAGE */
Quoted 6 lines
include/linux/pageblock-flags.h extern unsigned int pageblock_order; · line 58
Quoted 4 lines
include/linux/pageblock-flags.h +2
-0#define pageblock_nr_pages (1UL << pageblock_order) +#define pageblock_start_pfn (pfn) round_down(pfn, pageblock_nr_pages) +#define pageblock_end_pfn (pfn) ALIGN((pfn + 1), pageblock_nr_pages)I'd naturally have paired ALIGN with
ALIGN_DOWN-- orround_upwithround_down. (You're replacing one instance whereALIGN_DOWNwas used at least.)
I think they are same for pageblock usage,but the original macro introduced from Vlastimil
(06b6640a3902 mm, compaction: wrap calculating first and last pfn of pageblock), let's
wait for Vlastimil to see if there are some background.
Quoted 92 lines
But maybe there is an obvious reason that I am missing :)
Quoted 78 lines
include/linux/pageblock-flags.h +0
-0/* Forward declaration */ struct page ;mm/compaction.c +0
-2@@ -52,8 +52,6 @@ static inline void count_compact_events(enum vm_event_item item, long delta)#define block_start_pfn (pfn, order) round_down(pfn, 1UL << (order))#define block_end_pfn (pfn, order) ALIGN((pfn) + 1, 1UL << (order)) -#define pageblock_start_pfn (pfn) block_start_pfn(pfn, pageblock_order) -#define pageblock_end_pfn (pfn) block_end_pfn(pfn, pageblock_order)/* * Page order with-respect-to which proactive compaction mm/memblock.c +1
-1@@ -2000,7 +2000,7 @@ static void __init free_unused_memmap(void)* presume that there are no holes in the memory map inside * a pageblock */ - start =round_down (start, pageblock_nr_pages); + start =pageblock_start_pfn (start);/* * If we had a previous bank, and there is a space mm/page_alloc.c +6
-7@@ -544,7 +544,7 @@ static inline int pfn_to_bitidx(const struct page *page, unsigned long pfn)#ifdef CONFIG_SPARSEMEM pfn &= (PAGES_PER_SECTION -1 );#else - pfn = pfn -round_down (page_zone (page)->zone_start_pfn, pageblock_nr_pages); + pfn = pfn -pageblock_start_pfn (page_zone (page)->zone_start_pfn);#endif /* CONFIG_SPARSEMEM */ return (pfn >> pageblock_order) *NR_PAGEBLOCK_BITS ; }@@ -1857,7 +1857,7 @@ void set_zone_contiguous(struct zone *zone)unsigned long block_start_pfn = zone->zone_start_pfn;unsigned long block_end_pfn; - block_end_pfn =ALIGN (block_start_pfn +1 , pageblock_nr_pages); + block_end_pfn =pageblock_end_pfn (block_start_pfn);for (; block_start_pfn <zone_end_pfn (zone); block_start_pfn = block_end_pfn, block_end_pfn += pageblock_nr_pages) {@@ -2653,8 +2653,8 @@ int move_freepages_block(struct zone *zone, struct page *page, *num_movable =0 ; pfn =page_to_pfn (page); - start_pfn = pfn & ~(pageblock_nr_pages -1 ); - end_pfn = start_pfn + pageblock_nr_pages -1 ; + start_pfn =pageblock_start_pfn (pfn); + end_pfn =pageblock_end_pfn (pfn) -1 ;/* Do not cross zone boundaries */ if (!zone_spans_pfn (zone, start_pfn))@@ -6939,9 +6939,8 @@ static void __init init_unavailable_range(unsigned long spfn,u64 pgcnt =0 ;for (pfn = spfn; pfn < epfn; pfn++) { -if (!pfn_valid (ALIGN_DOWN (pfn, pageblock_nr_pages))) { - pfn =ALIGN_DOWN (pfn, pageblock_nr_pages) - + pageblock_nr_pages -1 ; +if (!pfn_valid (pageblock_start_pfn (pfn))) { + pfn =pageblock_end_pfn (pfn) -1 ;continue ; }__init_single_page (pfn_to_page (pfn), pfn, zone, node);mm/page_isolation.c +0
-0mm/page_isolation.c static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ · line 177
Quoted 7 lines
mm/page_isolation.c +1
-1@@ -172,7 +172,7 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_* to avoid redundant checks. */ check_unmovable_start =max (page_to_pfn (page), start_pfn); - check_unmovable_end =min (ALIGN (page_to_pfn (page) +1 , pageblock_nr_pages), + check_unmovable_end =min (pageblock_end_pfn (page_to_pfn (page)), end_pfn);There are some more cases that might need care as well:
Quoted 8 lines
mm/memblock.c: prev_end = ALIGN(end, pageblock_nr_pages); mm/memblock.c: prev_end = ALIGN(end, pageblock_nr_pages); mm/page_isolation.c: VM_BUG_ON(ALIGN_DOWN(start_pfn, pageblock_nr_pages) != mm/page_isolation.c: ALIGN_DOWN(end_pfn - 1, pageblock_nr_pages)); mm/page_isolation.c: unsigned long isolate_start = ALIGN_DOWN(start_pfn, pageblock_nr_pages); mm/page_isolation.c: unsigned long isolate_end = ALIGN(end_pfn, pageblock_nr_pages); mm/page_isolation.c: unsigned long isolate_start = ALIGN_DOWN(start_pfn, pageblock_nr_pages); mm/page_isolation.c: unsigned long isolate_end = ALIGN(end_pfn, pageblock_nr_pages);
ok, will update.