[PATCH 11/24] HWPOISON: detect free buddy pages explicitly

From: Wu Fengguang
Date: Tue Dec 01 2009 - 23:41:11 EST


Most free pages in the buddy system have no PG_buddy set.
Introduce is_free_buddy_page() for detecting them reliably.

CC: Andi Kleen <andi@xxxxxxxxxxxxxx>
CC: Nick Piggin <npiggin@xxxxxxx>
CC: Mel Gorman <mel@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Wu Fengguang <fengguang.wu@xxxxxxxxx>
---
mm/internal.h | 3 +++
mm/memory-failure.c | 9 +++++++--
mm/page_alloc.c | 21 +++++++++++++++++++++
3 files changed, 31 insertions(+), 2 deletions(-)

--- linux-mm.orig/mm/memory-failure.c 2009-11-30 20:04:51.000000000 +0800
+++ linux-mm/mm/memory-failure.c 2009-11-30 20:06:00.000000000 +0800
@@ -783,8 +783,13 @@ int __memory_failure(unsigned long pfn,
* that may make page_freeze_refs()/page_unfreeze_refs() mismatch.
*/
if (!ref && !get_page_unless_zero(compound_head(p))) {
- action_result(pfn, "free or high order kernel", IGNORED);
- return PageBuddy(compound_head(p)) ? 0 : -EBUSY;
+ if (is_free_buddy_page(p)) {
+ action_result(pfn, "free buddy", DELAYED);
+ return 0;
+ } else {
+ action_result(pfn, "high order kernel", IGNORED);
+ return -EBUSY;
+ }
}

/*
--- linux-mm.orig/mm/internal.h 2009-11-30 11:08:34.000000000 +0800
+++ linux-mm/mm/internal.h 2009-11-30 20:06:01.000000000 +0800
@@ -50,6 +50,9 @@ extern void putback_lru_page(struct page
*/
extern void __free_pages_bootmem(struct page *page, unsigned int order);
extern void prep_compound_page(struct page *page, unsigned long order);
+#ifdef CONFIG_MEMORY_FAILURE
+extern bool is_free_buddy_page(struct page *page);
+#endif


/*
--- linux-mm.orig/mm/page_alloc.c 2009-11-30 11:08:34.000000000 +0800
+++ linux-mm/mm/page_alloc.c 2009-11-30 20:06:01.000000000 +0800
@@ -5085,3 +5085,24 @@ __offline_isolated_pages(unsigned long s
spin_unlock_irqrestore(&zone->lock, flags);
}
#endif
+
+#ifdef CONFIG_MEMORY_FAILURE
+bool is_free_buddy_page(struct page *page)
+{
+ struct zone *zone = page_zone(page);
+ unsigned long pfn = page_to_pfn(page);
+ unsigned long flags;
+ int order;
+
+ spin_lock_irqsave(&zone->lock, flags);
+ for (order = 0; order < MAX_ORDER; order++) {
+ struct page *page_head = page - (pfn & ((1 << order) - 1));
+
+ if (PageBuddy(page_head) && page_order(page_head) >= order)
+ break;
+ }
+ spin_unlock_irqrestore(&zone->lock, flags);
+
+ return order < MAX_ORDER;
+}
+#endif


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/