From patchwork Thu Aug 6 18:49:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 11704095 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 6FC4B1510 for ; Thu, 6 Aug 2020 18:49:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9A3B922CB3 for ; Thu, 6 Aug 2020 18:49:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Pg0nVi4q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A3B922CB3 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 39CD86B000C; Thu, 6 Aug 2020 14:49:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 374A76B000D; Thu, 6 Aug 2020 14:49:50 -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 2641D6B000E; Thu, 6 Aug 2020 14:49:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id 0F75C6B000C for ; Thu, 6 Aug 2020 14:49:50 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C8440181AEF10 for ; Thu, 6 Aug 2020 18:49:49 +0000 (UTC) X-FDA: 77121032898.16.duck16_3a01c8726fb9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 9E73C100E690B for ; Thu, 6 Aug 2020 18:49:49 +0000 (UTC) X-Spam-Summary: 1,0,0,0ad45adc87398c3c,d41d8cd98f00b204,nao.horiguchi@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:2693:2899:3138:3139:3140:3141:3142:3353:3865:3866:3868:3870:3872:3874:4321:5007:6119:6120:6261:6653:6742:7576:7901:7903:8957:9413:10004:11026:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12679:12683:12740:12895:14110:14181:14394:14721:21060:21080:21444:21627:21666:21990:22119:30012:30054,0,RBL:209.85.216.67:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100;04yfdjoj8mh571o8rxquuo1jhizghopjp7aaed7gnpnp3ghmwbn4a1ze9gbge51.164c5bwowsdcyqitcx3d58k9i8qs4nwzibzpzeg353p1z4ghk9buprxcc57kdyd.o-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:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: duck16_3a01c8726fb9 X-Filterd-Recvd-Size: 5832 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Thu, 6 Aug 2020 18:49:49 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id mt12so7322398pjb.4 for ; Thu, 06 Aug 2020 11:49:48 -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=waWNBxGk6iMPpav8Mj47fC2tLAwOLjpd+rtwaTivLoM=; b=Pg0nVi4qfc3JE7BvbZZqMTxAl/O4+2QJe9KQgrXh8iuL9xnFQzxEtbNK9spmDqEEzq lphsXWqzRETj5yg7O6xd7xWKVAnr57l9YK62W14XO8MvAKBiQHluh+D1m4iTCsIxHXsu iLNyVxm4UasjFzZ73MhjOjSajlgz5OI26CobetVi1z0w9tRPRTJeIDBRQmodpQRe3jGx nJp0DvCjcvVlzImdFoY/R7iZYgOrXhv1JXDyuyOqRt8AcytxYY9BwkDr9i4/FVrSfLVS 2Har4jeTBZXvQwrwT3CnoazHJhRVxwPFS4ociGyiHi3Ai9djwPftESUTTPw/6FW6p5OP Xanw== 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=waWNBxGk6iMPpav8Mj47fC2tLAwOLjpd+rtwaTivLoM=; b=THil9L1S+figPR7+fYKu97wX8/p32zCqC1m3XCxyZz+zvQFy0Ws/xuIGh0X3P1qLaF ybMpjbPtr34Em8QDu4WTisn4UFns5uwBRis/Qr6ZyudYJ8pmuQBwZL8iuHRFS3EoJGGG rPNP8h/UfsXhGxkZv0N1LDzU4XZ4EMfoQ/BwgOdsGE9yhNoLbLH2Ii9EYzPfXyQGppOg KUxM2LhaVi0U0mP/xrY/oqMu/dGD2og7ygq311g2XE7Six0NpuH5dBe4C97lNsL+vD9A XFJSzD2jibRqrvgl+jgV8+Go+UtWCIVoo3GPVe6t3E0wCYDpAjtw8lbfpo1ILY95MDzR HWmQ== X-Gm-Message-State: AOAM530cFDKfKPUfup2K84vN1W84GwhleVoVx2L8Ejr5d3FEhG0iY/V+ knUNrynLivOz6f8JEgrj7L8I0OPAmQ== X-Google-Smtp-Source: ABdhPJy23FvrXJY1ir5JHfjRf2aw0PiitzQkRSXbVYYiLuoHqYf7AnXsXuad9Ycm/ZBgfq6fDoibTQ== X-Received: by 2002:a17:90b:1c06:: with SMTP id oc6mr9305658pjb.182.1596739787945; Thu, 06 Aug 2020 11:49:47 -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 u24sm9096730pfm.20.2020.08.06.11.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 11:49:47 -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 v6 06/12] mm,hwpoison: Unify THP handling for hard and soft offline Date: Thu, 6 Aug 2020 18:49:17 +0000 Message-Id: <20200806184923.7007-7-nao.horiguchi@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200806184923.7007-1-nao.horiguchi@gmail.com> References: <20200806184923.7007-1-nao.horiguchi@gmail.com> X-Rspamd-Queue-Id: 9E73C100E690B X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 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 Signed-off-by: Naoya Horiguchi --- mm/memory-failure.c | 48 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 26 deletions(-) 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 6853bf3a253d..276c1588f82a 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 @@ -1103,6 +1103,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); @@ -1325,21 +1344,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); } @@ -1850,19 +1856,9 @@ static int soft_offline_in_use_page(struct page *page, int flags) 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