Commit 39ddb991 authored by Kefeng Wang's avatar Kefeng Wang Committed by Linus Torvalds

mm, page_alloc: avoid page_to_pfn() in move_freepages()

The start_pfn and end_pfn are already available in move_freepages_block(),
there is no need to go back and forth between page and pfn in
move_freepages and move_freepages_block, and pfn_valid_within() should
validate pfn first before touching the page.

Link: https://lkml.kernel.org/r/20210323131215.934472-1-liushixin2@huawei.comSigned-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
Reviewed-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Michal Hocko <mhocko@suse.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d68d015a
...@@ -2431,19 +2431,21 @@ static inline struct page *__rmqueue_cma_fallback(struct zone *zone, ...@@ -2431,19 +2431,21 @@ static inline struct page *__rmqueue_cma_fallback(struct zone *zone,
* boundary. If alignment is required, use move_freepages_block() * boundary. If alignment is required, use move_freepages_block()
*/ */
static int move_freepages(struct zone *zone, static int move_freepages(struct zone *zone,
struct page *start_page, struct page *end_page, unsigned long start_pfn, unsigned long end_pfn,
int migratetype, int *num_movable) int migratetype, int *num_movable)
{ {
struct page *page; struct page *page;
unsigned long pfn;
unsigned int order; unsigned int order;
int pages_moved = 0; int pages_moved = 0;
for (page = start_page; page <= end_page;) { for (pfn = start_pfn; pfn <= end_pfn;) {
if (!pfn_valid_within(page_to_pfn(page))) { if (!pfn_valid_within(pfn)) {
page++; pfn++;
continue; continue;
} }
page = pfn_to_page(pfn);
if (!PageBuddy(page)) { if (!PageBuddy(page)) {
/* /*
* We assume that pages that could be isolated for * We assume that pages that could be isolated for
...@@ -2453,8 +2455,7 @@ static int move_freepages(struct zone *zone, ...@@ -2453,8 +2455,7 @@ static int move_freepages(struct zone *zone,
if (num_movable && if (num_movable &&
(PageLRU(page) || __PageMovable(page))) (PageLRU(page) || __PageMovable(page)))
(*num_movable)++; (*num_movable)++;
pfn++;
page++;
continue; continue;
} }
...@@ -2464,7 +2465,7 @@ static int move_freepages(struct zone *zone, ...@@ -2464,7 +2465,7 @@ static int move_freepages(struct zone *zone,
order = buddy_order(page); order = buddy_order(page);
move_to_free_list(page, zone, order, migratetype); move_to_free_list(page, zone, order, migratetype);
page += 1 << order; pfn += 1 << order;
pages_moved += 1 << order; pages_moved += 1 << order;
} }
...@@ -2474,25 +2475,22 @@ static int move_freepages(struct zone *zone, ...@@ -2474,25 +2475,22 @@ static int move_freepages(struct zone *zone,
int move_freepages_block(struct zone *zone, struct page *page, int move_freepages_block(struct zone *zone, struct page *page,
int migratetype, int *num_movable) int migratetype, int *num_movable)
{ {
unsigned long start_pfn, end_pfn; unsigned long start_pfn, end_pfn, pfn;
struct page *start_page, *end_page;
if (num_movable) if (num_movable)
*num_movable = 0; *num_movable = 0;
start_pfn = page_to_pfn(page); pfn = page_to_pfn(page);
start_pfn = start_pfn & ~(pageblock_nr_pages-1); start_pfn = pfn & ~(pageblock_nr_pages - 1);
start_page = pfn_to_page(start_pfn);
end_page = start_page + pageblock_nr_pages - 1;
end_pfn = start_pfn + pageblock_nr_pages - 1; end_pfn = start_pfn + pageblock_nr_pages - 1;
/* Do not cross zone boundaries */ /* Do not cross zone boundaries */
if (!zone_spans_pfn(zone, start_pfn)) if (!zone_spans_pfn(zone, start_pfn))
start_page = page; start_pfn = pfn;
if (!zone_spans_pfn(zone, end_pfn)) if (!zone_spans_pfn(zone, end_pfn))
return 0; return 0;
return move_freepages(zone, start_page, end_page, migratetype, return move_freepages(zone, start_pfn, end_pfn, migratetype,
num_movable); num_movable);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment