Commit 0dcc48c1 authored by KAMEZAWA Hiroyuki's avatar KAMEZAWA Hiroyuki Committed by Linus Torvalds

memory hotplug: fix next block calculation in is_removable

next_active_pageblock() is for finding next _used_ freeblock.  It skips
several blocks when it finds there are a chunk of free pages lager than
pageblock.  But it has 2 bugs.

  1. We have no lock. page_order(page) - pageblock_order can be minus.
  2. pageblocks_stride += is wrong. it should skip page_order(p) of pages.
Signed-off-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: <stable@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent bc693045
...@@ -584,19 +584,19 @@ static inline int pageblock_free(struct page *page) ...@@ -584,19 +584,19 @@ static inline int pageblock_free(struct page *page)
/* Return the start of the next active pageblock after a given page */ /* Return the start of the next active pageblock after a given page */
static struct page *next_active_pageblock(struct page *page) static struct page *next_active_pageblock(struct page *page)
{ {
int pageblocks_stride;
/* Ensure the starting page is pageblock-aligned */ /* Ensure the starting page is pageblock-aligned */
BUG_ON(page_to_pfn(page) & (pageblock_nr_pages - 1)); BUG_ON(page_to_pfn(page) & (pageblock_nr_pages - 1));
/* Move forward by at least 1 * pageblock_nr_pages */
pageblocks_stride = 1;
/* If the entire pageblock is free, move to the end of free page */ /* If the entire pageblock is free, move to the end of free page */
if (pageblock_free(page)) if (pageblock_free(page)) {
pageblocks_stride += page_order(page) - pageblock_order; int order;
/* be careful. we don't have locks, page_order can be changed.*/
order = page_order(page);
if ((order < MAX_ORDER) && (order >= pageblock_order))
return page + (1 << order);
}
return page + (pageblocks_stride * pageblock_nr_pages); return page + pageblock_nr_pages;
} }
/* Checks if this range of memory is likely to be hot-removable. */ /* Checks if this range of memory is likely to be hot-removable. */
......
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