Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1140285ybg; Fri, 18 Oct 2019 12:41:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzB+3YU0Nopu08zbqtekn2xY3JUc2bjuAbfDKP/gPz1rYOP7+BeerF5Lc8WENa2djFj/mL X-Received: by 2002:a50:b966:: with SMTP id m93mr11445660ede.228.1571427685680; Fri, 18 Oct 2019 12:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571427685; cv=none; d=google.com; s=arc-20160816; b=mgz/JF81pusPJ8xwbQ/TXQLyQDaOfkeuf3/u3LJ1iakSgJBqnaTJtCbL1Q9AnJAeTQ 6qrvqTrZjBmkLSYI+6KONnzwOl5WE24CCcpP2IgRIqQmvD8ZOoBwgKQ03UzU7ejK/G72 fwNit/EP4a3mgfAUkm+T94DYXAqclMlgERPVLI7UF4KcGYpdmYfswdmvTcfW0KVnlbNw sjfKSgs7m2JhXCFIBALfweyOQxe/ziufnjJK88vGtuOLzyoGdq4vkAJM8Ld9Xu48JBhj I75gPUsoMA4djtGTQ2P7EBDdHrVxn2dQnJnHgm9RE1m1uvM7T3a31Jx4879qKnwGRN6G 6xPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=IoablwxAfET8J7sYZxAWdA/G+rKo0nzvNrWy1dtsvhc=; b=a3Wy3pYMby3mAqnnx3dekUjEQ6z4NQh9nig/RcefQhkI437fG1COi3eRFrNmnO2k/5 p3mtV5r0VY1Q38R/YN2pZqobnZ3jF8cgXwePBNgtVAUeIIqXdy+NJM7Pi69FdpXgA6XB mnGzAv3JgYKfQt4kBPsdinL+4wuhy6qAMPJOAo08u2ivpwA8lGPGuzh3wckukhNRalyh yRsPFcZQYXKdpnjl10euc/WHC0tDTaJMo1dU80VHYMxk+7vZGR81new6JBYJce6kQcXu HzxxU07iroEYe/5R4TARm2h/xAPFJyOsSuSCKBxMEMz4uuAE2HYVd9Tyj0R/PyzP7RZv jItw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h26si3804143ejx.177.2019.10.18.12.40.45; Fri, 18 Oct 2019 12:41:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440235AbfJQOWG (ORCPT + 99 others); Thu, 17 Oct 2019 10:22:06 -0400 Received: from mx2.suse.de ([195.135.220.15]:40676 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2440135AbfJQOVi (ORCPT ); Thu, 17 Oct 2019 10:21:38 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 11D7DB4EE; Thu, 17 Oct 2019 14:21:36 +0000 (UTC) From: Oscar Salvador To: n-horiguchi@ah.jp.nec.com Cc: mhocko@kernel.org, mike.kravetz@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [RFC PATCH v2 10/16] mm,hwpoison: Rework soft offline for free pages Date: Thu, 17 Oct 2019 16:21:17 +0200 Message-Id: <20191017142123.24245-11-osalvador@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20191017142123.24245-1-osalvador@suse.de> References: <20191017142123.24245-1-osalvador@suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When trying to soft-offline a free page, we need to first take it off the buddy allocator. Once we know is out of reach, we can safely flag it as poisoned. take_page_off_buddy will be used to take a page meant to be poisoned off the buddy allocator. take_page_off_buddy calls break_down_buddy_pages, which splits a higher-order page in case our page belongs to one. Once the page is under our control, we call page_set_poison to set it as poisoned and grab a refcount on it. Signed-off-by: Oscar Salvador --- mm/memory-failure.c | 20 +++++++++++----- mm/page_alloc.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 6 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 37b230b8cfe7..1d986580522d 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -78,6 +78,15 @@ EXPORT_SYMBOL_GPL(hwpoison_filter_dev_minor); EXPORT_SYMBOL_GPL(hwpoison_filter_flags_mask); EXPORT_SYMBOL_GPL(hwpoison_filter_flags_value); +extern bool take_page_off_buddy(struct page *page); + +static void page_handle_poison(struct page *page) +{ + SetPageHWPoison(page); + page_ref_inc(page); + num_poisoned_pages_inc(); +} + static int hwpoison_filter_dev(struct page *p) { struct address_space *mapping; @@ -1830,14 +1839,13 @@ static int soft_offline_in_use_page(struct page *page) static int soft_offline_free_page(struct page *page) { - int rc = dissolve_free_huge_page(page); + int rc = -EBUSY; - if (!rc) { - if (set_hwpoison_free_buddy_page(page)) - num_poisoned_pages_inc(); - else - rc = -EBUSY; + if (!dissolve_free_huge_page(page) && take_page_off_buddy(page)) { + page_handle_poison(page); + rc = 0; } + return rc; } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index cd1dd0712624..255df0c76a40 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8632,6 +8632,74 @@ bool is_free_buddy_page(struct page *page) #ifdef CONFIG_MEMORY_FAILURE /* + * Break down a higher-order page in sub-pages, and keep our target out of + * buddy allocator. + */ +static void break_down_buddy_pages(struct zone *zone, struct page *page, + struct page *target, int low, int high, + struct free_area *area, int migratetype) +{ + unsigned long size = 1 << high; + struct page *current_buddy, *next_page; + + while (high > low) { + area--; + high--; + size >>= 1; + + if (target >= &page[size]) { + next_page = page + size; + current_buddy = page; + } else { + next_page = page; + current_buddy = page + size; + } + + if (set_page_guard(zone, current_buddy, high, migratetype)) + continue; + + if (current_buddy != target) { + add_to_free_area(current_buddy, area, migratetype); + set_page_order(current_buddy, high); + page = next_page; + } + } +} + +/* + * Take a page that will be marked as poisoned off the buddy allocator. + */ +bool take_page_off_buddy(struct page *page) + { + struct zone *zone = page_zone(page); + unsigned long pfn = page_to_pfn(page); + unsigned long flags; + unsigned int order; + bool ret = false; + + spin_lock_irqsave(&zone->lock, flags); + for (order = 0; order < MAX_ORDER; order++) { + struct page *page_head = page - (pfn & ((1 << order) - 1)); + int buddy_order = page_order(page_head); + struct free_area *area = &(zone->free_area[buddy_order]); + + if (PageBuddy(page_head) && buddy_order >= order) { + unsigned long pfn_head = page_to_pfn(page_head); + int migratetype = get_pfnblock_migratetype(page_head, + pfn_head); + + del_page_from_free_area(page_head, area); + break_down_buddy_pages(zone, page_head, page, 0, + buddy_order, area, migratetype); + ret = true; + break; + } + } + spin_unlock_irqrestore(&zone->lock, flags); + return ret; + } + +/* * Set PG_hwpoison flag if a given page is confirmed to be a free page. This * test is performed under the zone lock to prevent a race against page * allocation. -- 2.12.3