Currently is_mem_section_removable checks whether each pageblock fromthe given pfn range is of MIGRATE_MOVABLE type or if it is free. If bothare false then the range is considered non removable.

On the other hand, offlining code (more specificallyset_migratetype_isolate) doesn't care whether a page is free and insteadit just checks the migrate type of the page and whether the page's zoneis movable.

This can lead into a situation when we can mark a node as not removablejust because a pageblock is MIGRATE_RESERVE and it is not free.

Let's make a common helper is_page_removable which unifies both testsat one place. Also let's check for MIGRATE_UNMOVABLE rather than allpossible MIGRATEable types.

+#ifdef CONFIG_MEMORY_HOTREMOVE+/*+ * A free page on the buddy free lists (not the per-cpu lists) has PageBuddy+ * set and the size of the free page is given by page_order(). Using this,+ * the function determines if the pageblock contains only free pages.+ * Due to buddy contraints, a free page at least the size of a pageblock will+ * be located at the start of the pageblock+ */+static inline int pageblock_free(struct page *page)+{+ return PageBuddy(page) && page_order(page) >= pageblock_order;+}++/*+ * A free pageblock or the one which is movable or reclaimable is+ * considered to be removable+ */+static inline bool is_page_removable(struct page *page)+{+ return get_pageblock_migratetype(page) != MIGRATE_UNMOVABLE+ || pageblock_free(page);+}+#else+#define is_page_removable(p) 0+#endif+ static inline int populated_zone(struct zone *zone) { return (!!zone->present_pages);diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.cindex a4cfcdc..66195b8 100644--- a/mm/memory_hotplug.c+++ b/mm/memory_hotplug.c@@ -569,17 +569,6 @@ out: EXPORT_SYMBOL_GPL(add_memory);

#ifdef CONFIG_MEMORY_HOTREMOVE-/*- * A free page on the buddy free lists (not the per-cpu lists) has PageBuddy- * set and the size of the free page is given by page_order(). Using this,- * the function determines if the pageblock contains only free pages.- * Due to buddy contraints, a free page at least the size of a pageblock will- * be located at the start of the pageblock- */-static inline int pageblock_free(struct page *page)-{- return PageBuddy(page) && page_order(page) >= pageblock_order;-}

/* Return the start of the next active pageblock after a given page */ static struct page *next_active_pageblock(struct page *page)@@ -608,13 +597,7 @@ int is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)