Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1141076ybg; Fri, 18 Oct 2019 12:42:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5Xwnj0gBSMpzsrBRjEo7r6dN7NCRI0qgRb5fMLfVX4aPvBovJmrCGqBo+AjKLoXZNUn4Q X-Received: by 2002:a17:906:3946:: with SMTP id g6mr10361278eje.49.1571427724442; Fri, 18 Oct 2019 12:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571427724; cv=none; d=google.com; s=arc-20160816; b=MeT6GRdV8BVPyBQ6gEtnd+UKwWaifFEDxXoxrQBIsvVXX6/oIwPIUk/BL/OpT1kxPm 1+kBXIHGwItr0Vb9FLKWlIndP2ktYwm998b2+rVN+wgmeXOtRYlC4zd7ZtAVZGMC7+yD M8bTysv7+8LpgEiLKejIsvHL/XnyS3zbmctdBHuU/iITe46lnYny9IlRWTGSEz/z9hq1 a6KVQRiPqa3GADy3+AwqVgE92LpJZyUwtcHWEv0rLtEVmxmVbXXFXhTZbfz01qD4BJbt cBleRJd2lfk2bNSlsMsQ3XRIHg0InhTdlizR3IENR3xCbmQufbI8u3aRAdCU7abMMSnA JU2A== 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=Q8hOWVImjaQ+vP0RUEFpYUu2Tk2NDBlHvQQfpK3gBXQ=; b=dk387FOtzhsdqxySB1Gyl0xNHOuPf4/0sgqUWV1LsvxY+YYTi6KyYUzkqI7BvBtP1P TF6ZolRpHglKdUGrA0THNc+sBmt2A4y9E7GGJ1xeaAUDJcCAyoKfbJpbk/uj2HBYxehY 38QzbsNwadatY66wfXWFhL2J8yLXCTJeMoLzrSw7StAMV6GSQ9b+iZXjaHmyuJ9t/Nil FjfVmJxHVcy+n8qkSNpShW9Qa5CH8Hcb2JauqRkKbuYFW1Op6Tpq+G2qsChMln1h2ohX 38tUeOyyrn2o0aLJM8Tz9qTvroB8uUsZ0f7d0o/IWSWI8cRDnFw7hnk81b8SDwh41VOt 8FUQ== 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 j9si4698579edt.32.2019.10.18.12.41.41; Fri, 18 Oct 2019 12:42:04 -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 S2440253AbfJQOWR (ORCPT + 99 others); Thu, 17 Oct 2019 10:22:17 -0400 Received: from mx2.suse.de ([195.135.220.15]:40648 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2440130AbfJQOVh (ORCPT ); Thu, 17 Oct 2019 10:21:37 -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 9B76CB4CC; Thu, 17 Oct 2019 14:21:35 +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 09/16] mm,hwpoison: Unify THP handling for hard and soft offline Date: Thu, 17 Oct 2019 16:21:16 +0200 Message-Id: <20191017142123.24245-10-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 Place the THP's page handling in a helper and use it from both hard and soft-offline machinery, so we get rid of some duplicated code. Signed-off-by: Oscar Salvador --- mm/memory-failure.c | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 836d671fb74f..37b230b8cfe7 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1066,6 +1066,25 @@ static int identify_page_state(unsigned long pfn, struct page *p, return page_action(ps, p, pfn); } +static int try_to_split_thp_page(struct page *page, const char *msg) +{ + lock_page(page); + if (!PageAnon(page) || unlikely(split_huge_page(page))) { + unsigned long pfn = page_to_pfn(page); + + unlock_page(page); + if (!PageAnon(page)) + pr_info("%s: %#lx: non anonymous thp\n", msg, pfn); + else + pr_info("%s: %#lx: thp split failed\n", msg, pfn); + put_page(page); + return -EBUSY; + } + unlock_page(page); + + return 0; +} + static int memory_failure_hugetlb(unsigned long pfn, int flags) { struct page *p = pfn_to_page(pfn); @@ -1288,21 +1307,8 @@ int memory_failure(unsigned long pfn, int flags) } if (PageTransHuge(hpage)) { - lock_page(p); - if (!PageAnon(p) || unlikely(split_huge_page(p))) { - unlock_page(p); - if (!PageAnon(p)) - pr_err("Memory failure: %#lx: non anonymous thp\n", - pfn); - else - pr_err("Memory failure: %#lx: thp split failed\n", - pfn); - if (TestClearPageHWPoison(p)) - num_poisoned_pages_dec(); - put_page(p); + if (try_to_split_thp_page(p, "Memory Failure") < 0) return -EBUSY; - } - unlock_page(p); VM_BUG_ON_PAGE(!page_count(p), p); hpage = compound_head(p); } @@ -1801,19 +1807,9 @@ static int soft_offline_in_use_page(struct page *page) int mt; struct page *hpage = compound_head(page); - if (!PageHuge(page) && PageTransHuge(hpage)) { - lock_page(page); - if (!PageAnon(page) || unlikely(split_huge_page(page))) { - unlock_page(page); - if (!PageAnon(page)) - pr_info("soft offline: %#lx: non anonymous thp\n", page_to_pfn(page)); - else - pr_info("soft offline: %#lx: thp split failed\n", page_to_pfn(page)); - put_page(page); + if (!PageHuge(page) && PageTransHuge(hpage)) + if (try_to_split_thp_page(page, "soft offline") < 0) return -EBUSY; - } - unlock_page(page); - } /* * Setting MIGRATE_ISOLATE here ensures that the page will be linked -- 2.12.3