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>
This commit is contained in:
Michal Nazarewicz 2012-04-03 15:06:15 +02:00 committed by Marek Szyprowski
parent 47118af076
commit 0815f3d81d
6 changed files with 34 additions and 27 deletions

View File

@ -394,7 +394,8 @@ static inline bool pm_suspended_storage(void)
#ifdef CONFIG_CMA #ifdef CONFIG_CMA
/* The below functions must be run on a range from a single zone. */ /* The below functions must be run on a range from a single zone. */
extern int alloc_contig_range(unsigned long start, unsigned long end); extern int alloc_contig_range(unsigned long start, unsigned long end,
unsigned migratetype);
extern void free_contig_range(unsigned long pfn, unsigned nr_pages); extern void free_contig_range(unsigned long pfn, unsigned nr_pages);
/* CMA stuff */ /* CMA stuff */

View File

@ -3,7 +3,7 @@
/* /*
* Changes migrate type in [start_pfn, end_pfn) to be MIGRATE_ISOLATE. * Changes migrate type in [start_pfn, end_pfn) to be MIGRATE_ISOLATE.
* If specified range includes migrate types other than MOVABLE, * If specified range includes migrate types other than MOVABLE or CMA,
* this will fail with -EBUSY. * this will fail with -EBUSY.
* *
* For isolating all pages in the range finally, the caller have to * For isolating all pages in the range finally, the caller have to
@ -11,27 +11,27 @@
* test it. * test it.
*/ */
extern int extern int
start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn); start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
unsigned migratetype);
/* /*
* Changes MIGRATE_ISOLATE to MIGRATE_MOVABLE. * Changes MIGRATE_ISOLATE to MIGRATE_MOVABLE.
* target range is [start_pfn, end_pfn) * target range is [start_pfn, end_pfn)
*/ */
extern int extern int
undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn); undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
unsigned migratetype);
/* /*
* test all pages in [start_pfn, end_pfn)are isolated or not. * Test all pages in [start_pfn, end_pfn) are isolated or not.
*/ */
extern int int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn);
test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn);
/* /*
* Internal funcs.Changes pageblock's migrate type. * Internal functions. Changes pageblock's migrate type.
* Please use make_pagetype_isolated()/make_pagetype_movable().
*/ */
extern int set_migratetype_isolate(struct page *page); extern int set_migratetype_isolate(struct page *page);
extern void unset_migratetype_isolate(struct page *page); extern void unset_migratetype_isolate(struct page *page, unsigned migratetype);
#endif #endif

View File

@ -1404,7 +1404,7 @@ static int get_any_page(struct page *p, unsigned long pfn, int flags)
/* Not a free page */ /* Not a free page */
ret = 1; ret = 1;
} }
unset_migratetype_isolate(p); unset_migratetype_isolate(p, MIGRATE_MOVABLE);
unlock_memory_hotplug(); unlock_memory_hotplug();
return ret; return ret;
} }

View File

@ -891,7 +891,7 @@ static int __ref offline_pages(unsigned long start_pfn,
nr_pages = end_pfn - start_pfn; nr_pages = end_pfn - start_pfn;
/* set above range as isolated */ /* set above range as isolated */
ret = start_isolate_page_range(start_pfn, end_pfn); ret = start_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
if (ret) if (ret)
goto out; goto out;
@ -956,7 +956,7 @@ static int __ref offline_pages(unsigned long start_pfn,
We cannot do rollback at this point. */ We cannot do rollback at this point. */
offline_isolated_pages(start_pfn, end_pfn); offline_isolated_pages(start_pfn, end_pfn);
/* reset pagetype flags and makes migrate type to be MOVABLE */ /* reset pagetype flags and makes migrate type to be MOVABLE */
undo_isolate_page_range(start_pfn, end_pfn); undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
/* removal success */ /* removal success */
zone->present_pages -= offlined_pages; zone->present_pages -= offlined_pages;
zone->zone_pgdat->node_present_pages -= offlined_pages; zone->zone_pgdat->node_present_pages -= offlined_pages;
@ -981,7 +981,7 @@ static int __ref offline_pages(unsigned long start_pfn,
start_pfn, end_pfn); start_pfn, end_pfn);
memory_notify(MEM_CANCEL_OFFLINE, &arg); memory_notify(MEM_CANCEL_OFFLINE, &arg);
/* pushback to free area */ /* pushback to free area */
undo_isolate_page_range(start_pfn, end_pfn); undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
out: out:
unlock_memory_hotplug(); unlock_memory_hotplug();

View File

@ -5582,7 +5582,7 @@ int set_migratetype_isolate(struct page *page)
return ret; return ret;
} }
void unset_migratetype_isolate(struct page *page) void unset_migratetype_isolate(struct page *page, unsigned migratetype)
{ {
struct zone *zone; struct zone *zone;
unsigned long flags; unsigned long flags;
@ -5590,8 +5590,8 @@ void unset_migratetype_isolate(struct page *page)
spin_lock_irqsave(&zone->lock, flags); spin_lock_irqsave(&zone->lock, flags);
if (get_pageblock_migratetype(page) != MIGRATE_ISOLATE) if (get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
goto out; goto out;
set_pageblock_migratetype(page, MIGRATE_MOVABLE); set_pageblock_migratetype(page, migratetype);
move_freepages_block(zone, page, MIGRATE_MOVABLE); move_freepages_block(zone, page, migratetype);
out: out:
spin_unlock_irqrestore(&zone->lock, flags); spin_unlock_irqrestore(&zone->lock, flags);
} }
@ -5669,6 +5669,10 @@ static int __alloc_contig_migrate_range(unsigned long start, unsigned long end)
* alloc_contig_range() -- tries to allocate given range of pages * alloc_contig_range() -- tries to allocate given range of pages
* @start: start PFN to allocate * @start: start PFN to allocate
* @end: one-past-the-last PFN to allocate * @end: one-past-the-last PFN to allocate
* @migratetype: migratetype of the underlaying pageblocks (either
* #MIGRATE_MOVABLE or #MIGRATE_CMA). All pageblocks
* in range must have the same migratetype and it must
* be either of the two.
* *
* The PFN range does not have to be pageblock or MAX_ORDER_NR_PAGES * The PFN range does not have to be pageblock or MAX_ORDER_NR_PAGES
* aligned, however it's the caller's responsibility to guarantee that * 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)
* pages which PFN is in [start, end) are allocated for the caller and * pages which PFN is in [start, end) are allocated for the caller and
* need to be freed with free_contig_range(). * need to be freed with free_contig_range().
*/ */
int alloc_contig_range(unsigned long start, unsigned long end) int alloc_contig_range(unsigned long start, unsigned long end,
unsigned migratetype)
{ {
struct zone *zone = page_zone(pfn_to_page(start)); struct zone *zone = page_zone(pfn_to_page(start));
unsigned long outer_start, outer_end; unsigned long outer_start, outer_end;
@ -5712,7 +5717,7 @@ int alloc_contig_range(unsigned long start, unsigned long end)
*/ */
ret = start_isolate_page_range(pfn_max_align_down(start), ret = start_isolate_page_range(pfn_max_align_down(start),
pfn_max_align_up(end)); pfn_max_align_up(end), migratetype);
if (ret) if (ret)
goto done; goto done;
@ -5772,7 +5777,7 @@ int alloc_contig_range(unsigned long start, unsigned long end)
done: done:
undo_isolate_page_range(pfn_max_align_down(start), undo_isolate_page_range(pfn_max_align_down(start),
pfn_max_align_up(end)); pfn_max_align_up(end), migratetype);
return ret; return ret;
} }

View File

@ -24,6 +24,7 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages)
* to be MIGRATE_ISOLATE. * to be MIGRATE_ISOLATE.
* @start_pfn: The lower PFN of the range to be isolated. * @start_pfn: The lower PFN of the range to be isolated.
* @end_pfn: The upper PFN of the range to be isolated. * @end_pfn: The upper PFN of the range to be isolated.
* @migratetype: migrate type to set in error recovery.
* *
* Making page-allocation-type to be MIGRATE_ISOLATE means free pages in * Making page-allocation-type to be MIGRATE_ISOLATE means free pages in
* the range will never be allocated. Any free pages and pages freed in the * 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)
* start_pfn/end_pfn must be aligned to pageblock_order. * start_pfn/end_pfn must be aligned to pageblock_order.
* Returns 0 on success and -EBUSY if any part of range cannot be isolated. * Returns 0 on success and -EBUSY if any part of range cannot be isolated.
*/ */
int int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn) unsigned migratetype)
{ {
unsigned long pfn; unsigned long pfn;
unsigned long undo_pfn; unsigned long undo_pfn;
@ -56,7 +57,7 @@ start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
for (pfn = start_pfn; for (pfn = start_pfn;
pfn < undo_pfn; pfn < undo_pfn;
pfn += pageblock_nr_pages) pfn += pageblock_nr_pages)
unset_migratetype_isolate(pfn_to_page(pfn)); unset_migratetype_isolate(pfn_to_page(pfn), migratetype);
return -EBUSY; return -EBUSY;
} }
@ -64,8 +65,8 @@ start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
/* /*
* Make isolated pages available again. * Make isolated pages available again.
*/ */
int int undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn) unsigned migratetype)
{ {
unsigned long pfn; unsigned long pfn;
struct page *page; struct page *page;
@ -77,7 +78,7 @@ undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
page = __first_valid_page(pfn, pageblock_nr_pages); page = __first_valid_page(pfn, pageblock_nr_pages);
if (!page || get_pageblock_migratetype(page) != MIGRATE_ISOLATE) if (!page || get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
continue; continue;
unset_migratetype_isolate(page); unset_migratetype_isolate(page, migratetype);
} }
return 0; return 0;
} }
@ -86,7 +87,7 @@ undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
* all pages in [start_pfn...end_pfn) must be in the same zone. * all pages in [start_pfn...end_pfn) must be in the same zone.
* zone->lock must be held before call this. * zone->lock must be held before call this.
* *
* Returns 1 if all pages in the range is isolated. * Returns 1 if all pages in the range are isolated.
*/ */
static int static int
__test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn) __test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn)