From patchwork Thu Aug 4 02:51:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 12936059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D3ACC19F29 for ; Thu, 4 Aug 2022 02:52:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B4138E0007; Wed, 3 Aug 2022 22:52:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9632A8E0001; Wed, 3 Aug 2022 22:52:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82A908E0007; Wed, 3 Aug 2022 22:52:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 744A78E0001 for ; Wed, 3 Aug 2022 22:52:23 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 48F59AC076 for ; Thu, 4 Aug 2022 02:52:23 +0000 (UTC) X-FDA: 79760386566.03.7F8B5E0 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf30.hostedemail.com (Postfix) with ESMTP id 064C580021 for ; Thu, 4 Aug 2022 02:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659581542; x=1691117542; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=xmkSAnTZhOOsygVpBmS8ih5UJdM4R+uNZw4DEWDW92M=; b=k6qg/kvo41NG/PVod/WGmXJNENa9eFk9NSkmf4nlpzf13yR63t2jojDm XcMvAAKUDBI6fPUGmy3uKEbGn4SBIJAuiDTZMQbLCAlOljDPShAOZv9ta ywLJFQbIZzT6JNNfZn9N2BtXy3pPseN0gwwwTA5kVKPfb9fi/ablXWcsx YnQGSY5IMWTy6hjqVJpu1AWrh+snB6t1LbEO7L2d73HX5oUQXWxVQQWiX +45msLI+78B3YX9aJlcCY/mrPlDvTk2ZtD3yO1EF1mEf2bfBivr5JA4M/ 8NPvdjkbApZOsnPxnCBvxc5z6p6DgMC/PWFoiwxFV1JLHxi/tKJ96LPoX w==; X-IronPort-AV: E=McAfee;i="6400,9594,10428"; a="269597949" X-IronPort-AV: E=Sophos;i="5.93,214,1654585200"; d="scan'208";a="269597949" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2022 19:52:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,214,1654585200"; d="scan'208";a="606593934" Received: from fyin-dev2.sh.intel.com ([10.239.146.202]) by fmsmga007.fm.intel.com with ESMTP; 03 Aug 2022 19:52:18 -0700 From: Yin Fengwei To: linux-mm@kvack.org, naoya.horiguchi@nec.com, linmiaohe@huawei.com, willy@infradead.org Cc: aaron.lu@intel.com, tony.luck@intel.com, qiuxu.zhuo@intel.com, fengwei.yin@intel.com Subject: [PATCH] mm/memory-failure: release private data before split THP Date: Thu, 4 Aug 2022 10:51:21 +0800 Message-Id: <20220804025121.4001361-1-fengwei.yin@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659581542; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=zy5GgG0DIx9c/Uc9i93o2vmtcY5115ye8r5NgWjvgaQ=; b=fuKg9Oe/wcBd5+XYlk4GPaAhsWTLobsyhN8Kyqw5W5ia1t23tZIkUlg4Z7fxmPZUyQIEhU NOxGCyc3/QrmYDHYrORXGIcelW2mVKdz9CrxJtOgMcpV4KcWu+qXlGmxLLinCqmKIvu0sF A8RD6MOtSZSCTsXcg5oGC6jk1S7kz5Y= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b="k6qg/kvo"; spf=pass (imf30.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659581542; a=rsa-sha256; cv=none; b=lyBgmAK3Atag2/vzgdhDFo49oQy98DUyCG7D/vfLTuCZGZtjgeyPM5H9Y2WRwBtuZTXazR NIQ/0tcsR/rjB7j6K0cbgymnY3bnsWyVQWTFlIQ/lmC5wzJugl9DatloT8I3AHMKN0FNrE VDX5N7bShYd3lxexDFuQGQCu4outt10= Authentication-Results: imf30.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b="k6qg/kvo"; spf=pass (imf30.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 064C580021 X-Stat-Signature: 81f61c4ug13q318uhye5zdr43wct6ss1 X-Rspam-User: X-HE-Tag: 1659581541-242931 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: If there is private data attached to THP, the refcount of THP will be increased and block the THP split. Which could further cause the meomry failure not recovered. Release private data attached to THP before split it to increase the chance of splitting THP successfully. The issue was hit during HW error injection testing with 5.18 kernel + xfs as rootfs, test got killed and system reboot was required to re-run the test. The issue was tracked down to THP split failure caused the memory failure not being handled. The page dump showed: [ 1785.433075] page:0000000025f9530b refcount:18 mapcount:0 mapping:000000008162eea7 index:0xa10 pfn:0x2f0200 [ 1785.443954] head:0000000025f9530b order:4 compound_mapcount:0 compound_pincount:0 [ 1785.452408] memcg:ff4247f2d28e9000 [ 1785.456304] aops:xfs_address_space_operations ino:8555182 dentry name:"baseos-filenames.solvx" [ 1785.466612] flags: 0x1000000000012036(referenced|uptodate|lru|active|private|head|node=0|zone=2) [ 1785.476514] raw: 1000000000012036 ffb9460f8bc07c08 ffb9460f8bc08408 ff4247f22e6299f8 [ 1785.485268] raw: 0000000000000a10 ff4247f194ade900 00000012ffffffff ff4247f2d28e9000 It was like the error was injected to a large folio for xfs with private data attached. With private data released before split THP, the test case could be run successfully many times without reboot system. Co-developed-by: Qiuxu Zhuo Signed-off-by: Qiuxu Zhuo Signed-off-by: Yin Fengwei Suggested-by: Matthew Wilcox Reviewed-by: Aaron Lu Reviewed-by: Miaohe Lin --- Changelog from RFC: - Use new folio API per Mathhew Wilcox's suggestion - Add one line comment before re-get folio of page per Miaohe's comment - Remove RFC tag - Add Co-developed-by of Qiuxu who did a lot of debugging work to locate where the real issue is mm/memory-failure.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) base-commit: f86d1fbbe7858884d6754534a0afbb74fc30bc26 diff --git a/mm/memory-failure.c b/mm/memory-failure.c index b864c2eff641..ef87741b0fea 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1484,16 +1484,24 @@ static int identify_page_state(unsigned long pfn, struct page *p, static int try_to_split_thp_page(struct page *page, const char *msg) { - lock_page(page); + struct folio *folio = page_folio(page); + + folio_lock(folio); + if (folio_test_private(folio)) + filemap_release_folio(folio, GFP_KERNEL); + if (unlikely(split_huge_page(page))) { unsigned long pfn = page_to_pfn(page); - unlock_page(page); + folio_unlock(folio); pr_info("%s: %#lx: thp split failed\n", msg, pfn); - put_page(page); + folio_put(folio); return -EBUSY; } - unlock_page(page); + + /* If split_huge_page success, folio could be different */ + folio = page_folio(page); + folio_unlock(folio); return 0; }