From patchwork Fri Jul 31 12:21:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 11694847 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CAC48913 for ; Fri, 31 Jul 2020 12:21:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8E9CB22CF6 for ; Fri, 31 Jul 2020 12:21:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uz8VyDn0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E9CB22CF6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5DC238D003B; Fri, 31 Jul 2020 08:21:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 58B508D0038; Fri, 31 Jul 2020 08:21:54 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DCF18D003B; Fri, 31 Jul 2020 08:21:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id 1F1448D0038 for ; Fri, 31 Jul 2020 08:21:54 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9DFCC3626 for ; Fri, 31 Jul 2020 12:21:53 +0000 (UTC) X-FDA: 77098282506.16.act95_00096ba26f83 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 6BB29100E6924 for ; Fri, 31 Jul 2020 12:21:53 +0000 (UTC) X-Spam-Summary: 1,0,0,fb9ec8d268e2d59c,d41d8cd98f00b204,nao.horiguchi@gmail.com,,RULES_HIT:2:41:355:379:541:800:960:965:966:973:988:989:1260:1345:1359:1437:1535:1606:1730:1747:1777:1792:2194:2196:2198:2199:2200:2201:2393:2559:2562:2693:2731:2898:2899:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3872:3874:4119:4321:4385:4390:4395:4421:4605:5007:6119:6261:6653:6742:7576:7875:7903:8603:8660:8957:9036:9413:9707:10004:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12679:12683:12740:12895:13148:13161:13229:13230:14096:14394:21060:21080:21094:21323:21444:21451:21627:21666:21939:21990:22119:30054:30070,0,RBL:209.85.214.193:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yrhthyo1dedr6ck8s34pshobppgopxhyq5tqirpkfrwbhhaxd17193paz49d5.kiur1kgpxse1z86w1f4y48whnfnsu8ycktqufrtop4wmwd8jggs4wrshdyb9fph.s-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:non e,Custom X-HE-Tag: act95_00096ba26f83 X-Filterd-Recvd-Size: 8383 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Fri, 31 Jul 2020 12:21:52 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id r4so6591789pls.2 for ; Fri, 31 Jul 2020 05:21:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AfC68d7kowdj1Po3j2eNcI6eI877xr95Yeb/gsIh8aA=; b=uz8VyDn0DSMwpxqa5V5r0k2Lr0QbardqpcV4k+YfGA/sra0EgnqjLw/7l6kHbD50aD A17TvzMuCG4hzEP2mxy0Jfu+6Os17uoQOKk7emeFZsvKaJgXaNnVjxL75v/lWGphHLr7 RuqUcQe/lsOKDO1xWedNWvZOOkH1jcD8HjAuc1R2umnS/tt+GSQ1KiI4tuQoSpP5xgYr YW7xYgIQm+G8JDArh1e+6I7VXm3xoyRXFIJGF2MGdR7kSbbMV03IsUbmaPa8QZOW5aho 4ppYa6kaG2fphE50CKH1k7szFANRmezKzAMCA+yg18A6urZpWi1j8Phz8kKfavAoDKj5 cWDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AfC68d7kowdj1Po3j2eNcI6eI877xr95Yeb/gsIh8aA=; b=NZKggfH+htnhldc6nyPalO5W+nV/1CnkxaerSj5++uE98lsBiKfHJvxbKfXfYO/+77 uwleBKBGTB2GQn2F2YmeKUmHvNZu0eCrgVKQH/nCPBzIEONcvCFQpz7eTkjZTJ6k/C6V kLmzhQNB3ezhafJzNkABnntB99JXbNm4Tn1aNtXjE+UKWcewgwGi6wu+v8T10Y8WB2uE sWjPFX4wQG4fb9JJlmUwhd8FlCFvp3dDTf51Q6yLyQGlpyzYcQ2uxMPwGxlikAC8dTAH Euxe9jIc6H4a26qFdaCxV8psi26JctGUUGL7GiVio6iJGfPZHFquAIXEuGpmi99eCQfE rlyw== X-Gm-Message-State: AOAM531aWKN8x7mpqjah5dIPLIdfzE4/0sQRGykoGKUgaV3iSVZoI9+o Z1nDM6S5h6Sv79VZVvjcfuF1nLWXqA== X-Google-Smtp-Source: ABdhPJwH/QssPRbVm1gWQ8BpCPSGvx2DbzMcjnLj2G2Ki5xoYTcQ+FNxavxRRSGDwJ4jQigRty9tIw== X-Received: by 2002:a62:c585:: with SMTP id j127mr3201614pfg.295.1596198111940; Fri, 31 Jul 2020 05:21:51 -0700 (PDT) Received: from ip-172-31-41-194.ap-northeast-1.compute.internal (ec2-52-199-21-241.ap-northeast-1.compute.amazonaws.com. [52.199.21.241]) by smtp.gmail.com with ESMTPSA id m19sm3675692pjv.34.2020.07.31.05.21.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 05:21:51 -0700 (PDT) From: nao.horiguchi@gmail.com To: linux-mm@kvack.org Cc: mhocko@kernel.org, akpm@linux-foundation.org, mike.kravetz@oracle.com, osalvador@suse.de, tony.luck@intel.com, david@redhat.com, aneesh.kumar@linux.vnet.ibm.com, zeil@yandex-team.ru, cai@lca.pw, naoya.horiguchi@nec.com, linux-kernel@vger.kernel.org Subject: [PATCH v5 11/16] mm,hwpoison: Rework soft offline for free pages Date: Fri, 31 Jul 2020 12:21:07 +0000 Message-Id: <20200731122112.11263-12-nao.horiguchi@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200731122112.11263-1-nao.horiguchi@gmail.com> References: <20200731122112.11263-1-nao.horiguchi@gmail.com> X-Rspamd-Queue-Id: 6BB29100E6924 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Oscar Salvador 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_handle_poison to set it as poisoned and grab a refcount on it. Signed-off-by: Oscar Salvador Signed-off-by: Naoya Horiguchi --- ChangeLog v4 -> v5: - fix comile error ChangeLog v2 -> v3: - use add_to_free_list() instead of add_to_free_area() - use del_page_from_free_list() instead of del_page_from_free_area() - add fast return - move extern definition to header file as warned by checkpatch.pl --- include/linux/page-flags.h | 1 + mm/memory-failure.c | 18 ++++++---- mm/page_alloc.c | 68 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 6 deletions(-) diff --git v5.8-rc7-mmotm-2020-07-27-18-18/include/linux/page-flags.h v5.8-rc7-mmotm-2020-07-27-18-18_patched/include/linux/page-flags.h index 6be1aa559b1e..9fa5d4e2d69a 100644 --- v5.8-rc7-mmotm-2020-07-27-18-18/include/linux/page-flags.h +++ v5.8-rc7-mmotm-2020-07-27-18-18_patched/include/linux/page-flags.h @@ -423,6 +423,7 @@ PAGEFLAG(HWPoison, hwpoison, PF_ANY) TESTSCFLAG(HWPoison, hwpoison, PF_ANY) #define __PG_HWPOISON (1UL << PG_hwpoison) extern bool set_hwpoison_free_buddy_page(struct page *page); +extern bool take_page_off_buddy(struct page *page); #else PAGEFLAG_FALSE(HWPoison) static inline bool set_hwpoison_free_buddy_page(struct page *page) diff --git v5.8-rc7-mmotm-2020-07-27-18-18/mm/memory-failure.c v5.8-rc7-mmotm-2020-07-27-18-18_patched/mm/memory-failure.c index 803f4b2ac510..8b6a98929b54 100644 --- v5.8-rc7-mmotm-2020-07-27-18-18/mm/memory-failure.c +++ v5.8-rc7-mmotm-2020-07-27-18-18_patched/mm/memory-failure.c @@ -65,6 +65,13 @@ int sysctl_memory_failure_recovery __read_mostly = 1; atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0); +static void page_handle_poison(struct page *page) +{ + SetPageHWPoison(page); + page_ref_inc(page); + num_poisoned_pages_inc(); +} + #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE) u32 hwpoison_filter_enable = 0; @@ -1873,14 +1880,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 v5.8-rc7-mmotm-2020-07-27-18-18/mm/page_alloc.c v5.8-rc7-mmotm-2020-07-27-18-18_patched/mm/page_alloc.c index efe2e94c45f5..aab89f7db4ac 100644 --- v5.8-rc7-mmotm-2020-07-27-18-18/mm/page_alloc.c +++ v5.8-rc7-mmotm-2020-07-27-18-18_patched/mm/page_alloc.c @@ -8776,6 +8776,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, + int migratetype) +{ + unsigned long size = 1 << high; + struct page *current_buddy, *next_page; + + while (high > low) { + 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_list(current_buddy, zone, high, 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); + + 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_list(page_head, zone, buddy_order); + break_down_buddy_pages(zone, page_head, page, 0, + buddy_order, migratetype); + ret = true; + break; + } + if (page_count(page_head) > 0) + 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