Skip to content

Commit 0815f3d

Browse files
mina86mszyprow
authored andcommitted
mm: page_isolation: MIGRATE_CMA isolation functions added
This commit changes various functions that change pages and pageblocks migrate type between MIGRATE_ISOLATE and MIGRATE_MOVABLE in such a way as to allow to work with MIGRATE_CMA migrate type. Signed-off-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Tested-by: Rob Clark <rob.clark@linaro.org> Tested-by: Ohad Ben-Cohen <ohad@wizery.com> Tested-by: Benjamin Gaignard <benjamin.gaignard@linaro.org> Tested-by: Robert Nelson <robertcnelson@gmail.com> Tested-by: Barry Song <Baohua.Song@csr.com>
1 parent 47118af commit 0815f3d

6 files changed

Lines changed: 34 additions & 27 deletions

File tree

‎include/linux/gfp.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ static inline bool pm_suspended_storage(void)
394394
#ifdef CONFIG_CMA
395395

396396
/* The below functions must be run on a range from a single zone. */
397-
extern int alloc_contig_range(unsigned long start, unsigned long end);
397+
extern int alloc_contig_range(unsigned long start, unsigned long end,
398+
unsigned migratetype);
398399
extern void free_contig_range(unsigned long pfn, unsigned nr_pages);
399400

400401
/* CMA stuff */

‎include/linux/page-isolation.h‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33

44
/*
55
* Changes migrate type in [start_pfn, end_pfn) to be MIGRATE_ISOLATE.
6-
* If specified range includes migrate types other than MOVABLE,
6+
* If specified range includes migrate types other than MOVABLE or CMA,
77
* this will fail with -EBUSY.
88
*
99
* For isolating all pages in the range finally, the caller have to
1010
* free all pages in the range. test_page_isolated() can be used for
1111
* test it.
1212
*/
1313
extern int
14-
start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn);
14+
start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
15+
unsigned migratetype);
1516

1617
/*
1718
* Changes MIGRATE_ISOLATE to MIGRATE_MOVABLE.
1819
* target range is [start_pfn, end_pfn)
1920
*/
2021
extern int
21-
undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn);
22+
undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
23+
unsigned migratetype);
2224

2325
/*
24-
* test all pages in [start_pfn, end_pfn)are isolated or not.
26+
* Test all pages in [start_pfn, end_pfn) are isolated or not.
2527
*/
26-
extern int
27-
test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn);
28+
int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn);
2829

2930
/*
30-
* Internal funcs.Changes pageblock's migrate type.
31-
* Please use make_pagetype_isolated()/make_pagetype_movable().
31+
* Internal functions. Changes pageblock's migrate type.
3232
*/
3333
extern int set_migratetype_isolate(struct page *page);
34-
extern void unset_migratetype_isolate(struct page *page);
34+
extern void unset_migratetype_isolate(struct page *page, unsigned migratetype);
3535

3636

3737
#endif

‎mm/memory-failure.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ static int get_any_page(struct page *p, unsigned long pfn, int flags)
14041404
/* Not a free page */
14051405
ret = 1;
14061406
}
1407-
unset_migratetype_isolate(p);
1407+
unset_migratetype_isolate(p, MIGRATE_MOVABLE);
14081408
unlock_memory_hotplug();
14091409
return ret;
14101410
}

‎mm/memory_hotplug.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ static int __ref offline_pages(unsigned long start_pfn,
891891
nr_pages = end_pfn - start_pfn;
892892

893893
/* set above range as isolated */
894-
ret = start_isolate_page_range(start_pfn, end_pfn);
894+
ret = start_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
895895
if (ret)
896896
goto out;
897897

@@ -956,7 +956,7 @@ static int __ref offline_pages(unsigned long start_pfn,
956956
We cannot do rollback at this point. */
957957
offline_isolated_pages(start_pfn, end_pfn);
958958
/* reset pagetype flags and makes migrate type to be MOVABLE */
959-
undo_isolate_page_range(start_pfn, end_pfn);
959+
undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
960960
/* removal success */
961961
zone->present_pages -= offlined_pages;
962962
zone->zone_pgdat->node_present_pages -= offlined_pages;
@@ -981,7 +981,7 @@ static int __ref offline_pages(unsigned long start_pfn,
981981
start_pfn, end_pfn);
982982
memory_notify(MEM_CANCEL_OFFLINE, &arg);
983983
/* pushback to free area */
984-
undo_isolate_page_range(start_pfn, end_pfn);
984+
undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
985985

986986
out:
987987
unlock_memory_hotplug();

‎mm/page_alloc.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5582,16 +5582,16 @@ int set_migratetype_isolate(struct page *page)
55825582
return ret;
55835583
}
55845584

5585-
void unset_migratetype_isolate(struct page *page)
5585+
void unset_migratetype_isolate(struct page *page, unsigned migratetype)
55865586
{
55875587
struct zone *zone;
55885588
unsigned long flags;
55895589
zone = page_zone(page);
55905590
spin_lock_irqsave(&zone->lock, flags);
55915591
if (get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
55925592
goto out;
5593-
set_pageblock_migratetype(page, MIGRATE_MOVABLE);
5594-
move_freepages_block(zone, page, MIGRATE_MOVABLE);
5593+
set_pageblock_migratetype(page, migratetype);
5594+
move_freepages_block(zone, page, migratetype);
55955595
out:
55965596
spin_unlock_irqrestore(&zone->lock, flags);
55975597
}
@@ -5669,6 +5669,10 @@ static int __alloc_contig_migrate_range(unsigned long start, unsigned long end)
56695669
* alloc_contig_range() -- tries to allocate given range of pages
56705670
* @start: start PFN to allocate
56715671
* @end: one-past-the-last PFN to allocate
5672+
* @migratetype: migratetype of the underlaying pageblocks (either
5673+
* #MIGRATE_MOVABLE or #MIGRATE_CMA). All pageblocks
5674+
* in range must have the same migratetype and it must
5675+
* be either of the two.
56725676
*
56735677
* The PFN range does not have to be pageblock or MAX_ORDER_NR_PAGES
56745678
* aligned, however it's the caller's responsibility to guarantee that
@@ -5681,7 +5685,8 @@ static int __alloc_contig_migrate_range(unsigned long start, unsigned long end)
56815685
* pages which PFN is in [start, end) are allocated for the caller and
56825686
* need to be freed with free_contig_range().
56835687
*/
5684-
int alloc_contig_range(unsigned long start, unsigned long end)
5688+
int alloc_contig_range(unsigned long start, unsigned long end,
5689+
unsigned migratetype)
56855690
{
56865691
struct zone *zone = page_zone(pfn_to_page(start));
56875692
unsigned long outer_start, outer_end;
@@ -5712,7 +5717,7 @@ int alloc_contig_range(unsigned long start, unsigned long end)
57125717
*/
57135718

57145719
ret = start_isolate_page_range(pfn_max_align_down(start),
5715-
pfn_max_align_up(end));
5720+
pfn_max_align_up(end), migratetype);
57165721
if (ret)
57175722
goto done;
57185723

@@ -5772,7 +5777,7 @@ int alloc_contig_range(unsigned long start, unsigned long end)
57725777

57735778
done:
57745779
undo_isolate_page_range(pfn_max_align_down(start),
5775-
pfn_max_align_up(end));
5780+
pfn_max_align_up(end), migratetype);
57765781
return ret;
57775782
}
57785783

‎mm/page_isolation.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages)
2424
* to be MIGRATE_ISOLATE.
2525
* @start_pfn: The lower PFN of the range to be isolated.
2626
* @end_pfn: The upper PFN of the range to be isolated.
27+
* @migratetype: migrate type to set in error recovery.
2728
*
2829
* Making page-allocation-type to be MIGRATE_ISOLATE means free pages in
2930
* the range will never be allocated. Any free pages and pages freed in the
@@ -32,8 +33,8 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages)
3233
* start_pfn/end_pfn must be aligned to pageblock_order.
3334
* Returns 0 on success and -EBUSY if any part of range cannot be isolated.
3435
*/
35-
int
36-
start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
36+
int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
37+
unsigned migratetype)
3738
{
3839
unsigned long pfn;
3940
unsigned long undo_pfn;
@@ -56,16 +57,16 @@ start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
5657
for (pfn = start_pfn;
5758
pfn < undo_pfn;
5859
pfn += pageblock_nr_pages)
59-
unset_migratetype_isolate(pfn_to_page(pfn));
60+
unset_migratetype_isolate(pfn_to_page(pfn), migratetype);
6061

6162
return -EBUSY;
6263
}
6364

6465
/*
6566
* Make isolated pages available again.
6667
*/
67-
int
68-
undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
68+
int undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
69+
unsigned migratetype)
6970
{
7071
unsigned long pfn;
7172
struct page *page;
@@ -77,7 +78,7 @@ undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
7778
page = __first_valid_page(pfn, pageblock_nr_pages);
7879
if (!page || get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
7980
continue;
80-
unset_migratetype_isolate(page);
81+
unset_migratetype_isolate(page, migratetype);
8182
}
8283
return 0;
8384
}
@@ -86,7 +87,7 @@ undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
8687
* all pages in [start_pfn...end_pfn) must be in the same zone.
8788
* zone->lock must be held before call this.
8889
*
89-
* Returns 1 if all pages in the range is isolated.
90+
* Returns 1 if all pages in the range are isolated.
9091
*/
9192
static int
9293
__test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn)

0 commit comments

Comments
 (0)