Skip to content

Commit

Permalink
mm: page_isolation: MIGRATE_CMA isolation functions added
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Marek Szyprowski <[email protected]>
Reviewed-by: KAMEZAWA Hiroyuki <[email protected]>
Tested-by: Rob Clark <[email protected]>
Tested-by: Ohad Ben-Cohen <[email protected]>
Tested-by: Benjamin Gaignard <[email protected]>
Tested-by: Robert Nelson <[email protected]>
Tested-by: Barry Song <[email protected]>
  • Loading branch information
mina86 authored and mszyprow committed May 21, 2012
1 parent 47118af commit 0815f3d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
3 changes: 2 additions & 1 deletion include/linux/gfp.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ static inline bool pm_suspended_storage(void)
#ifdef CONFIG_CMA

/* 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);

/* CMA stuff */
Expand Down
18 changes: 9 additions & 9 deletions include/linux/page-isolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@

/*
* 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.
*
* For isolating all pages in the range finally, the caller have to
* free all pages in the range. test_page_isolated() can be used for
* test it.
*/
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.
* target range is [start_pfn, end_pfn)
*/
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
test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn);
int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn);

/*
* Internal funcs.Changes pageblock's migrate type.
* Please use make_pagetype_isolated()/make_pagetype_movable().
* Internal functions. Changes pageblock's migrate type.
*/
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
2 changes: 1 addition & 1 deletion mm/memory-failure.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ static int get_any_page(struct page *p, unsigned long pfn, int flags)
/* Not a free page */
ret = 1;
}
unset_migratetype_isolate(p);
unset_migratetype_isolate(p, MIGRATE_MOVABLE);
unlock_memory_hotplug();
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions mm/memory_hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ static int __ref offline_pages(unsigned long start_pfn,
nr_pages = end_pfn - start_pfn;

/* 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)
goto out;

Expand Down Expand Up @@ -956,7 +956,7 @@ static int __ref offline_pages(unsigned long start_pfn,
We cannot do rollback at this point. */
offline_isolated_pages(start_pfn, end_pfn);
/* 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 */
zone->present_pages -= offlined_pages;
zone->zone_pgdat->node_present_pages -= offlined_pages;
Expand All @@ -981,7 +981,7 @@ static int __ref offline_pages(unsigned long start_pfn,
start_pfn, end_pfn);
memory_notify(MEM_CANCEL_OFFLINE, &arg);
/* pushback to free area */
undo_isolate_page_range(start_pfn, end_pfn);
undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);

out:
unlock_memory_hotplug();
Expand Down
17 changes: 11 additions & 6 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5582,16 +5582,16 @@ int set_migratetype_isolate(struct page *page)
return ret;
}

void unset_migratetype_isolate(struct page *page)
void unset_migratetype_isolate(struct page *page, unsigned migratetype)
{
struct zone *zone;
unsigned long flags;
zone = page_zone(page);
spin_lock_irqsave(&zone->lock, flags);
if (get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
goto out;
set_pageblock_migratetype(page, MIGRATE_MOVABLE);
move_freepages_block(zone, page, MIGRATE_MOVABLE);
set_pageblock_migratetype(page, migratetype);
move_freepages_block(zone, page, migratetype);
out:
spin_unlock_irqrestore(&zone->lock, flags);
}
Expand Down Expand Up @@ -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
* @start: start 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
* aligned, however it's the caller's responsibility to guarantee that
Expand All @@ -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
* 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));
unsigned long outer_start, outer_end;
Expand Down Expand Up @@ -5712,7 +5717,7 @@ int alloc_contig_range(unsigned long start, unsigned long end)
*/

ret = start_isolate_page_range(pfn_max_align_down(start),
pfn_max_align_up(end));
pfn_max_align_up(end), migratetype);
if (ret)
goto done;

Expand Down Expand Up @@ -5772,7 +5777,7 @@ int alloc_contig_range(unsigned long start, unsigned long end)

done:
undo_isolate_page_range(pfn_max_align_down(start),
pfn_max_align_up(end));
pfn_max_align_up(end), migratetype);
return ret;
}

Expand Down
15 changes: 8 additions & 7 deletions mm/page_isolation.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages)
* to be MIGRATE_ISOLATE.
* @start_pfn: The lower 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
* the range will never be allocated. Any free pages and pages freed in the
Expand All @@ -32,8 +33,8 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages)
* start_pfn/end_pfn must be aligned to pageblock_order.
* Returns 0 on success and -EBUSY if any part of range cannot be isolated.
*/
int
start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
unsigned migratetype)
{
unsigned long pfn;
unsigned long undo_pfn;
Expand All @@ -56,16 +57,16 @@ start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
for (pfn = start_pfn;
pfn < undo_pfn;
pfn += pageblock_nr_pages)
unset_migratetype_isolate(pfn_to_page(pfn));
unset_migratetype_isolate(pfn_to_page(pfn), migratetype);

return -EBUSY;
}

/*
* Make isolated pages available again.
*/
int
undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
int undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
unsigned migratetype)
{
unsigned long pfn;
struct page *page;
Expand All @@ -77,7 +78,7 @@ undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn)
page = __first_valid_page(pfn, pageblock_nr_pages);
if (!page || get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
continue;
unset_migratetype_isolate(page);
unset_migratetype_isolate(page, migratetype);
}
return 0;
}
Expand All @@ -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.
* 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
__test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn)
Expand Down

0 comments on commit 0815f3d

Please sign in to comment.