From patchwork Wed Aug 10 06:49:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 12940276 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 0FE4BC00140 for ; Wed, 10 Aug 2022 06:50:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 775038E0003; Wed, 10 Aug 2022 02:50:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 724C88E0001; Wed, 10 Aug 2022 02:50:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EBFB8E0003; Wed, 10 Aug 2022 02:50:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 508B68E0001 for ; Wed, 10 Aug 2022 02:50:25 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 244ED1C678F for ; Wed, 10 Aug 2022 06:50:25 +0000 (UTC) X-FDA: 79782759210.27.CC2A76C Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by imf21.hostedemail.com (Postfix) with ESMTP id 95E151C01A6 for ; Wed, 10 Aug 2022 06:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660114223; x=1691650223; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uPzuz9rGdhzJXfybTWaQJmcUDjGiOIZmKVcX6O4Wjrw=; b=FORMrOUmH2zPkQdRAwJMDFuueQ4rE3iwfnK/kPa1vF0DbfS7KLqqR/rl MLWE1kMWd2eis0gcvgXNGLKdkg0rKg5ts0zNeSAwyqEDReQQABVrybILl DJu96vXWdyTekPiJj3bQg7Zc5sSrrJPEQ+GIOwQ+UOZW35NYNewPj2J13 waDm7+h1a40dAzmBOm6Fw1f9COSdt1RzKMG6ZbhggIUZyD4gcnFbFNgwT fPRYETHsVIOXBOy67TT/quBuegZLtCMWmNN5JtlGC/v0ym0gjvNoQgjJa gHZ462b/sIPzLPXJ5ooxw7KFvJ3bj0Ih3CUi1G0wxNTnRtq31zbtBPXDh w==; X-IronPort-AV: E=McAfee;i="6400,9594,10434"; a="355014598" X-IronPort-AV: E=Sophos;i="5.93,226,1654585200"; d="scan'208";a="355014598" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2022 23:50:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,226,1654585200"; d="scan'208";a="932777300" Received: from fyin-dev2.sh.intel.com ([10.239.146.202]) by fmsmga005.fm.intel.com with ESMTP; 09 Aug 2022 23:50:19 -0700 From: Yin Fengwei To: linux-mm@kvack.org, naoya.horiguchi@nec.com, linmiaohe@huawei.com, willy@infradead.org, shy828301@gmail.com Cc: aaron.lu@intel.com, tony.luck@intel.com, qiuxu.zhuo@intel.com Subject: [PATCH v3] mm: release private data before split THP Date: Wed, 10 Aug 2022 14:49:07 +0800 Message-Id: <20220810064907.582899-1-fengwei.yin@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660114224; a=rsa-sha256; cv=none; b=rGVPwz9MXHv6i4gATzAEcIeLPWAnQedfsYbOPxFEJV9VoiAeRGceQ3yqYHPEhDVmM7mr+I 9CXY/7sjOLka77T1UZi10Rtc8lf0x61PPFq6Bjc7b/upeDv5QGhiGpqociSG1XiEUEZnGO PUb9JPNKEZrU+NUd+z0YiF+Fv2UGG6Y= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=FORMrOUm; spf=pass (imf21.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660114224; 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=QnA1BjF64kWQIJdhqWr8x5owAhFU9TJzC+gR6VagU8s=; b=NffbIS7PmWkWz/x6eedlQcypHJlfNlF2wLYRoBMiJYmOcI+YeIyIZGruxIumZcItlibdy+ 6jmamzjGF600BBKnj5k9XuScloBmsQXbwnUoYksHNfaXyxypboxkD0kA/TD1bv2m00sAcR J8eRhfJY2cY+GbflvHOPtqopNbIlmFI= X-Rspamd-Server: rspam06 X-Rspam-User: X-Stat-Signature: 9bohy5dyxggfwpsk8sjg83kejrqtsxx6 X-Rspamd-Queue-Id: 95E151C01A6 Authentication-Results: imf21.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=FORMrOUm; spf=pass (imf21.hostedemail.com: domain of fengwei.yin@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com X-HE-Tag: 1660114223-817013 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. Release private data attached to THP before split it to increase the chance of splitting THP successfully. There was a memory failure issue 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: Yang Shi Reviewed-by: Miaohe Lin Reviewed-by: Aaron Lu --- Changelog from v2: - Use safe gfp flags for different callsite of split_huge_page_to_list per Yang's comment. - Remove reviewed-by tag from Aaron which was only valid for RFC patch but keep it by mistake. Changelog from v1: - Move private release to split_huge_page_to_list to cover wider path per Yang's comment. - Update to commit message. 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/huge_memory.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) base-commit: d4252071b97d2027d246f6a82cbee4d52f618b47 diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 8a7c1b344abe..ae8c4e209e58 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2627,6 +2627,8 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) mapping = NULL; anon_vma_lock_write(anon_vma); } else { + gfp_t gfp; + mapping = head->mapping; /* Truncated ? */ @@ -2635,8 +2637,16 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) goto out; } - xas_split_alloc(&xas, head, compound_order(head), - mapping_gfp_mask(mapping) & GFP_RECLAIM_MASK); + gfp = current_gfp_context(mapping_gfp_mask(mapping) & + GFP_RECLAIM_MASK); + + if (folio_test_private(folio) && + !filemap_release_folio(folio, gfp)) { + ret = -EBUSY; + goto out; + } + + xas_split_alloc(&xas, head, compound_order(head), gfp); if (xas_error(&xas)) { ret = xas_error(&xas); goto out;