From patchwork Tue Jun 4 05:47:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xu.xin16@zte.com.cn X-Patchwork-Id: 13684674 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 04D25C25B7E for ; Tue, 4 Jun 2024 05:47:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CD926B0083; Tue, 4 Jun 2024 01:47:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 656706B0085; Tue, 4 Jun 2024 01:47:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F6E16B0088; Tue, 4 Jun 2024 01:47:51 -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 2E74A6B0083 for ; Tue, 4 Jun 2024 01:47:51 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BB28B120CBA for ; Tue, 4 Jun 2024 05:47:50 +0000 (UTC) X-FDA: 82192124700.17.4B40FD9 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by imf12.hostedemail.com (Postfix) with ESMTP id 5B52240011 for ; Tue, 4 Jun 2024 05:47:47 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf12.hostedemail.com: domain of xu.xin16@zte.com.cn designates 63.216.63.35 as permitted sender) smtp.mailfrom=xu.xin16@zte.com.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717480068; 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-type:content-transfer-encoding:in-reply-to: references; bh=U2EBXtbIigci+9bdY/33CLPYAzBTLHKvUNqD9wGPnMg=; b=55Uhj1nrIE9cWP60ZnY6ZYliUAj1a7pEAuoLT9QUf/wEJWKJNLw1kXkYndOFp1t+lMNQMv ppOs5639LIv0OL0idf1YLOwdMnWRr+ieSyHKZIe4jxIcpXIPmOfChcQTqle2ioOGopM0ad 6Xx0e11gvWVsFz264STeH9Aa8wt6cBg= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf12.hostedemail.com: domain of xu.xin16@zte.com.cn designates 63.216.63.35 as permitted sender) smtp.mailfrom=xu.xin16@zte.com.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717480068; a=rsa-sha256; cv=none; b=IwJxe2yubCE9eyleM/tGdVQD6oSt0TM22PBTfk2MWUaC79PJEiSifBYHCWcAQAWCWyynoV /cj+flwWZImTfKFYtJfcQyWDphON5cD1Py2KzSSe5WOovSkZDEHeYO5DxQnXOSAjiJC0Yr 3nSQGEWueQOC1xGLQS8t+/E7gWhwuKI= Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4Vtfkl3JFsz5R9kD; Tue, 4 Jun 2024 13:47:43 +0800 (CST) Received: from xaxapp01.zte.com.cn ([10.88.99.176]) by mse-fl2.zte.com.cn with SMTP id 4545laZs009782; Tue, 4 Jun 2024 13:47:36 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp01[null]) by mapi (Zmail) with MAPI id mid32; Tue, 4 Jun 2024 13:47:38 +0800 (CST) Date: Tue, 4 Jun 2024 13:47:38 +0800 (CST) X-Zmail-TransId: 2af9665eaa7a03e-7c67f X-Mailer: Zmail v1.0 Message-ID: <20240604134738264WKaKYb3q_YTE32hNAy2lz@zte.com.cn> Mime-Version: 1.0 From: To: , Cc: , , , , , , Subject: =?utf-8?q?=5BPATCH_linux-next=5D_mm=3A_huge=5Fmemory=3A_fix_misused?= =?utf-8?q?_mapping=5Flarge=5Ffolio=5Fsupport=28=29=C2=A0for_anon_folios?= X-MAIL: mse-fl2.zte.com.cn 4545laZs009782 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 665EAA7F.000/4Vtfkl3JFsz5R9kD X-Rspamd-Queue-Id: 5B52240011 X-Stat-Signature: nsuwisfcz6g98spaop9micsicr86h7k1 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1717480067-913459 X-HE-Meta: U2FsdGVkX19KDMp3NB39jCRIyWC8fVTu2BpH3YjLjD7wvNBfhvE1zKz3uD69Y73BDrmdQMgrYMfxta2qgG2Za1cmA8p6Xgy2WfVlNxpK9lCck03N1F/fL3lro6gc4pv52ceAjCCEhXPN6RYUsyOhxYUuHl7ubbOgoWVF6a6Fax6zNKtpkhJbHrSmVkI5udwgvs6cBLSZekhaKUrdxxusAPbDE99lY+XLlABk/WwlGy1GyhpgCoNcRlUH6ABJWOW0OUygvQUr8mysH4jjtXu9vbCH7xPPuVPYSa4rFq0LAlWOMygUR3lZv0wCFKZfNgzyKpI44v15CYkfX2Rn2K4IUDUP6bjJIuMMLOfl1iXDjJ2eVR89p2ciWgRlXOzmcaubudj++qLThlbiExRSaVnv0RAy14o3FXjd4LOt3R/syGvU0uTLmcBecxKzzQzxk9d5WRH0y74YcAP2NOyReeg9vOOyNVE64L/+7lkbPaa4fJMAu2zA5AmgOcCc9vq7ZoYwxxpPRmTOvX0QvjdylmU8lHf44MDMBGbCooEVZ6B47GsACX+mfXtWbfDrk77Xz1S+9A9WlPy2gOGcKIHyXe7Boh3QJJMODr9wWQVAqzhZgCEwquc6d64PkNOlbav30NPlWW1kDsmenHvbot3VkTqKVfsR2NFMBbUma32Sks3/A6rwYE4LZGx2fpQ0mWwnIUY9VlyURWxk1QcqCfaU6Kpp7K7XEyzbUDdyeuB947MhKvMPRIXB1eP3kP834mu0zdCpJDWmZM1dVstTGFv9UmCWE6TJ0KAyYRF8UD6yFuSbQ/WNQ8/YMZJ0V8uh+X+zQaAC0qB6JRE/ckgM66yzH50ULrRk8suyPz2eSG18gncG3ikBwPi6SuQcJsepeHjkDfyzTJboudbDUQAkwUcYDD1J9OTQnawFtpWKmZl8ngUgDDehXef/bJnGmY9bm2J+IZ0bxSQT/5u+jSBIqFMTVkt lg/myifT 3hqJmHWSYlGpgKH5L8THZsCCbdXh+LYPalt6QczPXW32qieLkngQGCXrtKBsQWBIccnncxOZAwyEO3T8rW6ujJTsbLmD8lsbrdNLuehlEh7IHkNkgLfuU6yRbhKK1PIi8W4A84M7cLdfvKjknFXauhYZ6aDNx9axDq46aF6wVwg2wA5KBE6ULFTiW881OtIaxKzKJAdsCVledlLBFasROxvOiW0rZhnlsWE3o 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: List-Subscribe: List-Unsubscribe: From: Ran Xiaokai When I did a large folios split test, a WARNING "[ 5059.122759][ T166] Cannot split file folio to non-0 order" was triggered. But my test cases are only for anonmous folios. while mapping_large_folio_support() is only reasonable for page cache folios. In split_huge_page_to_list_to_order(), the folio passed to mapping_large_folio_support() maybe anonmous folio. The folio_test_anon() check is missing. So the split of the anonmous THP is failed. This is also the same for shmem_mapping(). We'd better add a check for both. But the shmem_mapping() in __split_huge_page() is not involved, as for anonmous folios, the end parameter is set to -1, so (head[i].index >= end) is always false. shmem_mapping() is not called. Using /sys/kernel/debug/split_huge_pages to verify this, with this patch, large anon THP is successfully split and the warning is ceased. Signed-off-by: Ran Xiaokai Cc: xu xin Cc: Yang Yang --- mm/huge_memory.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 317de2afd371..4c9c7e5ea20c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3009,31 +3009,33 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, if (new_order >= folio_order(folio)) return -EINVAL; - /* Cannot split anonymous THP to order-1 */ - if (new_order == 1 && folio_test_anon(folio)) { - VM_WARN_ONCE(1, "Cannot split to order-1 folio"); - return -EINVAL; - } - if (new_order) { /* Only swapping a whole PMD-mapped folio is supported */ if (folio_test_swapcache(folio)) return -EINVAL; - /* Split shmem folio to non-zero order not supported */ - if (shmem_mapping(folio->mapping)) { - VM_WARN_ONCE(1, - "Cannot split shmem folio to non-0 order"); - return -EINVAL; - } - /* No split if the file system does not support large folio */ - if (!mapping_large_folio_support(folio->mapping)) { - VM_WARN_ONCE(1, - "Cannot split file folio to non-0 order"); - return -EINVAL; + + if (folio_test_anon(folio)) { + /* Cannot split anonymous THP to order-1 */ + if (new_order == 1) { + VM_WARN_ONCE(1, "Cannot split to order-1 folio"); + return -EINVAL; + } + } else { + /* Split shmem folio to non-zero order not supported */ + if (shmem_mapping(folio->mapping)) { + VM_WARN_ONCE(1, + "Cannot split shmem folio to non-0 order"); + return -EINVAL; + } + /* No split if the file system does not support large folio */ + if (!mapping_large_folio_support(folio->mapping)) { + VM_WARN_ONCE(1, + "Cannot split file folio to non-0 order"); + return -EINVAL; + } } } - is_hzp = is_huge_zero_folio(folio); if (is_hzp) { pr_warn_ratelimited("Called split_huge_page for huge zero page\n");