From patchwork Mon Jan 6 16:55:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13927687 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 BA896E77188 for ; Mon, 6 Jan 2025 16:59:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 407F66B00A3; Mon, 6 Jan 2025 11:59:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 391626B00A4; Mon, 6 Jan 2025 11:59:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BCC96B00A5; Mon, 6 Jan 2025 11:59:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id ED71C6B00A3 for ; Mon, 6 Jan 2025 11:58:59 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id ADA90120128 for ; Mon, 6 Jan 2025 16:58:59 +0000 (UTC) X-FDA: 82977636798.14.5EE48B0 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2062.outbound.protection.outlook.com [40.107.212.62]) by imf27.hostedemail.com (Postfix) with ESMTP id F28474000A for ; Mon, 6 Jan 2025 16:58:56 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=MTeK0kPC; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf27.hostedemail.com: domain of ziy@nvidia.com designates 40.107.212.62 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736182737; a=rsa-sha256; cv=pass; b=dBX9A0JiU/k5iCqp0720aIpF0wJSV07fhrefNoxeJe8ukARvLXSvDdyOPOHnVqcwj1E5la ZULwrDeFXtdgaztZKS4lcNbstMvEFP7xf4eMKcw6NIOuxdGK9rttCWf9pLoUP1CpKX9A9Y bl8ii4CiLp0a3hbG5tUsPnIlqi3XjuE= ARC-Authentication-Results: i=2; imf27.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=MTeK0kPC; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf27.hostedemail.com: domain of ziy@nvidia.com designates 40.107.212.62 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736182737; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1lwTVNAVLwi1gyG41osM9o7VeGen/aJvxEZw1mntkp0=; b=vvkzZMLK9qI6pqcvidCgC48yqxCM52aKIwe440cALO6soU7Ofxsslu323Kb/9Pi+zhgfBs mm+dJXnXT0Zbt8GpGMYaCf6mCYduNa4C41Bjf88RdMrWjp5xFTDas7jJJ744+z/tbBb4Eq kD3Eg5EOqGl9znVIdkHocAhSZPllC8A= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tz7Eggjw7dRfMpnqqaJETgCRkmW/Lz71+CYsjNXSTCeYDpe2fBOa13bp1+tPD+8PaWCh5OJ11+Xj0F6HW908Bz3GB3tTHryd/1fu4FnRjdxNhoCNbslFQcx3WOwwESW3chf3gv6fnigF4iwel5c5IdTCsvVGHp2DiaanI/OCCAms0QgU4DxR6jQRoG6C0hXtRtGCzfnBbcYtiejmH/sfzrqiOcprccOT+kYCuMmRpfbWoSNhTguzHqeotEiolnEDP4Xy4tt4OXXjdHO7qHthwxDLFa66G/F1y8BTYskkBq28fbC4Hj8n/YJuKasZrTcoAQkGhPUUZ1g5yCCcWTW2Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1lwTVNAVLwi1gyG41osM9o7VeGen/aJvxEZw1mntkp0=; b=wyzG6EebpiBrG0/FhrtU5lKkGiyvigHGX88VM4B2L9we0/p3g74RK2UWud6RdwGaeQGBGqhebAoUuL+46zWOA4Y/9rwix/+IKirMFq/Pydz8l31/obRCkob+CHI5JeUeRiyniMcTUWDNjJetPwPrBOXUK9H+PcgBEEBETnZc8KmZhKPVLEZBKPuZlI+jUWb51E31I0qBsZKUAQv7QkIgR1N275YMFXgtVnbZiICRYw6peMNbRroOsZJ3aAkfcacPL4lGSSXnuxEOy3y7BtCvFA/ahTrNPbbouXptZbgfr7RePzo15qR3PweEeDDeqysrmRnxDyOGrapRzhqVGo2kgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1lwTVNAVLwi1gyG41osM9o7VeGen/aJvxEZw1mntkp0=; b=MTeK0kPCI4zh3PnL/Xsm1YdaDoC0oRusbM9NSoeGuDdsejxgziKBkllXr0ZRufVrcRjc7dQkKoPDxyb0/SRBMSXeD0kUJYpRsRGJ6XlYkpuB+taddnrgVF+hOzsdO4DWDvcBhar4TCwNM+0oIUAD5N0NAMPnfJAWPvJcCtJWUaJd3OvgfmUIWOkIgIF0rdT/3e07svby+aSQLIb/BwH46sGfZXZIJVJxo4JbUlhBp+MJmvMYd96NHo/lJAcEUuEgKJIy7pVcE1GWLLLE+pALhxmtK8T8SYYUmsZWbAR+gbug9drWRaa+JiElkW/OJP2Wza/WoO4TNGasHwYoz7oW8g== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by PH7PR12MB6634.namprd12.prod.outlook.com (2603:10b6:510:211::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Mon, 6 Jan 2025 16:55:22 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8314.018; Mon, 6 Jan 2025 16:55:22 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v4 01/10] selftests/mm: use selftests framework to print test result. Date: Mon, 6 Jan 2025 11:55:04 -0500 Message-ID: <20250106165513.104899-2-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106165513.104899-1-ziy@nvidia.com> References: <20250106165513.104899-1-ziy@nvidia.com> X-ClientProxiedBy: BL1PR13CA0245.namprd13.prod.outlook.com (2603:10b6:208:2ba::10) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|PH7PR12MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: 74115550-ac52-4f1c-ba26-08dd2e72e8da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: Wp+Kwxwvi5ktsVdC+N15VHEsUhLxyGIrPYK2hN44mO8t3BmEsBvn3PZL3tNE/0ysIPNzHFQMIne9ezX8nGDWT+C9nDkzOraUtEUwENqAJnN/DejYCZhP8xUVw0C494K+Uc08x43RCB2sx/mwf7Ol5YIbdGYvloShAQfarcCbkRATFBJJ6VcrkjXmjHK7ursF+yIeiJLvOh/UXk5DdglUp/nN28LzaYoez0jucTFxsjoiGn0EzOdoQGj8bKVFV94sEJnRYEVgN70FyZapQxdw5ncFcy/6pHMDGhyRxA+VKCCjAqYlR3DPZln+vOYG+AJVE2wiK1uE6BkS4cmsmPwqFJVQDyqA3Leic99p8PSUmwnNHYYjxlb832EB/9TOu29acnGYqaFw0yLlgusxoHvdwXAET1nDySQGX5tjMw7NLAV+g+69rg8toH6amqYT9pkA2HmkOpgN9jZ/XRupdrwpgn3Lv3e+aOzvIG+hMktTBQDSgKX9mEaF3TK4f4q+EJEGKi0++i/2Ey8iOlG2GMBeq1E1YtlbkAR93PB8uN740Jpg33q33H6VRxXyOnZI9Hsrjp3ys+/2HbfSn848YM+hqntJpGV8s9iVlMK9CQzfPW7Q49OqSlCpXcDRNE3Rwt/3aCRqzhQ264urEtAIkHA98V16GXhUUBb4Ym8NV720m5G3oWFjqvDly90k/gJAtK538kfzBrKcAK3BUG/HGM2t+Se4i00l3ULTn2AgBcLynD/8WJXoWHMPqmqIFy+6h7+FGIxNGoisjfXP1DdnQT0AcZe39CfxDTZjyMNzHQ61pRbcSFRASad1wS3txFMqONz5Nt17ubNtnPK86o2/rwHf+vFMro4eVbl9wVYFDszs9htMQrvGswB7JZ+Z1OlDxE/vq9gTtha+JPU+2x28IoU9tFvch+s98XG/1jATZeDye43KgyN3JrXn6gDf3GSNTZEXpHVTQYxGjLOfKqT2efbxZ+ZCZwNJMjurd+9W9gYx8k+RN6pFb9v2Jaw4gBZS0lRdTzcZKH1SLoy0zMZhGqO5nEaoQr7BMNWL5usFKfagU3i4kKBU3/H5gMOboGqLcnxTezJDKSxUYTBMmLeUn4RyHwm+494A1cgnKAIWA6pKdrjA72H3FVj80vOXYSIsMeSXSIjXwuCRuA6WomM1957zFkB3GrZ4DAEhIYpG3QkkV89VEZiXEF4Ncty73ss80tfeEUCoofH3vwuCovUJhPIbXfgvhxcEYOwmSwuRTRAq1gpqm5/rGrMH35dW/OvoMFSbvNxq5sTan3QsGx80Ma430mOJCLhUdsms/jqu6G/uhw6vZkCVivxiczcWrVpNGAl/4874ykJ3rFrJqZhUsIIN0OzvQDzGUJjQewVuOlQAqecm22CguzZO+8+6zPpemwTW X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r9vkFeThXIgGsobZmaCYqNehpq7V+iFcMibCWNtCciDQdX0ufuTp2uvVpOj6apJ8YXMb6Vy1vr62uu6+4cVFNUa4ZwVL0Jwm6VuMDrc+9fe7BDSBL3kZtNE2gBLRNM85/1/tKh0LCH3KuvQGDSwPgq3vBKsygSIQI+SOTQyyLNbNYfR/1hk/XOMuHpepi1nNotjC+QZtVtTmB+BXO2UNqcyOXmsNsoyp6RUto6hVD/v9HN9BFBFWleA2duYGZ9rddJdBnfZbScPCzQVrao/fuw3axZowpyNfBRBnTY7firKNvfvX9vtdadjvGtl1IAmvzXWg2fk2FyM6X9zfU5p6zdTrnmSP0l5T8iA3HZuBjUqH0sBcAo/GuiK71qrEF/w/ObbP9vzIJ/1AtY/GkAQCeI7WxQvg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CKDdhi8JHwlu1kR7JNn/I5yk7tzuPpzIlYxjHnxXSQLSusPsfnks+pDKfTWvGaCxpXGQNFZwI4vG9FMSUygg3xKUrrm31pqOO+mA7X5 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74115550-ac52-4f1c-ba26-08dd2e72e8da X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 16:55:22.5370 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qI61iye5HFqaF/pdkAwbRr3pTceMSg8AwKt5vegSPXcxaJnHgsayw7ykPbC9KVKJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6634 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F28474000A X-Stat-Signature: bp576yqt7kojfu6q88833zazra8hq7jt X-Rspam-User: X-HE-Tag: 1736182736-152751 X-HE-Meta: U2FsdGVkX18CJoQqkAqaOG0Mi/hgTQSWpbGWdEYGnM40AzvGHaupiFeF7Y3k7oZ1ktjqTbosD2GzqSPRhMj1rE6zThq00QziOXMbsXVwIRQLzPCfLy60eq9NAHQpziNF+GWba+e0fLaRvbwvTFcz2a2mX0b2XIomeYr+PqR8Ix2gxfp7oEguQFYK845yUkdXcKZQV/uWjOF5U4OgV9zdO6I47PHsM7SuJmBYySe1VehXG9xKOOledy+esPH+lRx7a6D9I/Dueziv9+pb+FONFwsIOHavs6nek8I8JUSiHlwCyWK1PilbCdY6jQGw1T53dTdliXO96kEugGF/JD09Q2WQTOG9Yj1BshiiMUEgZuVLvEdtmOPH1LKw273Dc26a4FwYtMOK2I4SaakaBf7DqTGKtAZSo/GBIag4Tat4HLb/nTU1ifcFHHApMMzf+fLl9AmNL23Wb8sZUHGDeeWVQ6ugRYDD+N5w9P7bBSk901hsVahFefbRruhR90wIucXpaIdlIhnNeP1nW41stIOSEwXnIdG0Od7xZcKDGXDVVA2PaWqqr5L9EcFrvoFUiT3GB+IilS0UMsRiEDGoWtgitNAGr46GCIJ/esHrlXQQxCuwr/r3Vb46Q27cPzXxUe785v1NYVKsOXaQ7pSE/bZsbTnUlOY3jAYaCVeQdHiheUsYQGdyTbSPqLJQzG+/82Jq0idaoO8z7fxFOxx9TkcA9iT4TzvwiGZ6QA77nD2Ry+fQeqGim1W19MwuGITCoQE99v6Fhipgt8mCun8K58sFQ1xvYh917gqsoe78bI476GrB8XMCk7WRW7FR2bGhYxFoiv+UFPn9eh+83nADeDljmqfLqIknzH6MdAeDz6daPTFWbnMkZnIqJ9z/fAtaAoBH4wIIp3xkIAhzpYqfmkApAhwpEPTqIVnnW5sS6mrTUbRkmrHuHXOVGDe9JfsKXJPpVPjLieIBi/PJUDP4hpm Y7Dt5tAC 4PVx4cA0h2zfNXC/Y9N8/nCX2VY9rezOU2DXLGJ7ys4vU/X+BstVL8gFMCveBKitlMWYr2/rVuisB2/QLsrBlds0ptncsqxWyaVmYuqhsFu9/qwS7+hF+iN5J9dRZ8iaY2A36j0ebNhjLt2ggOiXh3L/zCAxISq84GJuRp+OJYDVquFMg9x78tg8rZtkFZpxqSUwhd27KcBmUfzWUm1EU41K5e2RF/C7HGiFLC+oUQBiY+VtIv6eZSoh0ZOti1ei6bF6oB8OPiN90YhKuFKU96flW1m3iFdw5EbeDvntURgulqzRHNSWkQfmIi0/sGt4nEyrlnmQfFO/WHtRyHMiW5K/wJA== 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: Otherwise the number of tests does not match the reality. Fixes: 391e86971161 ("mm: selftest to verify zero-filled pages are mapped to zeropage") Signed-off-by: Zi Yan --- .../selftests/mm/split_huge_page_test.c | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index eb6d1b9fc362..cd74ea9b1295 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -108,38 +108,28 @@ static void verify_rss_anon_split_huge_page_all_zeroes(char *one_page, int nr_hp unsigned long rss_anon_before, rss_anon_after; size_t i; - if (!check_huge_anon(one_page, 4, pmd_pagesize)) { - printf("No THP is allocated\n"); - exit(EXIT_FAILURE); - } + if (!check_huge_anon(one_page, 4, pmd_pagesize)) + ksft_exit_fail_msg("No THP is allocated\n"); rss_anon_before = rss_anon(); - if (!rss_anon_before) { - printf("No RssAnon is allocated before split\n"); - exit(EXIT_FAILURE); - } + if (!rss_anon_before) + ksft_exit_fail_msg("No RssAnon is allocated before split\n"); /* split all THPs */ write_debugfs(PID_FMT, getpid(), (uint64_t)one_page, (uint64_t)one_page + len, 0); for (i = 0; i < len; i++) - if (one_page[i] != (char)0) { - printf("%ld byte corrupted\n", i); - exit(EXIT_FAILURE); - } + if (one_page[i] != (char)0) + ksft_exit_fail_msg("%ld byte corrupted\n", i); - if (!check_huge_anon(one_page, 0, pmd_pagesize)) { - printf("Still AnonHugePages not split\n"); - exit(EXIT_FAILURE); - } + if (!check_huge_anon(one_page, 0, pmd_pagesize)) + ksft_exit_fail_msg("Still AnonHugePages not split\n"); rss_anon_after = rss_anon(); - if (rss_anon_after >= rss_anon_before) { - printf("Incorrect RssAnon value. Before: %ld After: %ld\n", + if (rss_anon_after >= rss_anon_before) + ksft_exit_fail_msg("Incorrect RssAnon value. Before: %ld After: %ld\n", rss_anon_before, rss_anon_after); - exit(EXIT_FAILURE); - } } void split_pmd_zero_pages(void) @@ -150,7 +140,7 @@ void split_pmd_zero_pages(void) one_page = allocate_zero_filled_hugepage(len); verify_rss_anon_split_huge_page_all_zeroes(one_page, nr_hpages, len); - printf("Split zero filled huge pages successful\n"); + ksft_test_result_pass("Split zero filled huge pages successful\n"); free(one_page); } @@ -491,7 +481,7 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path = argv[1]; - ksft_set_plan(3+9); + ksft_set_plan(4+9); pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; From patchwork Mon Jan 6 16:55:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13927679 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 D9FBBE77198 for ; Mon, 6 Jan 2025 16:55:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 761256B0093; Mon, 6 Jan 2025 11:55:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 711F76B0095; Mon, 6 Jan 2025 11:55:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 58A926B0096; Mon, 6 Jan 2025 11:55:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3B7E56B0093 for ; Mon, 6 Jan 2025 11:55:43 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B7AF5120113 for ; Mon, 6 Jan 2025 16:55:42 +0000 (UTC) X-FDA: 82977628524.12.2C1336F Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2072.outbound.protection.outlook.com [40.107.96.72]) by imf30.hostedemail.com (Postfix) with ESMTP id E21BA80012 for ; Mon, 6 Jan 2025 16:55:39 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=EE1OJfhv; spf=pass (imf30.hostedemail.com: domain of ziy@nvidia.com designates 40.107.96.72 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736182540; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FZxMul1WU308N00KYNlcxD/DyDEr6jnTyKBgAiwblKE=; b=b5/appGHuqAT3+rXLlUTPRJz17yfm+w+3XZmJ3dJiSQiNf+rv5ej4v5whYt9FEULwQ1jy4 mc697diorqKHGRgxXS7fCF/Djgm9Sbc6nwYCwFExokDw1b0y7400a9hhs8giPDUBya6dLT P1VTxTWNZkDj0mmNqeAj/aiUh1cpitM= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=EE1OJfhv; spf=pass (imf30.hostedemail.com: domain of ziy@nvidia.com designates 40.107.96.72 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736182540; a=rsa-sha256; cv=pass; b=hMhJ+sUBQ2C0HchIBKNhv9MGADZSaqjiUN9sf7Hg1J6DwBJSbiMACWqYAy/YMl5j2kC5eM k9m2qbN1KZrcwswfxV6ohXQ9jY7Cu1Eyt8pcUx7xn74DkAwlAUhldWHVcMWwy3D6IFAkxg QapDBAii6hbF951zcM0C+OUtbUNRuto= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jqqpFa35uAG73RjnaimIVDWA0YaYPPenHTF3MA4256LbuJyN/OPDaJ5OLVnAYG9abR25LfWaeT4/gNsdGrfnpuyl+vUnf28Ryb8Ykkp1m+hpdrFtJtuSpufvpOs1/htilZ1fuC+FH53idITWT3w5fqMxKk/1deVYA73+oNuFfjSm8jmMZDHkfVetn1erkJk4CuryPnqGrGG/hp1HsgOBWTHduuszCuPF1ZOxrXs3P/YifM7MX2xpoJH8zhRwnCw/2pE74Pd1OdcHBIOu2No+E60xH2Dwyst+s/pA836pEpW5jhpZ7ntYNuSQXdAZ1PX5+HzgHXp5sljf2FO4LJFpHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FZxMul1WU308N00KYNlcxD/DyDEr6jnTyKBgAiwblKE=; b=jn3p4J9cvygqElegLuBZq4x7wqZCVdguT+uOoHuKmv/Vt/uvd/xTJkArYqtfaemPC/ZJXagRSYtnC7yGNXNKYJcDHW8GqBioWmsblZIKpnm2Em9pDuvhIVHjH0JIkvZ+6YCTFj4002XrUaHSAcP4GQ0wF/e8m0EtfPThI/ZhIyndrWur/eMelQMbqPtgfinS0Shed5h2S94yrThcJ2gx4uXXlLt3xVqhmqE3nBfPeeJkbZ+jgUcM73aWSXBOkziVMR+dvH4LSuQOPdLZZp0yi0/x472+lKV3H9uzp3aYwHpOoFJZaEOXqbFUXamv2E4RXrDJhZMX2v7ampEra4XDjg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FZxMul1WU308N00KYNlcxD/DyDEr6jnTyKBgAiwblKE=; b=EE1OJfhv5J5i8GroyuK3Ysf5jMGpXKgJpv0ocsvphrI3TEuz0UR7TtzuCDEHqtt/vwJNY5UkXIOxfYkDRZcOdQCt1sw96OufHa9LsvI5U/WZrRuuDpnogsR0wjWT3xxX1k7odHeYzH7QMWhTJ7vW6lPLPCVtNrEIFTf8K9EZU1WTaSNi5SwCA3ltRBGyvtN7m6/JBf7exM7vaoivtBLF+hD3JXcP3mguQ4u5EQxu/sR7UDUn9T1iuxgK2ZAN4JbkvG6d4GzSHkZqmnEFRYuV2SGB4GsdiONdwEfHurj9ciRpUNO5cL5X1S5nTWom2h5YNeelch+w4Jra2VhCLGPZFg== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by PH7PR12MB6634.namprd12.prod.outlook.com (2603:10b6:510:211::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Mon, 6 Jan 2025 16:55:23 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8314.018; Mon, 6 Jan 2025 16:55:23 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v4 02/10] selftests/mm: add tests for splitting pmd THPs to all lower orders. Date: Mon, 6 Jan 2025 11:55:05 -0500 Message-ID: <20250106165513.104899-3-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106165513.104899-1-ziy@nvidia.com> References: <20250106165513.104899-1-ziy@nvidia.com> X-ClientProxiedBy: BL1PR13CA0246.namprd13.prod.outlook.com (2603:10b6:208:2ba::11) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|PH7PR12MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: 12822cae-2e90-4d49-3eeb-08dd2e72e981 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: 14b/Zj9e+F+Mj9pOcGKtvNVbFmzYrSnrMGfMbh+5IKHzu+r4HosZfGqPzLHI+L1mkpABl6drxGn0mbqgCSFrKvMDL99zYAg29Sq1CaFK7Tg+g1du5rvrtPe2ccunXMXzM1z5BGKDyUyBCk6e1lru+WeOw4I0VjaVHqVenAoHfL0gHB+fieCqKW7Xr7cSV7LkU9FekKGMG6AE2I/vCCf9iJd+a/GlDh9R5EQROMmA+MbPylxnAj/kZh8RQ5EdUREeIGVjL4iThE/+ffhakulMDHv57lq7Mo5HzkS+PKuAwLcyqwQcqb1S5bOHdRYvoxAyyi+21T9RN/jwrx5kmR7A/FrM0/uqUqlXzrNhbXyDtoHZrCRvEktaZpEI5XWifDtTvxbtJ78+18932k6EX2t7kpaY2q5eyRgzkwieK673YymLQYb5a91H9N8fZBTXZ8R1FCpjhdo9G36BUPHgBEaPUzpXl4VRW+nPFV3SG83cFxlm61DOfQZF9RO9Pn9xj41DWiAOWZeLjkTKSfSZy2UOzcS1qx29TObaEprh32AReFokENaubnvdYf7nKnB16kA9Uw5IOxcEcj4wMz5lFHkPEqIBVAz/lFYQL90rCuufnB4JfYvw6SuYLb9YZE7wLLWXgs77U42DFtn9DZeUzX7tKhbOJ2i57jEKkZbdmiXCd76gE3zktPJQKkSEyo1FjcRj+hzQBxXskjq3c47DxBustgmyTDQWMKcCpKAbpsMT7R+09KiQJDngEXhYE3vs/+KjHBhi2RDGAkQj3/V7Gld5bxa1YvzobjLH3/omJcMJQGhxEvB7DEPT6qvynC9rFN5rH2DQ1mSugu3wqEY5MYr21ACDcj/A/BXRExeZiG6+j5foHJ49bAXHkkR2vgJ7GRMgbbDAEzmxOyEHj8RIbfwCMSlD7uI2HM8LMaYjEwm6ezQiPa/Yhtpvi9oTFQkH+TrBge3CvZeB9+PvxeH+g/WpMoqPdCWECD95IoWGbGjP4kpZRqvkIdFSW+d9IdazAvcktPyyedqFUi+a4e2mDbDfojUEsHXrHIwcAAHvKyYFTGWmFBaqKRLPiylZw3G0pk1fXw2IVMaEin9diQrBHreL4rUwbNflKT/+C4mv/r7i+t+f7yWov72RcHFCD0HBpidzx+7ieXBWP5E8e4WbqfCcnihryIdhzsAZJM7VM01sbFwiPOCknajDzQ6gT+aIZ2ud3klorkxhbG2DtF5hGV7CxahI3M3qq1m533YfUP9JOXwtWEwvt7u4WHSISi0y2PzK01PtuvAoAFPavs/L+NKwjuuzqGOOyaJYMhmEbWL2d4lUqUPdrlOtPGwFgm6wKbX8ELElkY0qjBgjenKfMc80VuY8wacHbD7JFUtHMYljzegPZxg3Qcu11hZytANz7W9E X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gm0tyrqw3wwWGc0qVuU6T2590/NtoEZmBMiYusMQJaaM4OG9oWs3oh9qtrUoppzx5qF9noDKc9YKQDpSaS61DJlqGfdXmXheN/imbxWJQObRWTeH24r4v8eFV1ogGK2zUAcdV3WaluiOE1bWDYIcGTU59/hQElihCBWck77pLGVak2L0/0uyyM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/bGxb8stE7+6OFnwNjFAC6RjUAKsf+IaGU6HtWbjhHkGQJL4SQIVfrLFmk/8A/QG2uuUfYsIv4yDYARKZTz6SteEwwsyNDdC6mGntcU07TyAcefdt55uplPozTMcf3Y7qolzoc/x9FtDyw/KDaJo84A4c1TPmX5QsCbTRI9C/FeEgTcWmbmbA9uOuSWxxP8GzbavM9z+voTCWe+cVX5/sgV6i/I12Z/2k2tT7YwLK+A7UTGE0g2Cv6gXX5UFcN5/12GOzwWCVboSzTt0A2Lcz+pmA9XNkjUbjJYEmC3usuNehFl2IZBeCEapzifMYvTQ08ZrTWbBp/V0S2DjuqGe4 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12822cae-2e90-4d49-3eeb-08dd2e72e981 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 16:55:23.6386 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XPk7K/KNWsWDG3/gJ0c4D8b5jjreNZAn3JIz3YQebpavZ99qptVFy7AAuvEfahXi X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6634 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E21BA80012 X-Rspam-User: X-Stat-Signature: apga1bg7kqd7oazrfejbnune1uw9hhhb X-HE-Tag: 1736182539-362347 X-HE-Meta: U2FsdGVkX1+B4msjy/U+2U33xj/X926HOmlb+v44x/zy/xyLDr5DEnYinepY2ltSIRreZ3L0hcgUiYir+R/dNcREryKPiMUMcDv0IkOflEtsOuzQKFDOoGYS351Ma7OzWQY5fnq+y2yGXmmmJxAaQe52sVpWq1ATw082CUl+WSldSIK57e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bbiu6r7OfZYdRhkPhma+EGP/qDkU1Af++PnCxu7oDeMcjHTnWXTqdntCZkEO7l4aHJDXHWAEuQg== 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: Kernel already supports splitting a folio to any lower order. Test it. Signed-off-by: Zi Yan --- tools/testing/selftests/mm/split_huge_page_test.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index cd74ea9b1295..5bb159ebc83d 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -144,7 +144,7 @@ void split_pmd_zero_pages(void) free(one_page); } -void split_pmd_thp(void) +void split_pmd_thp_to_order(int order) { char *one_page; size_t len = 4 * pmd_pagesize; @@ -164,7 +164,7 @@ void split_pmd_thp(void) /* split all THPs */ write_debugfs(PID_FMT, getpid(), (uint64_t)one_page, - (uint64_t)one_page + len, 0); + (uint64_t)one_page + len, order); for (i = 0; i < len; i++) if (one_page[i] != (char)i) @@ -174,7 +174,7 @@ void split_pmd_thp(void) if (!check_huge_anon(one_page, 0, pmd_pagesize)) ksft_exit_fail_msg("Still AnonHugePages not split\n"); - ksft_test_result_pass("Split huge pages successful\n"); + ksft_test_result_pass("Split huge pages to order %d successful\n", order); free(one_page); } @@ -481,7 +481,7 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path = argv[1]; - ksft_set_plan(4+9); + ksft_set_plan(1+9+2+9); pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; @@ -492,7 +492,10 @@ int main(int argc, char **argv) fd_size = 2 * pmd_pagesize; split_pmd_zero_pages(); - split_pmd_thp(); + + for (i = 0; i < 9; i++) + split_pmd_thp_to_order(i); + split_pte_mapped_thp(); split_file_backed_thp(); From patchwork Mon Jan 6 16:55:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13927680 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 B9EB1E77198 for ; Mon, 6 Jan 2025 16:55:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47B1C6B0092; Mon, 6 Jan 2025 11:55:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42AA46B0095; Mon, 6 Jan 2025 11:55:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27DBD6B0096; Mon, 6 Jan 2025 11:55:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 03F346B0092 for ; Mon, 6 Jan 2025 11:55:46 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6B9E2140109 for ; Mon, 6 Jan 2025 16:55:46 +0000 (UTC) X-FDA: 82977628692.01.0D810D6 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2058.outbound.protection.outlook.com [40.107.212.58]) by imf16.hostedemail.com (Postfix) with ESMTP id 4E1DF180009 for ; Mon, 6 Jan 2025 16:55:43 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=LkzpCvPV; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf16.hostedemail.com: domain of ziy@nvidia.com designates 40.107.212.58 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736182543; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PXV4rWuZUVCz/nbn6ZSb49FvvwPgwyCkQ5fEHV4GAiU=; b=u8cHsoHE/1QidK1hraiQkmM1GwqzckbfeIgt1RUKKHBd6b0CwzbSiJBBicNCh1E33KTgtQ oqCJU5WeKSOttr6FhuPg4mFi7+au3VLsywrUGiyOzhy1n5fmSrZkr/lgu5hg3nLf+KgTlv eIp0/Hfbx42lLJGj36SJMq5oKyiEZoQ= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736182543; a=rsa-sha256; cv=pass; b=WK4/cb+39ikREHlLPhYqRck3VvMzmUu+cqDvyLBS5Fs1vxCIOcF5zvVIoA07YgbQF3dYSe kwS9v3DXgms0OfnijDIebR5T737+L3xt4wK8/5KiCyY7mCfPr8unjO7ENVyYtTF9AWYSgH /VcO32370OZhWTwwRxOunWA011NHHyk= ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=LkzpCvPV; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf16.hostedemail.com: domain of ziy@nvidia.com designates 40.107.212.58 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qlr+8MkFy8EWSusaXJu7VAe/MRicP4ZZaAW42N6kM9MX9MNIeOg97dzBL0mGRUBLc7Z62J5RQZ/dxmQH1bqIawrD9oJ/3C3YdwL3jsUOLAM6jqOHrcLnHg1//nXoJglb85LotvZBpmLCtxFYD6ObHJpBDM/NF55NbAbRNAe38mA0Ktrr7c6EG23tuTzFBmbrq8Mf+4k+VSKmUf33rbAbdaldKF3cId/umpxkmWUI73F/LvrTCIZo4H5uBF2aNX+NbfvudBrLrORp3E7ILRcLtb32hJT5o411DMqLTvYu9xJ1SIaF/j1kUbQLDIRO2AAGGsNaUpw94x+zhH1WCZU6BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PXV4rWuZUVCz/nbn6ZSb49FvvwPgwyCkQ5fEHV4GAiU=; b=fLM4+aRTVJrs/TZNDoXCQlzSNLPDdOs3O0KXxbS0UZ8ihRIslG83gBvBInMZO8IjMM7+7LCSK7QohLZyOXYsvO8sZSe4N9IcVGhma8K428hnXrVobAYU5ZfAYzGbojX9oMN9SXDk97V4IPQNczO6FSOFIRZNxz7u/4fG9i8EmdvW1nTanD8NO0I85ehZzWf8mLL55S61NFW2/sbU2GbbycmVf4IuxF+Kl94UJTh/CiaMbv7DmYcFajQ9PPXEtsyOGD3P7xduWUNKYnoXtlGp3amMcibTHMOYZJ7NSDCYvr/KaybCTxKGpdMV5OP2eUIOHGdEpNBddqT7f8MC4t4gtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PXV4rWuZUVCz/nbn6ZSb49FvvwPgwyCkQ5fEHV4GAiU=; b=LkzpCvPVraKAaqDMcmKySDu5RaRykJe6W48wFnpOxkrIMsowTeID6+diV/VhjTEIr1iKfBeSN/bQcuecWsu7ouePi8Bxi8xMOlBKtvdJgg3RPoJR78sXN3Cej+lhtny5yoG/C+D9ahQjR2foaqesfzgn65lOFB+NCpaS7M35CLi6NjE7MpZ2O8dus7Xe8gkXxDlZi+91qUaU4NiwRfjP6lowXDkpVjLlPN8DGxFcMtg74upRTk0kHe+H2+wopQxEAv07SgoE1V9/8PaOdzyzpKKXuDrSZkYAfMbvcZByjBycTo1Pr2DAsQWcvhjPLaHRpTYTPQi85mizLWz6pW713A== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by PH7PR12MB6634.namprd12.prod.outlook.com (2603:10b6:510:211::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Mon, 6 Jan 2025 16:55:25 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8314.018; Mon, 6 Jan 2025 16:55:25 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v4 03/10] mm/huge_memory: allow split shmem large folio to any order Date: Mon, 6 Jan 2025 11:55:06 -0500 Message-ID: <20250106165513.104899-4-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106165513.104899-1-ziy@nvidia.com> References: <20250106165513.104899-1-ziy@nvidia.com> X-ClientProxiedBy: BL1PR13CA0242.namprd13.prod.outlook.com (2603:10b6:208:2ba::7) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|PH7PR12MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: f19af93e-e4d3-4460-4c29-08dd2e72ea4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: Aqawqay0sgFbTtFX+apoyzuGD+JMa6IRtKpuFwY9hXlG6IvVkLp8LHBKwiAkBCyjcoEfUfzLZ5rAtvRNEKvI8E4+pxW4PIe12hrh8YS+5FKWUD/5s3Ltf6V5Z+I0U82YrFzKXNsZL8StEY3IXas29Zj1fhs1efEjQRHfGRh3LeKvty/lhq3uUZEYm/sThtjVIjZce2dx/JECOt2fT0S1SquRmUZVvnaVN0XjJ11YXJOI9G/O4DhTR5AgCLxVUPsEF51mOFUh4DPKv+i8RLaf4capM+W5PGgkXQUVAXnB/8bbwL3A63W6F8hNQmjlx5OR9LBB+zZoWb6c5Q9kB3RWQTQT7TDmsK9jGMwkTfAKDiA9yJBRJ/D/z8DDKSKKzugj9wcCbosmK2ZoU1FlkCwjoLYan970xgTtLd0ErkaP6FKp31fp5yzKp+W5cAWjKFfQFCBlf3KbiDUikwpYOkQhJOMKbe4KMEaE7OYwseFbnVSMbo6bwlBfBGFedHo1CglhiecR56tzzHF14kdvFjLwAP3sy+PveqOLiKoGiQ5Y8P2k8aW2/W19dz5e4JRnTgvyb7DuBwdaYv47rex8S6gt2EOyelZMDE/NO8v1FrizDZwZ36T3sA+emNo5dA/t45BVq1m+/e7Ksn7FVK+Ff9Xfk4gAzV++nPWafs0Fjbu9T+C2elkuaE7PBg49tGJUMKAyA3xabfRkSm8dyxVPaAlaQddER4A9e3EGiewI4OODKt3U105/1I7IM47LurFcIP6itjbmE4pkCNwSqG0QxuitPHW4uOKQ4NGQtz2RfuqfqRn9+F6C2FPUvIyH8Q7IdI6dNeHoRSc9M8a76eBzuQuMJinALVXPCRVSP8GEzPtSAHitC9O5zdlmtXfCuO6kE+Ac5pTPin/V94dyCJvkc3dbqaWWLOUl3N9cvvdSmK9MGDFYl1J88UIqq4KGsRYxAFbQu7XGVu+DvcBOsQIcWOCM+Q+sPevRHlx5sbQS9LLoM+uIChC7rri1eBbZjhB0XL67OkcDQzSAH7XzL0eD8D3wReohEN24wMEqU+sqaN69EL0Iv1DROQsf89uDI0RlsJiixWgMQnDnx6UDxzxuMdwjNfFL5w1G4+r2Yp4xyVYU743Ydk6OpxF6wsj+b3jGrg5fzL1OnCkgvWIQjhXcXX8Kp6tXrZgo7ibQRkAgJvTD2xpM3yDgx+KDPFxAAkaUwahUfhcR9JNrkcIciH8av6DPsn8juhsJXciz58iFOIi78e5pFFCf8RzPQnkUDvxnVIzE+my6/XMDBcPgjp65pOuAIqAUQhjprO7QeG08vM+j2tG5Aljgdq2UCaIMah39vnqA9IfDZZqbqW/pDCs3PM23i8pRPDhYNJ8/50wxTCt3WenEsRt0SO2MT4n/2hgTI/Ho X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lixZ93JToOT4jaSiAogbpgOMqq01c1LD7ex1v+Hs5MaSftpm8Jh8lsdom9OUGbP5ZedjPiKLnCSOHINMRl1cDeN7OpME8jYm5r17Kf6VdNgWsYKfHGx2gE4T+ht6vHoc6a/Bps/r8iHgCi8FQBoZGNyniNh/xA6/WB8+6Gqn0ySGevjuW68ydVsfXN6uTk7KI2E/CvsR2GDJ3DsQVtgG05ZD/t3Io4QRWszeL3BDWikv0wX0XF28uU4bn5w1VKmig8wRnm79Mg0gsRPp3VKJ6P/4PuJIMFMbG3DOKKjyBfQl7KakLnwaP58pDDJUGg6nIwp5H5Fwlpvaa7JH8LWaC+nNot/aHqG1Ge4LG+Z2ukIb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X6yj/a+ppBSNLHUvTF8KJk18APUNzyOy/4W83w62OCEhSWFD8N8SLxUSCVljUOYTXJduF5UO31u9EAETp60PNTPvsDZhyufKHhCcEqvMop11OKJ03zQczNN79PI4EvknoGWUBBnTViT4KgrzBSk/P9+i+2H+XJCw7eauMSgtjKeLBJK X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f19af93e-e4d3-4460-4c29-08dd2e72ea4e X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 16:55:24.9780 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: E3Jm0Ns44Y+xBWvp1Bt1W1a8KIfwWEWVi6cjKBmEJTm3+f5bVLOPtTkqFobwjk1v X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6634 X-Rspamd-Queue-Id: 4E1DF180009 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: qs7cx6myp6iy1bn6fz3r7utuq5ykngjo X-HE-Tag: 1736182543-104065 X-HE-Meta: U2FsdGVkX1+kOw1oF+GbZ5MkDWqx+1XDiU+L2jezdaUwCVr9+eRjUKVlMIIpjMdDwxoTDylTpryUTtZ6zd7ZY1MDV3BYZJk0adY6iYp1hpUTeEa62al67F8GK9yGgpOnrpWQj73Q8iQMiPDYLhhNtT4D0dI5GNASbHqc3w+PlU8iwESXVNY4QlVkh+TtxDLDni9HotvDDPmUPFK3cYtVB1XPmP4Ns7pQp7TGxhpICummVN3vZWrBvta6N2WnpE/ojbIQ7/rY4QIprlIPX1zuBlL6iBb9mxKCCCCYexrd2JX8GzR4cEYjY1bb95vny1G+u7uyQ9YATcrt2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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: Commit 4d684b5f92ba ("mm: shmem: add large folio support for tmpfs") has added large folio support to shmem. Remove the restriction in split_huge_page*(). Signed-off-by: Zi Yan --- mm/huge_memory.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c89aed1510f1..511b5b23894b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3287,7 +3287,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, /* Some pages can be beyond EOF: drop them from page cache */ if (tail->index >= end) { if (shmem_mapping(folio->mapping)) - nr_dropped++; + nr_dropped += new_nr; else if (folio_test_clear_dirty(tail)) folio_account_cleaned(tail, inode_to_wb(folio->mapping->host)); @@ -3453,12 +3453,6 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, return -EINVAL; } } else if (new_order) { - /* 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. * Note that we might still have THPs in such mappings due to From patchwork Mon Jan 6 16:55:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13927683 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 B674EE77188 for ; Mon, 6 Jan 2025 16:56:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47AF66B009B; Mon, 6 Jan 2025 11:56:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42ABD6B009C; Mon, 6 Jan 2025 11:56:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A5D26B009D; Mon, 6 Jan 2025 11:56:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 073B76B009B for ; Mon, 6 Jan 2025 11:56:14 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A6AF01C507E for ; Mon, 6 Jan 2025 16:56:13 +0000 (UTC) X-FDA: 82977629826.08.4A03506 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2067.outbound.protection.outlook.com [40.107.243.67]) by imf22.hostedemail.com (Postfix) with ESMTP id D36F9C000A for ; Mon, 6 Jan 2025 16:56:10 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=sl6MG5mZ; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf22.hostedemail.com: domain of ziy@nvidia.com designates 40.107.243.67 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736182571; a=rsa-sha256; cv=pass; b=wo+Jo8GN4LdzBCGZN8WEYMapsqzzLgdi0eMEqULjqkLfGz5sxRrDSkxZyDX4jrXug90mfN hf/aiyUbTLuxbzg08TiNX35uTrWnMxn+5L0enKDGr35tVM0ppqAZnFe4frt64zYNzYWu/H xqGh+1fc6FBDInH0FosUagEKPeumKL4= ARC-Authentication-Results: i=2; imf22.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=sl6MG5mZ; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf22.hostedemail.com: domain of ziy@nvidia.com designates 40.107.243.67 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736182571; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w5KWdyZeoa2VeruT4r2+LenfbzuPXZNx6nW2k88D9S8=; b=ghrX6CrIuyAJB1K5Km0MEVH/x7Q2Trd6Ngm18eWsUuj8KAICetJm+OO8Ipq8t3N0jpWX9H wmHpKIfta9Rafw5d96YTb4cFPUIkqyv5DL1RNdCxCff8IBpUSUnjsyZG3YpcikU1nMY1dQ S/5id6yF4okSmPyJ1FUQv5+CS1mu140= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WIXuc5IRD+fOflraJ9nGO94mSohAyuFxF17aLvOVEAYQ+4ANV97fLLK9SSsQUlf8yxFsYUIAz5XMFfl8sDAKG52UwDIBdL4ZLLu1bQuUes125uVmXPzd7YG7auNoPzPXYEHvCpuQDAW1FXjoqoU/sikRYuS0h97tItdHvKETNPnsoPVeejlpGngM7VycXkYy3ZNa1nJP08hMXl2DxbP1UC/IgkUJf59uPZCoV3kY9eTZhw5g+DVBgjhi95xSlaz8WZSFB74+9gVmfQz83a8I3LLlBI3At72sxvc//McoCzYOqH415bDlYx/HSPs0qy5nJw/0kcyH9nhgYyDQNhfWfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=w5KWdyZeoa2VeruT4r2+LenfbzuPXZNx6nW2k88D9S8=; b=Wy9oepApLGQfWWgRgH/Wxhx6TjMCYZIPEVQPzkc9fZHfHstyckKbf1d+EDpztERYGGcce9rwDSoLhps2Ye0R7Dhnw9XasFlnckc1mF+T3gItJaIemjZzEO7KEs96sZRgX7jXFnfXa+k163QnotoVKEt3CzYycs55Z542AJpGzdy1YvvIAoIQUw8Ko9WURexCRx46WMsLZgJ5KVG5nYgHqVw3/B89RtKH8JNJ9CnZfj7lHN8zaIq8Cb9GB3Ed1yDDBpOIoTYnH/XvUmXroOmS12b/eLr5ZNJK2vgAOTt0v1sjb9No4UPXPQbeakbkMj8C/1PdDQyG1P9NTl2i3OkfTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w5KWdyZeoa2VeruT4r2+LenfbzuPXZNx6nW2k88D9S8=; b=sl6MG5mZ9qV7d0i5xFWYSqLFdzNfVgJ0cl2JrmREilX6wfZJ+KcDfbxSg6EfmtuHAa8TEjqwYz14m8FWy6HFLsL4XG84NWRVYGeSv6lOH2AZEs1VzWPEkso504h0p25hdZz5wB+uHq2YQI6s/+3YY6MUEE3qTFyd4ypu2mvdLy0sfjRAV8zBWxNYAV/pARE/XOjAJwSb3bdoR07uxbNJc7aXwDHgSAxFONvdoHMGJ801SH//ksB4UxzdkSiKZ7NHMTGHIkCPvtMmNEOScpF4uKttJgudfwINtO28C4DG4F/Aic5JrmFQg4rzSKa69ZKOX3s2ahICXkd0Dqb6QBtleQ== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by PH7PR12MB6634.namprd12.prod.outlook.com (2603:10b6:510:211::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Mon, 6 Jan 2025 16:55:26 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8314.018; Mon, 6 Jan 2025 16:55:26 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v4 04/10] mm/huge_memory: add two new (not yet used) functions for folio_split() Date: Mon, 6 Jan 2025 11:55:07 -0500 Message-ID: <20250106165513.104899-5-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106165513.104899-1-ziy@nvidia.com> References: <20250106165513.104899-1-ziy@nvidia.com> X-ClientProxiedBy: BL1PR13CA0241.namprd13.prod.outlook.com (2603:10b6:208:2ba::6) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|PH7PR12MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: 8322bfb5-c7cb-4d98-1a95-08dd2e72eb15 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: 00z+cm404Pj2Lp9kd7t5NJ8bQLyDcJIoCO+GoCEKWL+mSyRT3LRUW26bdUYmPQOU7K8c//XurTLK98SohzMAFWV4hkZRVbVwoNpbZYJD8x0CQoTXrLRe3IDgMRz5tKYBUmft9xvgyIMXIEiDn6+sUX22wguIfmeuZ8ebZ7WsvRzrIKkcVuVyB7y7xyBXX/ZU4KjU9+KJNFPZNDk0D7WeFoFsDc5hll8/BlsMqIVRTfQTSWFheHCP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kKit1CbwHGAj8enkEEhtgBu/pZRcKYDorUDfpNCWpyErPPDFHGXoSIH1j2JRNfO+fmhZi4l1WUVe6an3lbSS+Pm9 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7FWQgeGE4eXS9x8WzNyrrIQENHE60wAA4CTxdUNqtWKrHstfQMD7Wyz7hKISMrdCKZaiUPNyxj2OCCxjSEbTHSj+NnDCHg1R6yeebS26xpxt9eqwwEtfW93SUmmtozvA2FEcARBinD+JbRuBNTAKke+LPFRhPJF0oSAM1bNE3EVrduGCLhakCd/f4xnCqipe3uFBWV5KFVY0HGxuVKbizMkhOSPkTKWQrDFW0Bhar74XIrpPv7sET4m3/fNs/27r2xJjd/gKtUX9gx90/SjAUU0fLikXf7G4QRe0z3rQeMhGAKexbSMUBaXIuR4/Dye5+KHPBpMg5Za7WpQU7YeniRyGI8gNp1TB3ZrN2gLfrjorGQItyl/Xc+lVYHHEA0hbpN/yywQo6yvyQg8rgRt2j60OuYorZe6wAVVafqhhMPJ6ANfdpeW70Hm/6fgClgwUJDsJ2oJlvSoGF2V8pEKU/hCngKIMm8OH+sfw63XOPrQcBmn2nQpVh00xRpRCRyXWHpKJBJinUefvD0vwD/wsaDbPTHnZlQ1ptoaLUS7J6Zlrfw1Q2TsokUjLgHzNNxXI6lnCm5Bkn8oAdXHrvGESN9zoLndx1kXhUykno5HujUMFJ3BLB5B5eq9o5VsCn0niwLgKNF55W7Swku7BISoTtSYvSCEhoM9ZC0/B/Lcs4fLTjeoknOKnSry6yOvrozwnzEfOPMsrhjU7IWAai2wNPt+PS4o8iPoxmXkvqBRlluYvvYdEJRENu2bUKV9x5Mw5vCHtfZwxzzPQLxqDAjNGXkl6eopYQGFbwQmoVqMs7PW0GiVY3MnFemr9UZUZNR5fRQNtQR/SaHXmWBLK6/xuHlcBZn0su1snwgOk2VSQty7HzWJFewT/6xPki4tako7qjOQtfaH8yPMBrOKt8g6gfN6SliqAZKXq1zsjxwMnMpl9LuhCKf8x7CGx2BdsMSggyI5+v4NwXQFNnROuckz8P0UwDM+Xf9dEmb9lwd/BKhEN5PCtfd4zZcDTKUVxuRoyFShEPoln6QwMkgmuFPs3qZEc0UyhU3GWcQsZ2pJLYcE0ZGbwVK9m+y8v/mgTRQNC6SKmH2pGuoEPxS/fhjqvIxUYXRjozyHArtnnBWE6fKDmTLgzSBxxv1LzICUVH54Y1vlqcaH/f2RfkNsY8pynNE1Ovyehrfy0H9sCkLaqXX7NQNuO0rX0NxazVuruoWzLwdrwIVao7Xfr7YaLxTxnEqUqLEXgBqpaig4dAK46VWqQkpcA9y46KtNwhu+qRy9cYa9Uj0JWTS+B1dFnRAJWiyBUbiwhKaO9sv9S96slUfUTNUCiuR5Y1h2twtgZGtZH1PeWPjgREylF/QNrXO5uZJGLwDWhxTWAUS6I73tqeIqQanrQXCk90zdh3kV30Ol2rJHQv6URvupaxOUIHVz+kKtM8EvM11Ms0girduE0+Yrpz3Rimcy9UcybzFCCi2X5ZDFaHJz1B0eE66eGQ4kiPFaEMQPHSnMKx5sNspr61vv7qYSVLxSIgR+mGko/iPcAISHHBoembXPlNWAq9UhF5zieo2lfKvM+W1GNZT22hWGyAGa3Xs8RVCjNwse6rlH5 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8322bfb5-c7cb-4d98-1a95-08dd2e72eb15 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 16:55:26.3198 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uhUYT2mD/xlIZiCnA5/NVczW197dnj3OqAgYJm8qZj2NMGQChYhe3vDpRL/X1R4q X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6634 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D36F9C000A X-Stat-Signature: 65u4fon9fk6xydeixf4syxgyhhgfqbge X-Rspam-User: X-HE-Tag: 1736182570-732938 X-HE-Meta: U2FsdGVkX18AvynQvTl8bLUSAhV+WnDP7Jh4/aygmJjs+EhYsR6T6ZrYOHyjc9GM9E+XzBhMNwRt7IgmG0PoZw+svJUG/FeNj8CFQrR/GTr/pefzK+YGv2UR3lhCccshkSBQ64ZIkVXlVPRVzcpd+jRE8iJVl39dDVTY8am7RDgj5r4ykE49CF/ReTlDW2CUQMXBJZKJHCNR26bODpGBqUIvQUa4+vG9KYiIsnk6r8vjIL9HM9U/KyrG4v955oyQX4sRb+syYoucp7wRmiW7+hwcS52i4Q9iN3irKhjN4Qtk8R7D8BTXFtAXwx1+4DSE0WXMppoBZNqWYH2skWTpNdxMxSgTarRwKDaltTlHewYyF1XyypIgUofOD0sKz+dEag0iciwmJv71mnvwB+7fGaUoZopP7K6kqIOMYWT8WcBGlWluet0YPz7cilFCA05oG4ZBD+VswD+GvatMXmTZLRMgunZcDesUecE830cfA+eXA/X8mnmkMtcyST+BoZaM0vrL0dDb58DGk5OwMf1NuCuQsyKkn87k19fRfrq1SCE8xs1d+qmYlQofVWhLfPRAsOeyycExd6OuOj0FCFO2H5N5CD2U4yla5kaPecz0XXPYRPBvUvnFylXbXq/j4zyhgogOOdVx9X4VCtZdEqxhEWi9CFb1wgFHTviHfyaV+FsAmKZzCV18fwL830SQvcYUMhQPrP7Q3KugxiW3sdQqddt7dJd7qqlC3ekCajV+HEm7VwjJfvIyMueAWFrN6fKhs4qPHpQ8mKQVsvtL1aQy3mBm8WiIHczUzZShx0eyG5jTsb8i0CV6ZSeyHxLlEbam2o/9WFkW7kXGeX2O6/WXRUKO0rIXQVgeKzEIyiqLHrg5yDvOioq0WEda3CoD3C+GG6u66cThGD9LfoYSNTKug9bzmy2Gu61BJ6c65r8s+C6es9veGTemuuXF1Srmv4lydGk+PIRN5S/FZMBzp2f Iw/7EuXs AH+mMlnYm5PpJT+VwCIkjaowqWu9xoycL2M03adttfu/6VAsDo52mmpYTaG/ygar+IKwCoIF7wKPnijqBvHFx6x5Voq6jzurOmQzEFSPcPMNVUZNeSZZ4B0hmSTWBEi373yl0j9sWw4W8nKBKrukEbp1QxwD5d/1wI5OQQix0NRfDqsiKtTUL0j3kG3ZPQRRKk7w5iUXRSp30JKirXy5+FCqzHkocaVqk+34Bxf9nNsuxX/aSmA9vQl3ry5aT6RPuozcgtZGKVgPvPsWUSjtpRfoyIq4tMlPumFlK66CJQTqBCbY9beR7Im2gNh3qi79AiedGHnodLNXZ5nwT27ni97j7VS4EirQ8pDxroItP0xs5orR3zVx3FhU9dJLIhZKlfjlxWoZ5OnKP+RE= 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: This is a preparation patch, both added functions are not used yet. The added __split_unmapped_folio() is able to split a folio with its mapping removed in two manners: 1) uniform split (the existing way), and 2) buddy allocator like split. The added __split_folio_to_order() can split a folio into any lower order. For uniform split, __split_unmapped_folio() calls it once to split the given folio to the new order. For buddy allocator split, __split_unmapped_folio() calls it (folio_order - new_order) times and each time splits the folio containing the given page to one lower order. Signed-off-by: Zi Yan --- mm/huge_memory.c | 348 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 347 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 511b5b23894b..d8e743f81e76 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3134,7 +3134,6 @@ static void remap_page(struct folio *folio, unsigned long nr, int flags) static void lru_add_page_tail(struct folio *folio, struct page *tail, struct lruvec *lruvec, struct list_head *list) { - VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); VM_BUG_ON_FOLIO(PageLRU(tail), folio); lockdep_assert_held(&lruvec->lru_lock); @@ -3378,6 +3377,353 @@ bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins) caller_pins; } +/* + * It splits @folio into @new_order folios and copies the @folio metadata to + * all the resulting folios. + */ +static int __split_folio_to_order(struct folio *folio, int new_order) +{ + int curr_order = folio_order(folio); + long nr_pages = folio_nr_pages(folio); + long new_nr_pages = 1 << new_order; + long index; + + if (curr_order <= new_order) + return -EINVAL; + + /* + * Skip the first new_nr_pages, since the new folio from them have all + * the flags from the original folio. + */ + for (index = new_nr_pages; index < nr_pages; index += new_nr_pages) { + struct page *head = &folio->page; + struct page *new_head = head + index; + + /* + * Careful: new_folio is not a "real" folio before we cleared PageTail. + * Don't pass it around before clear_compound_head(). + */ + struct folio *new_folio = (struct folio *)new_head; + + VM_BUG_ON_PAGE(atomic_read(&new_head->_mapcount) != -1, new_head); + + /* + * Clone page flags before unfreezing refcount. + * + * After successful get_page_unless_zero() might follow flags change, + * for example lock_page() which set PG_waiters. + * + * Note that for mapped sub-pages of an anonymous THP, + * PG_anon_exclusive has been cleared in unmap_folio() and is stored in + * the migration entry instead from where remap_page() will restore it. + * We can still have PG_anon_exclusive set on effectively unmapped and + * unreferenced sub-pages of an anonymous THP: we can simply drop + * PG_anon_exclusive (-> PG_mappedtodisk) for these here. + */ + new_head->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; + new_head->flags |= (head->flags & + ((1L << PG_referenced) | + (1L << PG_swapbacked) | + (1L << PG_swapcache) | + (1L << PG_mlocked) | + (1L << PG_uptodate) | + (1L << PG_active) | + (1L << PG_workingset) | + (1L << PG_locked) | + (1L << PG_unevictable) | +#ifdef CONFIG_ARCH_USES_PG_ARCH_2 + (1L << PG_arch_2) | +#endif +#ifdef CONFIG_ARCH_USES_PG_ARCH_3 + (1L << PG_arch_3) | +#endif + (1L << PG_dirty) | + LRU_GEN_MASK | LRU_REFS_MASK)); + + /* ->mapping in first and second tail page is replaced by other uses */ + VM_BUG_ON_PAGE(new_nr_pages > 2 && new_head->mapping != TAIL_MAPPING, + new_head); + new_head->mapping = head->mapping; + new_head->index = head->index + index; + + /* + * page->private should not be set in tail pages. Fix up and warn once + * if private is unexpectedly set. + */ + if (unlikely(new_head->private)) { + VM_WARN_ON_ONCE_PAGE(true, new_head); + new_head->private = 0; + } + + if (folio_test_swapcache(folio)) + new_folio->swap.val = folio->swap.val + index; + + /* Page flags must be visible before we make the page non-compound. */ + smp_wmb(); + + /* + * Clear PageTail before unfreezing page refcount. + * + * After successful get_page_unless_zero() might follow put_page() + * which needs correct compound_head(). + */ + clear_compound_head(new_head); + if (new_order) { + prep_compound_page(new_head, new_order); + folio_set_large_rmappable(new_folio); + + folio_set_order(folio, new_order); + } + + if (folio_test_young(folio)) + folio_set_young(new_folio); + if (folio_test_idle(folio)) + folio_set_idle(new_folio); + + folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio)); + } + + if (!new_order) + ClearPageCompound(&folio->page); + + return 0; +} + +/* + * It splits an unmapped @folio to lower order smaller folios in two ways. + * @folio: the to-be-split folio + * @new_order: the smallest order of the after split folios (since buddy + * allocator like split generates folios with orders from @folio's + * order - 1 to new_order). + * @page: in buddy allocator like split, the folio containing @page will be + * split until its order becomes @new_order. + * @list: the after split folios will be added to @list if it is not NULL, + * otherwise to LRU lists. + * @end: the end of the file @folio maps to. -1 if @folio is anonymous memory. + * @xas: xa_state pointing to folio->mapping->i_pages and locked by caller + * @mapping: @folio->mapping + * @uniform_split: if the split is uniform or not (buddy allocator like split) + * + * + * 1. uniform split: the given @folio into multiple @new_order small folios, + * where all small folios have the same order. This is done when + * uniform_split is true. + * 2. buddy allocator like split: the given @folio is split into half and one + * of the half (containing the given page) is split into half until the + * given @page's order becomes @new_order. This is done when uniform_split is + * false. + * + * The high level flow for these two methods are: + * 1. uniform split: a single __split_folio_to_order() is called to split the + * @folio into @new_order, then we traverse all the resulting folios one by + * one in PFN ascending order and perform stats, unfreeze, adding to list, + * and file mapping index operations. + * 2. buddy allocator like split: in general, folio_order - @new_order calls to + * __split_folio_to_order() are called in the for loop to split the @folio + * to one lower order at a time. The resulting small folios are processed + * like what is done during the traversal in 1, except the one containing + * @page, which is split in next for loop. + * + * After splitting, the caller's folio reference will be transferred to the + * folio containing @page. The other folios may be freed if they are not mapped. + * + * In terms of locking, after splitting, + * 1. uniform split leaves @page (or the folio contains it) locked; + * 2. buddy allocator like split leaves @folio locked. + * + * + * For !uniform_split, when -ENOMEM is returned, the original folio might be + * split. The caller needs to check the input folio. + */ +static int __split_unmapped_folio(struct folio *folio, int new_order, + struct page *page, struct list_head *list, pgoff_t end, + struct xa_state *xas, struct address_space *mapping, + bool uniform_split) +{ + struct lruvec *lruvec; + struct address_space *swap_cache = NULL; + struct folio *origin_folio = folio; + struct folio *next_folio = folio_next(folio); + struct folio *new_folio; + struct folio *next; + int order = folio_order(folio); + int split_order; + int start_order = uniform_split ? new_order : order - 1; + int nr_dropped = 0; + int ret = 0; + bool stop_split = false; + + if (folio_test_anon(folio) && folio_test_swapcache(folio)) { + /* a swapcache folio can only be uniformly split to order-0 */ + if (!uniform_split || new_order != 0) + return -EINVAL; + + swap_cache = swap_address_space(folio->swap); + xa_lock(&swap_cache->i_pages); + } + + if (folio_test_anon(folio)) + mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1); + + /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ + lruvec = folio_lruvec_lock(folio); + + /* + * split to new_order one order at a time. For uniform split, + * folio is split to new_order directly. + */ + for (split_order = start_order; + split_order >= new_order && !stop_split; + split_order--) { + int old_order = folio_order(folio); + struct folio *release; + struct folio *end_folio = folio_next(folio); + int status; + + /* order-1 anonymous folio is not supported */ + if (folio_test_anon(folio) && split_order == 1) + continue; + if (uniform_split && split_order != new_order) + continue; + + if (mapping) { + /* + * uniform split has xas_split_alloc() called before + * irq is disabled, since xas_nomem() might not be + * able to allocate enough memory. + */ + if (uniform_split) + xas_split(xas, folio, old_order); + else { + xas_set_order(xas, folio->index, split_order); + xas_split_alloc(xas, folio, folio_order(folio), + GFP_NOWAIT); + if (xas_error(xas)) { + ret = xas_error(xas); + stop_split = true; + goto after_split; + } + xas_split(xas, folio, old_order); + } + } + + /* complete memcg works before add pages to LRU */ + split_page_memcg(&folio->page, old_order, split_order); + split_page_owner(&folio->page, old_order, split_order); + pgalloc_tag_split(folio, old_order, split_order); + + status = __split_folio_to_order(folio, split_order); + + if (status < 0) { + stop_split = true; + ret = -EINVAL; + } + +after_split: + /* + * Iterate through after-split folios and perform related + * operations. But in buddy allocator like split, the folio + * containing the specified page is skipped until its order + * is new_order, since the folio will be worked on in next + * iteration. + */ + for (release = folio, next = folio_next(folio); + release != end_folio; + release = next, next = folio_next(next)) { + /* + * for buddy allocator like split, the folio containing + * page will be split next and should not be released, + * until the folio's order is new_order or stop_split + * is set to true by the above xas_split() failure. + */ + if (release == page_folio(page)) { + folio = release; + if (split_order != new_order && !stop_split) + continue; + } + if (folio_test_anon(release)) { + mod_mthp_stat(folio_order(release), + MTHP_STAT_NR_ANON, 1); + } + + /* + * Unfreeze refcount first. Additional reference from + * page cache. + */ + folio_ref_unfreeze(release, + 1 + ((!folio_test_anon(origin_folio) || + folio_test_swapcache(origin_folio)) ? + folio_nr_pages(release) : 0)); + + if (release != origin_folio) + lru_add_page_tail(origin_folio, &release->page, + lruvec, list); + + /* Some pages can be beyond EOF: drop them from page cache */ + if (release->index >= end) { + if (shmem_mapping(origin_folio->mapping)) + nr_dropped += folio_nr_pages(release); + else if (folio_test_clear_dirty(release)) + folio_account_cleaned(release, + inode_to_wb(origin_folio->mapping->host)); + __filemap_remove_folio(release, NULL); + folio_put(release); + } else if (!folio_test_anon(release)) { + __xa_store(&origin_folio->mapping->i_pages, + release->index, &release->page, 0); + } else if (swap_cache) { + __xa_store(&swap_cache->i_pages, + swap_cache_index(release->swap), + &release->page, 0); + } + } + } + + unlock_page_lruvec(lruvec); + + if (folio_test_anon(origin_folio)) { + if (folio_test_swapcache(origin_folio)) + xa_unlock(&swap_cache->i_pages); + } else + xa_unlock(&mapping->i_pages); + + /* Caller disabled irqs, so they are still disabled here */ + local_irq_enable(); + + if (nr_dropped) + shmem_uncharge(mapping->host, nr_dropped); + + remap_page(origin_folio, 1 << order, + folio_test_anon(origin_folio) ? + RMP_USE_SHARED_ZEROPAGE : 0); + + /* + * At this point, folio should contain the specified page. + * For uniform split, it is left for caller to unlock. + * For buddy allocator like split, the first after-split folio is left + * for caller to unlock. + */ + for (new_folio = origin_folio, next = folio_next(origin_folio); + new_folio != next_folio; + new_folio = next, next = folio_next(next)) { + if (uniform_split && new_folio == folio) + continue; + if (!uniform_split && new_folio == origin_folio) + continue; + + folio_unlock(new_folio); + /* + * Subpages may be freed if there wasn't any mapping + * like if add_to_swap() is running on a lru page that + * had its mapping zapped. And freeing these pages + * requires taking the lru_lock so we do the put_page + * of the tail pages after the split is complete. + */ + free_page_and_swap_cache(&new_folio->page); + } + return ret; +} + /* * This function splits a large folio into smaller folios of order @new_order. * @page can point to any page of the large folio to split. The split operation From patchwork Mon Jan 6 16:55:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13927685 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 E77A9E77198 for ; Mon, 6 Jan 2025 16:57:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78B4E6B0095; Mon, 6 Jan 2025 11:57:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 712606B009F; Mon, 6 Jan 2025 11:57:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 564B36B00A0; Mon, 6 Jan 2025 11:57:31 -0500 (EST) 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 391586B0095 for ; Mon, 6 Jan 2025 11:57:31 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E6F6212011E for ; Mon, 6 Jan 2025 16:57:30 +0000 (UTC) X-FDA: 82977633060.23.AF100E8 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2075.outbound.protection.outlook.com [40.107.95.75]) by imf01.hostedemail.com (Postfix) with ESMTP id 1A67740013 for ; Mon, 6 Jan 2025 16:57:27 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=SZuQG6rh; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf01.hostedemail.com: domain of ziy@nvidia.com designates 40.107.95.75 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736182648; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SPvVoJvT4mBBzU5IHfOt+qRzccUAAB1+CNSz4Sg4YUY=; b=jW4TxYrBJh7shNTY6VjShsBxBF8vIqq8ch378f0rHOuNaQoVplr8azQy1+cipfd+9O1KNQ 7VLNuqAsnTmYE4jyK1k6IWRkodxeOgB/kHhrc/uJsZNl2lVubdEdH0SwNzC0bASjnDqO/1 E4sEU2UvkxZaL4fhWRt086B74bav16Q= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736182648; a=rsa-sha256; cv=pass; b=gVRri23J870/39tcnnYMpV7UJdN6nNqSP+vyt8KEXrNFXUEZ5C5FbEDxxvFL5jA9QgPUzH yIVlxXHF20Nh8etbln+MrmBltoYFtBju0qlZU5v7TRnvwYFRtLrGxZJfUVGLQVrF7lIdHQ x2eTkiql1IHTTE6OB2LZM/Dk0Ovbcs4= ARC-Authentication-Results: i=2; imf01.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=SZuQG6rh; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf01.hostedemail.com: domain of ziy@nvidia.com designates 40.107.95.75 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FtUorw4fnz7gfZIeiP17bNOg9tqBoV9Aq+GPXxl+Hiut3HLB1CADXzHw7H0c1L9NeF2bce0NvvDgZ3IS6HOY21khS4wpc87kabSpFtpdqbIBB1/8j4TLBpyUmhymEt9l7R2uPYpG2P9B6R+wXCNXa5RgI759isMgyggYBa35N17WNQITcfKcXSEeUN4UwizEDMpqz0TIRcVBu7u8ZZLKZ3gHfKvmC2nqiWBOqbOC83tyrTeN+9X5y9qco6NAURywQEu/vTW7R4PUF0GCEiC12XH7NkZO/cWn0oAm08j4Jo8s9kPA4ijVdyiIGfdaZh13T00ccORlybkwYn4THl0Tbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SPvVoJvT4mBBzU5IHfOt+qRzccUAAB1+CNSz4Sg4YUY=; b=J8MzkTQTeqzfa15TpUiYMyapCuwNajPvyXm3yanQNnS3Q/EWrT8c+PdZiiIP1Hb4HAIRV3In6yl8ItlQQj+36bZnLonYXK+d0O/qjY6sEENfGkGCIzucm+dANbNdz7D7euzKx5wKu3Hu+bJBf/KdwhIUKEc7gtPnIBqphDvoiY77tJPGaARLXRO+ZZM5Ij1QOjV9RrWNKUuFPhbM9Hb/zMAyNGvSvyABLywjpUHiNVyiRhm7kIa2Vn0wD0SWg904qERsK0Yup3LIpwcI2ktL4RX7LYCMGn6CALvN7eESZmnBLtSOjBk8mwoZVQcn2R68SWghYVGOVfO1wBJajpQweA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SPvVoJvT4mBBzU5IHfOt+qRzccUAAB1+CNSz4Sg4YUY=; b=SZuQG6rh6hqu+FEmnrS0uHer/Z/LSQS4dQtNEq0j+M2haqwC+Eb1BAhJOqvzTa7J5n+WjRAKLJziwBF3zaN9UJ2yBXb9+a4aoBr9MCU1VvShU+MhSULzpvp7jb759HO8EdBeswGHobao/PZ0J1WQPVYK15nbg+lX69UUDACj4K95ULL2Wp9q/+D1QBTpBMa1zAnrSFPVb1BJOVTpFVrb2NowipOhEpDu+t0VjvJRBiFIIN5nESBnikjKscxTyEGXm/mlxwY2lKggF60CQkhmhcNhQ2BXhZHnbqoBHFXy4Exyz3HZqHoF7t1WICyjaTEi5TtTmra/U8Vq62ncPanBZA== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by PH7PR12MB6634.namprd12.prod.outlook.com (2603:10b6:510:211::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Mon, 6 Jan 2025 16:55:27 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8314.018; Mon, 6 Jan 2025 16:55:27 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v4 05/10] mm/huge_memory: move folio split common code to __folio_split() Date: Mon, 6 Jan 2025 11:55:08 -0500 Message-ID: <20250106165513.104899-6-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106165513.104899-1-ziy@nvidia.com> References: <20250106165513.104899-1-ziy@nvidia.com> X-ClientProxiedBy: MN2PR08CA0022.namprd08.prod.outlook.com (2603:10b6:208:239::27) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|PH7PR12MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: 88cb1e27-229b-4cc7-01dd-08dd2e72ebdf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: DqEU+yVDVswf/iqKrnHlgBDcHIFARiocXPoBx2D6Ugj4W3Pp48J3iVil9XNejJTaDEpYRbs9n+yh/EzpdEIj0/VnJqf6dQ2Qzqft/cn0umbXvc6bI5gj455YL/HgGhDHpDjBooZINh6uokeE3X3Y7fXHJCI8dERHBFD+VZ1Y2W31nOOsJzkVksSxEHvoq9xEhJrctYwe8smMNq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2gPLo0uMwIdbi+VpQiogIhLAfjFMNZi1fEDPqKNRdfoBfvvusLLdFlbUOjBEZSlt+IfteCWRi/Zv5pjaB8PXTVSJX7cNtHT1kzyFizBu4a0ISse8QCeQTY X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NQ3X1QnXhu920HW/Ke2kCZAiyZKTYX2gOT7Zzs3WbxbE9oMdLb4S6YGGrOHhCbp2+hZNwCaPGkZlRCyv5tNkvzuJCakazBMonD3E9AsrIKR7pSLZD6ftn9cu/PsZuqj1Vm1KUjhEVICxPNrMr/Ws4cfmYqfRQjqHRnVnY99snkScBRFJ8jiNc1N8yEqq7uxoK9g+4kNZ0ddcNICoqBhxlXdynDaSXl7YchCnx7Anj2ryLyIipZv3KB9gR+g7L0aPgX2JtYQPAfwWtgasXiO5v3JgNoRahKqDqq7RMwWAUK4ItXCEdFGsvKny0loFgzyYd66MCmnHBtUN363ExtgREj0cONWRty1GxAR8NtTQAxJ35HFiH7hjv4yibG1425NrbMTHZYWBah4WyoJtMFlKGsWLZWglUdJbeS6fyfkn5xiGwRWz+XY4jdm/a51sBjJrPtMHfIhe3SCLOE2L8hkFfK/OjdBLN2zoqCN6aJF6qDA23h17pJvcSGFDA/qf7FRaorDHeIdwy/ZqqblyZC3HBjCfUpT92MEuGQYTuoAW1we9Wfp/8RGpvQjILfX9ptys3F9L1vq8WIsnQ/X4e6EPgO2yFPq8B2+wT4J5MgK3tQH0GjVzUmoocXnCiKif0RII/f8azGxJvklCQtxxEIl2xCJfH/Iu+y5dhQ9E1xcRsvutQORMh/bC/e7BpSinHvTH54mCX4AIbQ3YRkJvYSO7xZsPFLElNFjQSr5vznZzWsKklWSPH9qGpg/wW1fvns1q2YNNi2taeTRntzEwLtE5hPJLE/VEm34stdUe2W+y+4LM8SuRxy8zQD/cWoghGcYANHn4Ku4Ybd0E7k8aP3PaCrrSZIk+GVIEcS7FX+WPPeP3DnoWRDVPgaClyaGKL0XvRoHYDkUHMlXCQkJm1HQwblF3uGp939+pbxxFx6TDRYrAb7l8K58SNnX/OwWb31LmPtQGImoRlPRw5t7tqDWGprN2V90B6p4RJVrxHPuzULKVrZwMhbZJxoOIZuTLkYAjQrXZHYsv24bfYnEEQ5ZjAu7+hvjQ5rf+V3ZgQMy9RVm70bUBd/MPdjznyn+IEVS2si0FM1QtwiXBtC4lpjMfZiO5c4SjTF5LY2tRE7nrYO2x/xz6PgXxRLNfgmHGHKFIfPweJaAiNeqamuwuKo7E2m34tFNrjpHHhYByG10OM+Jw6ruG0fR45ECmz4T+4W77nbBhWxv0o2OnavPLWpSA/RFI2b+PmaxY5HUHl1s4zttu1qynWiAhdFr0zd5cnzfn4fOkcG4e7fL7NWoyh7dlo233wA2Xtpa6ltSr/D5VeLRzWCW8GZVmZIGAOI/Ke3u+1++lq8FfEvIy4e6ss+Q6/3Un3MfjsbYEIW8B5UinQae+R1HIY2/Rh4/pUm3sbGjMKSEpJpyexrueb9cQ6etqsLj/wjNGhAy1FlKlahmafSyX4e5alSWFGyG5rui1SS2m5YhHj0mJTayBRW6/bTnLmiIGYF1w/zbAubUKPhiR3HMnbvFi7ZE2iB2IHWye+WMvc65E5bTuK/kTrn3b6CTJbHhRRU81E0HacpkcOPtZrprKdtKnhHsWd9ShIm3+hXVs X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 88cb1e27-229b-4cc7-01dd-08dd2e72ebdf X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 16:55:27.6119 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eHS5XiGVcKiTcYLOQ9lOclptGe2xgJOHMFq4iy11H9ikwkX/7Wls+Rs6EMyXd0jn X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6634 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1A67740013 X-Stat-Signature: x8ehms641m3i4czsuxbcxqunur7z3szm X-Rspam-User: X-HE-Tag: 1736182647-28494 X-HE-Meta: U2FsdGVkX1+yaP1jpKrleu8B9TJHf48oWWMGbXqjJSokk2pgMdVzsRbzFyECWw8IqKUPHX3u5dRjPXrojztgt7qucQAjgvCdm4372y+g+CUQh4V/+T8Wt8ktrYA2rbn7f0q+BkKRrn7vYJqku8wQdUObPmH04+HuuJD7QGZHHg8yFtQAxPUETzxDmhumCR3bU3paoBI2IFXRPnlUU0727wo0zjPCRNetl94CGgbumDA2LUVEADNAxmKafEHSSvDkDIiiTtEmTFZ6HAEnmeBoxr7XWGSmpXgWzamywlZhgShpXhnAv7g2H5ldxs5Z3v1tr8LQNz3MVdnZWPzAcGjp9fNkMmU6DKraaBIN+kb4oECp19Q5nww45lRa0uecieIOVUIwJ8XglOIVyQ86c7w4/Fc4st4kUF7oVF97yC2XvvIj56PzqJjyvEqKs25815k0wJ41+17JQzMs9SZ1lIims2wBNjOcgD94FhAKvsj9AqQitvRl/pFfbt/K6MFc0HAZOClG8WQjAFitk8lS37s3KsM8m8AcnYkGNvaPlC7y3gq66oRrXB3qyKLRDa1mhcesLLs4QkuS0zdcjEZu4G4psrhMJIKBSDI4ADI9YRyk/Av2CDFQXE9u6Vm2Oc5g1gjMJDWVzzeH2k/N74uClSZ5vODOhkFobWsPHLFbMh2y1znNjMZR5jakHNCN9h5Fnx7VecldP1MTgv4/kgJGvrqW0BXvEgq2hsrK+b0LPl/BLr3uQ5EVyU6GAIyDL4s58ujHCEYrCSFrAEhhjDSj5T3DBM8WAHlq2GJKibMGiskbb450N0Bejf3v7lysgKW2bsUotlprSFmwIeRVlziHhFAkB9lzH8Ll/ZxE9Stg9ovC+8d54V/h4uKAxN9dKym3Nloblkty10ROowPbpJrnoIvvxNooNZdtBjMgz7EuG4NC6ytA1nBpiIxDhAAAIpTi9hopq61v1LF2PjbGwSYKB6y ihL1/1C2 WSgIGVdmON9NR3DWVJ8Su18ebYFiBWf+UlnMGwQkPR6/4BjIyxOq0bIuPA7hgM3aIc8KkvD9qPOSBg2VX+lBZTctZA/Lpy4Us67W/OuW12Rk9sfqKHulCgJ6WWEntYFazJHIFI+pEoqokDtrW5PsiWs+gfiLpNXafPcpJu4xAojxu+UtWlXdmFVQKxnsiucKcExx/xQCOQc7BLkOv3s2jCtNLJcklYGNGPMYLMVe5n8TUsXccYjTwWg6gmp9PlElJGuPCyqK/o/PZcaR448zYoVg9nmV/RkPPGB3PKlOHufLTD6Aty3eTzw6qfPei9rRAUzMBUbBzBDb9vC1Ppk04mgtaTH3uifr7UokjID4hi9aNp8GAfyzDha8XAz9RlEVAO6y35oEE3ol0Opw= 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: This is a preparation patch for folio_split(). In the upcoming patch folio_split() will share folio unmapping and remapping code with split_huge_page_to_list_to_order(), so move the code to a common function __folio_split() first. Signed-off-by: Zi Yan --- mm/huge_memory.c | 107 +++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d8e743f81e76..586870e60003 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3724,57 +3724,9 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, return ret; } -/* - * This function splits a large folio into smaller folios of order @new_order. - * @page can point to any page of the large folio to split. The split operation - * does not change the position of @page. - * - * Prerequisites: - * - * 1) The caller must hold a reference on the @page's owning folio, also known - * as the large folio. - * - * 2) The large folio must be locked. - * - * 3) The folio must not be pinned. Any unexpected folio references, including - * GUP pins, will result in the folio not getting split; instead, the caller - * will receive an -EAGAIN. - * - * 4) @new_order > 1, usually. Splitting to order-1 anonymous folios is not - * supported for non-file-backed folios, because folio->_deferred_list, which - * is used by partially mapped folios, is stored in subpage 2, but an order-1 - * folio only has subpages 0 and 1. File-backed order-1 folios are supported, - * since they do not use _deferred_list. - * - * After splitting, the caller's folio reference will be transferred to @page, - * resulting in a raised refcount of @page after this call. The other pages may - * be freed if they are not mapped. - * - * If @list is null, tail pages will be added to LRU list, otherwise, to @list. - * - * Pages in @new_order will inherit the mapping, flags, and so on from the - * huge page. - * - * Returns 0 if the huge page was split successfully. - * - * Returns -EAGAIN if the folio has unexpected reference (e.g., GUP) or if - * the folio was concurrently removed from the page cache. - * - * Returns -EBUSY when trying to split the huge zeropage, if the folio is - * under writeback, if fs-specific folio metadata cannot currently be - * released, or if some unexpected race happened (e.g., anon VMA disappeared, - * truncation). - * - * Callers should ensure that the order respects the address space mapping - * min-order if one is set for non-anonymous folios. - * - * Returns -EINVAL when trying to split to an order that is incompatible - * with the folio. Splitting to order 0 is compatible with all folios. - */ -int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, - unsigned int new_order) +static int __folio_split(struct folio *folio, unsigned int new_order, + struct page *page, struct list_head *list) { - struct folio *folio = page_folio(page); struct deferred_split *ds_queue = get_deferred_split_queue(folio); /* reset xarray order to new order after split */ XA_STATE_ORDER(xas, &folio->mapping->i_pages, folio->index, new_order); @@ -3984,6 +3936,61 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, return ret; } +/* + * This function splits a large folio into smaller folios of order @new_order. + * @page can point to any page of the large folio to split. The split operation + * does not change the position of @page. + * + * Prerequisites: + * + * 1) The caller must hold a reference on the @page's owning folio, also known + * as the large folio. + * + * 2) The large folio must be locked. + * + * 3) The folio must not be pinned. Any unexpected folio references, including + * GUP pins, will result in the folio not getting split; instead, the caller + * will receive an -EAGAIN. + * + * 4) @new_order > 1, usually. Splitting to order-1 anonymous folios is not + * supported for non-file-backed folios, because folio->_deferred_list, which + * is used by partially mapped folios, is stored in subpage 2, but an order-1 + * folio only has subpages 0 and 1. File-backed order-1 folios are supported, + * since they do not use _deferred_list. + * + * After splitting, the caller's folio reference will be transferred to @page, + * resulting in a raised refcount of @page after this call. The other pages may + * be freed if they are not mapped. + * + * If @list is null, tail pages will be added to LRU list, otherwise, to @list. + * + * Pages in @new_order will inherit the mapping, flags, and so on from the + * huge page. + * + * Returns 0 if the huge page was split successfully. + * + * Returns -EAGAIN if the folio has unexpected reference (e.g., GUP) or if + * the folio was concurrently removed from the page cache. + * + * Returns -EBUSY when trying to split the huge zeropage, if the folio is + * under writeback, if fs-specific folio metadata cannot currently be + * released, or if some unexpected race happened (e.g., anon VMA disappeared, + * truncation). + * + * Callers should ensure that the order respects the address space mapping + * min-order if one is set for non-anonymous folios. + * + * Returns -EINVAL when trying to split to an order that is incompatible + * with the folio. Splitting to order 0 is compatible with all folios. + */ +int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, + unsigned int new_order) +{ + struct folio *folio = page_folio(page); + + return __folio_split(folio, new_order, page, list); +} + int min_order_for_split(struct folio *folio) { if (folio_test_anon(folio)) From patchwork Mon Jan 6 16:55:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13927681 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 A95A9E77188 for ; Mon, 6 Jan 2025 16:55:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 406AF6B0096; Mon, 6 Jan 2025 11:55:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B65B6B0098; Mon, 6 Jan 2025 11:55:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 230586B0099; Mon, 6 Jan 2025 11:55:59 -0500 (EST) 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 0494E6B0096 for ; Mon, 6 Jan 2025 11:55:58 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5A69F80128 for ; Mon, 6 Jan 2025 16:55:58 +0000 (UTC) X-FDA: 82977629196.10.57C1ECB Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2053.outbound.protection.outlook.com [40.107.223.53]) by imf08.hostedemail.com (Postfix) with ESMTP id 549D8160021 for ; Mon, 6 Jan 2025 16:55:54 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=cdmTojl8; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf08.hostedemail.com: domain of ziy@nvidia.com designates 40.107.223.53 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736182554; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pxyeeMVuxeaK62VlUKF1S6q9qijzmSMRqC58MRDJ0Bc=; b=3evtWuKFu3T8RZNnvBwzr41Q6fxByfMgNaOFFAK/x6MHaJ+YX8+fMJyG45LSLzEJTweaq1 ZzBxOsxuGCWNNRNjh3/Rk6NbtoAHvfwRbo3Cc8+BNNwvYBIPglaoHXhO+K9vr+fbCb0KYs i1pQvnbGUgbF4lH7RAsjOav8NuUEPOg= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736182554; a=rsa-sha256; cv=pass; b=C1+oTcIJ2rQhD0amxp+IOA3wwowCrhBL0r0kt1VZdTR8pk5jDYNgT+pNDds34UXW8Wiiku aRt9/OVf2aG4dZZgjSYFWLDMXfduyJooBMQU5NNj/D9rIaYxGUXL+DeMsoyzwGcObruIOB ENI7dBjjSlbSDuHjA5Rq0uTxTJybclw= ARC-Authentication-Results: i=2; imf08.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=cdmTojl8; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf08.hostedemail.com: domain of ziy@nvidia.com designates 40.107.223.53 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=symVzF6MvTRzVyVwGTiTh1jU6P6u3S6YZZrW80eZEwPSHNt4r9MJcwuEpV+QxL88i7FCt4REk6eOTf2/X9+J/ZOlp8gjdFGDxYNEMafSBrzGNNHiAeq45kw3kF1imSfH43v7WZSSv7uCCud4bwo80LCvz2Z3OIwwEMh+W7Ec0dYwSl7Ldo56NBYyy1Rp+AQ2Bv9zB3wjD6wPyi/cG3T1E8xEncQ07ACkIMqCCKuZl9x+zlDSnS9Wn/ICYrHEEbwmnS/xSCH2eXVUZoq2Ah9e8w//UObIXHQLGRo9HpaUSHbA0nHB73hcSpBsCIk8hOW9obwACp8Qsw49TQCvB92Q5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pxyeeMVuxeaK62VlUKF1S6q9qijzmSMRqC58MRDJ0Bc=; b=HioV8nOOtwHagZQ6sgrZ8RkYS6F6mmWmnASBnZg4bBHEqH4hzRyZA/8igxFm6VhiwpNUzMDuR2ZDDBcg0SwaQfdmrOzjlVyq1i8XfFl1aDdILOA8ArA25razbj8bx7+S0++3LUNi53hPRAMLUL2RUwbdaID2/rwjJRLTs1HhNcSjmDpMTj9GEZqHfEGMEF7Ws5imCZdku/7mNAaxOXEy5veXnfD6vqZpK9ypcxgLZx4RDmQ/D2Fe41s1jKSbYBRmlZwgXk48R/wLKspQvCed4LsqR6qklkKLBkiPvzTap23DI+RAY8JVHRzo93Jm7y97n78DpCjd5GgYDqL7+KSErw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pxyeeMVuxeaK62VlUKF1S6q9qijzmSMRqC58MRDJ0Bc=; b=cdmTojl8D/HTf7ush50rYQnmXtUAMVsvkHKXgKV/mgSSm+f1jRJPdi052HdZwXDxdyYeMySFrDWvLj+Lbpt/HR/raMCZGgauGt9KWEpV0SN4COsbKFV2kcwOt6JfY6hcyfFO/mUizNxEmDBZK/XcXYJ8TkpwyjBokskBnZwlq2UTOKDn0icvFmDvuRlEnKtFR+ip0PqUHVMv27ASdu8QQ5q+r5siKpH8cBICNZXFb6hpdJHyrse2Rtl8o9Gb1BtVVu2WAKaOlZoQ8k9KoEeUC4hqt/XBUeRguJV61U0Ui/YPlzRJ7mv9Nob63/oeS0Xhr60wVf2cLSqsvt3+CBu7JA== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by PH7PR12MB6634.namprd12.prod.outlook.com (2603:10b6:510:211::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Mon, 6 Jan 2025 16:55:28 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8314.018; Mon, 6 Jan 2025 16:55:28 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v4 06/10] mm/huge_memory: add buddy allocator like folio_split() Date: Mon, 6 Jan 2025 11:55:09 -0500 Message-ID: <20250106165513.104899-7-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106165513.104899-1-ziy@nvidia.com> References: <20250106165513.104899-1-ziy@nvidia.com> X-ClientProxiedBy: MN2PR08CA0023.namprd08.prod.outlook.com (2603:10b6:208:239::28) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|PH7PR12MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: ac137967-caca-4d11-74a5-08dd2e72ec98 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: jDkEPpy7SFhqE7F0bhe7Bfd8kGnas5NVII5Zn231WEHQDLjTOcKKmkqehsr/tKRIbjsL2Y9KoTM/RtMBsBhqr0w5Tho85iU/YoaD2wIjfk+zd/bUxqt5ufQcmrJavLqznKKuHy1fx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9Gaxggi63aasVQqv9L/0IaLLMxbxRQUrVt7LhhGqQXDRNRbtjI0v6gHGxdjcGE3/yTfKA7zpeHUaHyXEKIGib3pdWGDfWHTIr9Ik2poQ81cb1dtD3W6EaQOaZN9bFl2fY9CHfPCU33eYnUiOuj1ZRlWNJBVCJ1yLIXoofI7eLBRK6nmOJAp50 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EOIK+xFreTBiN/nDbwjIipOLlc9fiRXW3oFfaCJ7qw7JjYKhauJ0RVO8QlKw8MOxf/+VzBxfhpAIBvubk094IWnthhRlDibdfGSY2L7CdduwcD+XBkjfDyvgIB6/fuTKqkpZ37Ushh9wj3IkB3cSgNeuITfkVmsTfL71JSYjc8rCh0IL3Maww9ZEVaQNHeW6z9wAOccheN67/jRDcEGrJI5tL8KfJBKyhDlKuRBF2XxKuDIJj1HagH/t4I/nnWpuV0U7zrRGSj4BR2ApA6WtjZZrozQmAzn6pliGLGmZfsZPQVWqQ+5vXdwWCvoiRsBGK3cg4NZKEeihaknOWNRxDUfSOCgdL641crxMQTsoFFli6ljIUvb1zPP640FzzH1FZHNDHtwjGR3A5amcpGH54YnMi308aT4jVswmXQHdKxSUW2nRKVAJH+1ow7B0yZk57E9W2AFNXGImnDlAUCA61X2IS0ju+O3u2hPAeXIlkNN4G34R1PkJ/SkTPDi/VSKaopNvZYa3fc6vls72FbRjFYdvuw797MUjkwhQ8r9W1Eamut018Io8OAcTTPXAL1W2a4HqYMHQIwLJacRXUNqxovdSjIC+FpEUQLLGmar+tAu/K0CAy5ez5omHpzZpycCI/CT7KIJe3OWJlbZvqzSg3iaT2jYUgrZO7fiYOmr7bI9V2nMLVd2/27MGRLSc9eyY5f1gORLbMiuYJqPPs66ZzD67MTu80GLUxbiXrhbJaR0WLG8HLdOqFqhsSDkV61LKnsuKJss0Tv6aUUJZ5H7EitYQvnCEMHfWaJ/spK1cGmMJMdN5+sIKVyNwtueBjZqYBSBDr5VIDyZ/HciVXRbL4oVBsCiyZedaiYTpEBUBQ6MIUtxwRqQguXQofAJYTXZL5i2cJe9y4MbJvyC4SE+Wt3M5iCGXwQVoFRTrJpCEpfBW3iBHjBQFKbFC9uK1lPqpX95dj1Ll0HyD3jOUtbx8LlBPwAEwuevS8ARTbyTqMkiCYew503iq3vECOpwcnSU2WvEayEs7Ah5ulsHfgyi3A2T2GoAfXN1SW9pIbCNAxI9VLJIp8nI+PUflVDsmAgYIty+YkIfz7YMXbVmcrd4ZlFF7bBGbojpa+WOM+z2/eAgcEolmWz91BD7xbdHz6DxB9pA0hMPEAMCGTQ412b4inFS/avThn/D+HW2QHUFhE4A8vMBBkEG5l13UyI0cqFGtorOJSMjAGYcODAAHBotiBdTBFWC2TozM+ZeCqAmExYUhaoyd/r2cV8tM72l1s8AuGsrY7wRgD6efpetBpHsy9rJdx9Rt38ISe4gdGZtMnBJyRW/lVoTWY9DNd8yTSMzbtqLGeilkEJTPzZVGlykvU2PMirr8f1fY1ovXO4YGeubt58KSc7b18SLI9qtgFT4FY6QR2zdKZ/qY8hy8xL3QcbPTmQFDz2P0HFQ3Oyj7blTF6MPQQofkDmyHHC7+k31uiUYCmHVlX0UcpK8aeOIVYYrWZyDXVdAgRxZmbzFrdWHOWYZvIbDAGopCRtoonewC64xfTEnRBr6T9Lk7bBuQtHHXIi8ZcoaWooxA/7ViNKAhFo7e92lNIxzJQs1j/4SA X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac137967-caca-4d11-74a5-08dd2e72ec98 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 16:55:28.8328 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ICOzl3PPXsR8+AsCjFXoRe0oS188z61sUlHigfmTcPhWncvLmDbVk6xPfFs+PpLh X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6634 X-Rspamd-Queue-Id: 549D8160021 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: mie5c3xie1cq967cy7nh744z1nxpa6og X-HE-Tag: 1736182554-124194 X-HE-Meta: U2FsdGVkX1/DORtjM2Ot5kz2jXa4tbLT4hdzxsAZu3JWuHMhNX0rDc2yAbv/C+80WDwHOmie7RnJsdFhVn3UrHSa5m8qL9rz/CBohHH6l1FCXfToaNsk/ZFTWO0xoIoKiZFEqyifLRJdh3Vhu7GnQQ+FmJ0mwE9ZTRhlj0N21eh4hrqb4DWMqxDqwriI3HWckPFDXAjzFrzXLOzRMGlugRgesKuDJipLe6xBN6ryfIof/xMSb7As/JJCoPNjfrf4rDz7l2IZgSmQ7ruxqEnSXIFDOakj8p2v4PP1hKcpXNooyK125JTkkhUd9Fupr9UmpfOf6zXWUTdPTPxdg8E/6O9PwfBlUs+ltSfBYkS8EauomhVv7UTkagY5mdTSY271M/oZWkCsgIY9aJlMIONEV/ckE5+Ckzq32/gCDa436VUtpDnc5/8JJ4hOjVeEFUrX2ARfleKHWj1IXR4Ve+zkOYStbsCT/TvyjYPHOdFl5O+nlOCzXGq0Ofh/kezXXBFYYBBkANrqMS5AohVIpIu9M7P1BV0gTouYv5uZmSOyp1/puoBid7g0IR1/jJXEwpfhXMxNpUPbHqrje9MkROPOQpc1a8Fv9UTLzzEx4RfncN8U7O9cxD+G25rS1lIMcdcX9mFMOV/3OW0NkxaixQuJz1Jn0+FC9CrEpbaceDBY+Q7bt/57nAG6cM1lMJsZuq0qlaEpyJOYNGjpJh8gDIQ8iL8D0pyNPfmvLzPKSBpTMpBeardWGsz7tCArgAyJnd4mrPeBIfPbpOEqJ5mU7UWD8ODduLMYuTWudOD+OfGwaAO+LGijkCgVcewSf3ERi4hgwj4ykntHnEAGBlR5xAp/Nj6wedmbDAfbiES4Wfgl6Ceb1YoS1MOhtW1LKuL8LsupmDutBTKP8ijNLQYvJ90DC3ywLLW8XonVvMvG5Av+yBmg3gRR3WCDnOBbAuMJo2wVAUQk9UfTMVduvVj5vbu bTbVcFKj gLaQaJ1glsRfOuLUpt4Ts1yf1rVuY6wls489w102ZeJxArKn9ACQj+PNUm74xbOvsPNFL2jfOO5kvWqx4OQV+fPVPPxVX7Rf9U4C6piTtiqjFgc6XqYJfGsAs7EIGf1TKCIjzPi1HaGTCnw4zQNZn1TSXfKw7KsgW/hBkUiJczijclY4wjFi5s3jxgBhn7HGDX0iNcuIfCgCNkCF5BuJUZF98yXCTYWzdtIcb7gDUJNuoGown2R7YNy7f8ku/J54rrc9T8RAkTbZlvLIl3KQu4nKrxn2MhsmnKPPI62UIYwHzU4NdKzZBLzoOl+Niz1tRiW6jzyZi0bJLngsKnK20GxpOV7I3Am1aRyxORzHdgcGdzpbFBYbnn7Rynk3SSuyMrARv9QQrRfhl62o= 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: folio_split() splits a large folio in the same way as buddy allocator splits a large free page for allocation. The purpose is to minimize the number of folios after the split. For example, if user wants to free the 3rd subpage in a order-9 folio, folio_split() will split the order-9 folio as: O-0, O-0, O-0, O-0, O-2, O-3, O-4, O-5, O-6, O-7, O-8 if it is anon O-1, O-0, O-0, O-2, O-3, O-4, O-5, O-6, O-7, O-9 if it is pagecache Since anon folio does not support order-1 yet. It generates fewer folios than existing page split approach, which splits the order-9 to 512 order-0 folios. folio_split() and existing split_huge_page_to_list_to_order() share the folio unmapping and remapping code in __folio_split() and the common backend split code in __split_unmapped_folio() using uniform_split variable to distinguish their operations. Signed-off-by: Zi Yan --- mm/huge_memory.c | 58 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 586870e60003..e5f70ff88a1a 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3725,11 +3725,10 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, } static int __folio_split(struct folio *folio, unsigned int new_order, - struct page *page, struct list_head *list) + struct page *page, struct list_head *list, bool uniform_split) { struct deferred_split *ds_queue = get_deferred_split_queue(folio); - /* reset xarray order to new order after split */ - XA_STATE_ORDER(xas, &folio->mapping->i_pages, folio->index, new_order); + XA_STATE(xas, &folio->mapping->i_pages, folio->index); bool is_anon = folio_test_anon(folio); struct address_space *mapping = NULL; struct anon_vma *anon_vma = NULL; @@ -3750,14 +3749,15 @@ static int __folio_split(struct folio *folio, unsigned int new_order, VM_WARN_ONCE(1, "Cannot split to order-1 folio"); return -EINVAL; } - } else if (new_order) { + } else { /* * No split if the file system does not support large folio. * Note that we might still have THPs in such mappings due to * CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping * does not actually support large folios properly. */ - if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && + if ((!uniform_split || new_order) && + IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !mapping_large_folio_support(folio->mapping)) { VM_WARN_ONCE(1, "Cannot split file folio to non-0 order"); @@ -3766,7 +3766,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order, } /* Only swapping a whole PMD-mapped folio is supported */ - if (folio_test_swapcache(folio) && new_order) + if (folio_test_swapcache(folio) && (!uniform_split || new_order)) return -EINVAL; is_hzp = is_huge_zero_folio(folio); @@ -3823,10 +3823,13 @@ static int __folio_split(struct folio *folio, unsigned int new_order, goto out; } - xas_split_alloc(&xas, folio, folio_order(folio), gfp); - if (xas_error(&xas)) { - ret = xas_error(&xas); - goto out; + if (uniform_split) { + xas_set_order(&xas, folio->index, new_order); + xas_split_alloc(&xas, folio, folio_order(folio), gfp); + if (xas_error(&xas)) { + ret = xas_error(&xas); + goto out; + } } anon_vma = NULL; @@ -3891,7 +3894,6 @@ static int __folio_split(struct folio *folio, unsigned int new_order, if (mapping) { int nr = folio_nr_pages(folio); - xas_split(&xas, folio, folio_order(folio)); if (folio_test_pmd_mappable(folio) && new_order < HPAGE_PMD_ORDER) { if (folio_test_swapbacked(folio)) { @@ -3905,12 +3907,8 @@ static int __folio_split(struct folio *folio, unsigned int new_order, } } - if (is_anon) { - mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1); - mod_mthp_stat(new_order, MTHP_STAT_NR_ANON, 1 << (order - new_order)); - } - __split_huge_page(page, list, end, new_order); - ret = 0; + ret = __split_unmapped_folio(page_folio(page), new_order, + page, list, end, &xas, mapping, uniform_split); } else { spin_unlock(&ds_queue->split_queue_lock); fail: @@ -3988,7 +3986,31 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, { struct folio *folio = page_folio(page); - return __folio_split(folio, new_order, page, list); + return __folio_split(folio, new_order, page, list, true); +} + +/* + * folio_split: split a folio at offset_in_new_order to a new_order folio + * @folio: folio to split + * @new_order: the order of the new folio + * @page: a page within the new folio + * + * return: 0: successful, <0 failed (if -ENOMEM is returned, @folio might be + * split but not to @new_order, the caller needs to check) + * + * Split a folio at offset_in_new_order to a new_order folio, leave the + * remaining subpages of the original folio as large as possible. For example, + * split an order-9 folio at its third order-3 subpages to an order-3 folio. + * There are 2^6=64 order-3 subpages in an order-9 folio and the result will be + * a set of folios with different order and the new folio is in bracket: + * [order-4, {order-3}, order-3, order-5, order-6, order-7, order-8]. + * + * After split, folio is left locked for caller. + */ +int folio_split(struct folio *folio, unsigned int new_order, + struct page *page, struct list_head *list) +{ + return __folio_split(folio, new_order, page, list, false); } int min_order_for_split(struct folio *folio) From patchwork Mon Jan 6 16:55:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13927684 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 D196EE77198 for ; Mon, 6 Jan 2025 16:56:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6516A6B009D; Mon, 6 Jan 2025 11:56:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 600296B009E; Mon, 6 Jan 2025 11:56:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42C966B009F; Mon, 6 Jan 2025 11:56:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DD3006B009D for ; Mon, 6 Jan 2025 11:56:17 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6A5A916010F for ; Mon, 6 Jan 2025 16:56:17 +0000 (UTC) X-FDA: 82977629994.18.E92FF08 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2077.outbound.protection.outlook.com [40.107.236.77]) by imf29.hostedemail.com (Postfix) with ESMTP id 83748120006 for ; Mon, 6 Jan 2025 16:56:14 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=B9uy7mxT; spf=pass (imf29.hostedemail.com: domain of ziy@nvidia.com designates 40.107.236.77 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736182574; a=rsa-sha256; cv=pass; b=bPEMSC2P5SJCqVxI9y7wO3mJx+A9pO6bX/P4DHhxtkxtqvezFkiPDzqr3qWkUOVZtBOHzu lTyQ47I7iOW/81q5Z93OmBSbeZVncjjYvEqQ71aChJb92o2jUKI2870NRpQED8DI1WsKGw iO2zvGHw+lyrsKLCloya+BsNGAMcuzI= ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=B9uy7mxT; spf=pass (imf29.hostedemail.com: domain of ziy@nvidia.com designates 40.107.236.77 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736182574; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gpE6Cvj8Jcb1HWC151x52uK5cybchd3jkxrLMwW6R08=; b=pHYOrGerPUPsR8g7DjmJWM78N6//GOBq/u7VSmpkNwxEIO2y4H5IYwihX/EPadynJpmnYV wu8gQqO7Jp/upt5LFNBg3R3qJzfp6IjAX7UMfY+QN5H5oZ8c3JHyeNNh3iasOYq2g1dnK0 du/ErUJF2wusZBjJ9twkouz6j0vhV2M= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xwb28ox0KNWiIoZ2DzLKAGdxxO4h3D+eFuVnUOrWKqeNg9jJXV9JXsTe28p6Nx55JDzl8Ih/7K5+7uU8TXYYJVFDQE3DY0OipZkfT3mjZuTdzLqCKd5PoYc5Yon16G7QB0MRrd21/UtBLhnJXEpbwtsjle4uHDSJ8oubwXcu99jn/K/XH4U+M1MIvbwkra1vdGQ+jMkWgdOEoWRuifh/tqEqaxDItDiWeZ2dsdMIlucoVqhzGUVrDP8bFNUUMLcvVZV4U6Kh/FarVxcxLizN5X7Wtzn2rLIe/GMMbjnwrsmoZIBp5Iczy773SrPv/SH1K/CSo5XDC37eEKjvwkeokA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gpE6Cvj8Jcb1HWC151x52uK5cybchd3jkxrLMwW6R08=; b=BEV2LES6F+mhYmjzOtvy/IxP6EfQDQB+5K51Pz9+g+ZqUGQUE7dpg2tUTEFybH5pHECsuAE0/oWwgpvRScQJGHvdWV+uOoi7AwdJw3ZuJlHlV+scwjsZiBV7GTchXsUC6IPJg4El2zns+rZEuMcqr9zxk/lOS0els+IRznaM2Tv6cXdWknC5IP49loxFZtaSZLo/+IAfI+nNN7l3fgj80Ia6WY8BXEJ6z0/UWtLJHXr0xNsAIAE8VR1YrEmP2o5s/+OcEuuY/PljXHDp2S6ehVGtjgWBSobCOwzrRKd1qkXYQ2Cc0Cc7y5RDBDDat4Uk85Zud3lhYgHYKukAa0lYpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gpE6Cvj8Jcb1HWC151x52uK5cybchd3jkxrLMwW6R08=; b=B9uy7mxTuk50MIFI4y3EANTB12Vv3t/1utVy2TZtV1vTdM+osUlJuFA4wc6EbR0EI/vfE8fPScjtDSDoHQqHVIgbRZ84E2QNxu+9A1jvC8900xalsSXsSLlxXl1yCCvv6Pdh2e+6XFLcZXCfb2eXDiUy12MX9dtNEfTlBBOJVIPc3tjLrmdMpzGOISN3q8Jq+ALBe5blhyLhuqvNjPwoCC4rXPGLbKKdcpNvt292yN/IFdu1OEt70TEkkG7yOjp82SkqyiP0WimBApTLcdSQ50tXlVM7C6CVFgPseJtxZ2qC9GUva0nf6NPQeaC7UMiVhXql3NzTeX2eyx00bPyctA== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by PH7PR12MB6634.namprd12.prod.outlook.com (2603:10b6:510:211::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Mon, 6 Jan 2025 16:55:30 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8314.018; Mon, 6 Jan 2025 16:55:30 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v4 07/10] mm/huge_memory: remove the old, unused __split_huge_page() Date: Mon, 6 Jan 2025 11:55:10 -0500 Message-ID: <20250106165513.104899-8-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106165513.104899-1-ziy@nvidia.com> References: <20250106165513.104899-1-ziy@nvidia.com> X-ClientProxiedBy: MN2PR08CA0025.namprd08.prod.outlook.com (2603:10b6:208:239::30) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|PH7PR12MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: bf447af2-d373-478f-1c58-08dd2e72ed72 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: NG2GRtAhRQA8TT552CQNEs4mnZOIxKIPIiGApwwrCaOVGIsJRcn6ABEe17kmcytBYn+ZyiKCIHxgQnpvYxwtbk3FuTrqsGuNwK8fhXXXgtpDo2mMQqaH2tLSKUeI7+sbhRWxw1d+K+VCjvv+FAmRE+N+5kecy8p90eRUh6mfbAq4WoSHyzv2gB2zan8QCOUk6GRbqsMueIb10cDjssiEIqRP2CwvgXQeJrs2C5l9hTDy98asnSnCTJyedfKcKS2o17pE6pTuHq70UbAhj2F9MWF77uoEaAa9Y15FLEEdtqdU0GmTJ+vwyYA7O88Q+i43zlKOuE9PA+9/9Cct76SFbVGNHwABHNKOWqSTF9/joR6F3YkK5qxyyAVAJvAOsn5R2/0COuFvOL+W5YU5Ej455amAqrn3qLLBPce0s5/PEdIW+M3ZApvPpyfNJKi4JDtZKrfNnAYQtfgRNUooX6ayB5LUyT111ku1g7/XAdkciUfVNIKFrlX7ltS0rjZOjBdak8l8V7qSxqY+JdbczTzR3V2C2fcaNtVAB7EfMEa/NvUzHWyWCNPiITEDmqukDaQElOvMRPp4EUa5oplOdDS4S0SKX34G35YQsDMLk7XOYxLuoOuVr+wdWQNIhXvv7JP+7I6xEgghvREQscCAgCWPbu3pwKg22JvmDXxuTjI2OX0JIWEfYrIQMQNCWGvlc7RwNHISjoNkxQ0cqS97ZN8J/WxYvDKqJr03cMWAMvsnD0WxL7x3bZw0bbOLcwC19IooRpbJvYGFMC4iyyNe4WhytVXvqc9Yz/BtkQJtiM5KFDN2S3LgOa2pm5rJRzVgnhug3goU4q0W1SMnb0W2WwJi+vq4gy42aLJFIEAtwwUyZ2OQeEXUNh+2rECbtn4vJlRigj/h3L/9yy7p6OFHfpvpj9sk4Z8/PjsmTWmyX/gvuK5caZmQ2hy0vbrySOhQq02peIfStZk9ix8EjKA0EsKk/ybB+sPId0EqziU8nWJIJcS6gwANRxt61mjj/HkOvtmkscznEWpZk49pR2bot9Cgtu9azhrz4XxtjxCkksusRa5pNjcXHKhZHR0o1/tbCwqtm/u0lGkO+b8qe6SlhvwcIhEfuDroquZ8B/+vtBWfhk9yFm29WVL9Hm0I9bX7Jy79UFuwtN+NDfHk6d5dlIucbj97iG5Huu5fvBB7gPrFt7nm6tt8fWBVxN8OkoWyCClVA0j+sGZSXvNVxrS5Jr1z1fQYwO+kSF40MS6oAk+jwrzgX710UBM5oDvXiY+Dk6J+N6JwsBN5Trf+J7kn00hoounpODJYL/U45v08QALa5lrwWRjV8WWwlXsQT9FCFkAVI60p/l7n3nvx/Z8lNOEb0/ESWRsLDmQbT78GDFjCkw+1QXuGY60MlFcDV66yRCAC X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HsYWv9i12XBcFTiHK0FlBWXZ3NNNbQp4YsuCBTb8lwWPLK/bVC5Q2i4+kekYaZUiJosn6qPKi0wsHp9QP6YTlz0n2CUj/RMChoptX7DgpMvgJuAu+VhCC95OqhLA9ABBrOfrVkZRLfLkMRqB3IVgCewsNhI42pwcoxFTdtxWnYNudYuar5k/iDKmuAGeJMxUpD+VXdsgXkcvh5whU4EtdRivWVImaSWbiWSXLV+NaL5wYo9hsHx1CDK1Qo23t/xu+V9sZ1dVGPB5dkgJPdBfzSH4XiBNUsY2enzqd4cZ7oYLZUQ1PRVYCwok1IcKArkVldkdmbOzndeaxWCq/SgqcJYHfjZnAY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Owt1Dl2eQzU+KJAR7WJkirYJ7hfjH7F8parG3CssnmpQN/0O9FpBUBnpuFjskVJ4Y9ksUCVqN4iy18Bdy6mCeBg2o/sNE/ZnzgrD95Qg2+U5vrdGiRsgYGvmr4SrMbS1ARK7A/t1qtsZuzG0BblqekuxAEIeVoKfFe0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bf447af2-d373-478f-1c58-08dd2e72ed72 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 16:55:30.2529 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5kGKvaDurbkvQXN/sdLFAwQOPbwtMTPBlus0kdCZLxW2AQytfQ62RegWuhEOIhhS X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6634 X-Rspamd-Queue-Id: 83748120006 X-Stat-Signature: jm3ae4e73r1hwiw9d8jmi5hdfd4cwmm6 X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736182574-562934 X-HE-Meta: U2FsdGVkX1/xER/8QdJoXO71QEfrKEW+qClVdDex7kqqSqokvYkg4w4bm8r2QuN7oM1hbooCiJANpH8Yt4Fow3H+/qfrYb24BSVn9XGmI4YqHnMLXtR5+jaWY164CW3/TjKlqnRAm/7AhpkF9BLZQa5w2qhOs5M+i+/cl61AxwmDk6NtGdwidInRfL/wAl9avrZfKDahd9DVxQ5XLv+JrSBGyN6MzpV9A5C8UG/Ot1y7NELlwV2GPvYvWrxME+h6VT0Qch9LEt5fJNswWi/DmuGnvWttd2C+O3UhZNInbdWSEiUUl4Ggvf9Iqb99BJbQ9n7Ac2eTst0awydqYPL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amicity=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: Now split_huge_page_to_list_to_order() uses the new backend split code in __folio_split_without_mapping(), the old __split_huge_page() and __split_huge_page_tail() can be removed. Signed-off-by: Zi Yan --- mm/huge_memory.c | 207 ----------------------------------------------- 1 file changed, 207 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index e5f70ff88a1a..ec27287b7cbb 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3153,213 +3153,6 @@ static void lru_add_page_tail(struct folio *folio, struct page *tail, } } -static void __split_huge_page_tail(struct folio *folio, int tail, - struct lruvec *lruvec, struct list_head *list, - unsigned int new_order) -{ - struct page *head = &folio->page; - struct page *page_tail = head + tail; - /* - * Careful: new_folio is not a "real" folio before we cleared PageTail. - * Don't pass it around before clear_compound_head(). - */ - struct folio *new_folio = (struct folio *)page_tail; - - VM_BUG_ON_PAGE(atomic_read(&page_tail->_mapcount) != -1, page_tail); - - /* - * Clone page flags before unfreezing refcount. - * - * After successful get_page_unless_zero() might follow flags change, - * for example lock_page() which set PG_waiters. - * - * Note that for mapped sub-pages of an anonymous THP, - * PG_anon_exclusive has been cleared in unmap_folio() and is stored in - * the migration entry instead from where remap_page() will restore it. - * We can still have PG_anon_exclusive set on effectively unmapped and - * unreferenced sub-pages of an anonymous THP: we can simply drop - * PG_anon_exclusive (-> PG_mappedtodisk) for these here. - */ - page_tail->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; - page_tail->flags |= (head->flags & - ((1L << PG_referenced) | - (1L << PG_swapbacked) | - (1L << PG_swapcache) | - (1L << PG_mlocked) | - (1L << PG_uptodate) | - (1L << PG_active) | - (1L << PG_workingset) | - (1L << PG_locked) | - (1L << PG_unevictable) | -#ifdef CONFIG_ARCH_USES_PG_ARCH_2 - (1L << PG_arch_2) | -#endif -#ifdef CONFIG_ARCH_USES_PG_ARCH_3 - (1L << PG_arch_3) | -#endif - (1L << PG_dirty) | - LRU_GEN_MASK | LRU_REFS_MASK)); - - /* ->mapping in first and second tail page is replaced by other uses */ - VM_BUG_ON_PAGE(tail > 2 && page_tail->mapping != TAIL_MAPPING, - page_tail); - new_folio->mapping = folio->mapping; - new_folio->index = folio->index + tail; - - /* - * page->private should not be set in tail pages. Fix up and warn once - * if private is unexpectedly set. - */ - if (unlikely(page_tail->private)) { - VM_WARN_ON_ONCE_PAGE(true, page_tail); - page_tail->private = 0; - } - if (folio_test_swapcache(folio)) - new_folio->swap.val = folio->swap.val + tail; - - /* Page flags must be visible before we make the page non-compound. */ - smp_wmb(); - - /* - * Clear PageTail before unfreezing page refcount. - * - * After successful get_page_unless_zero() might follow put_page() - * which needs correct compound_head(). - */ - clear_compound_head(page_tail); - if (new_order) { - prep_compound_page(page_tail, new_order); - folio_set_large_rmappable(new_folio); - } - - /* Finally unfreeze refcount. Additional reference from page cache. */ - page_ref_unfreeze(page_tail, - 1 + ((!folio_test_anon(folio) || folio_test_swapcache(folio)) ? - folio_nr_pages(new_folio) : 0)); - - if (folio_test_young(folio)) - folio_set_young(new_folio); - if (folio_test_idle(folio)) - folio_set_idle(new_folio); - - folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio)); - - /* - * always add to the tail because some iterators expect new - * pages to show after the currently processed elements - e.g. - * migrate_pages - */ - lru_add_page_tail(folio, page_tail, lruvec, list); -} - -static void __split_huge_page(struct page *page, struct list_head *list, - pgoff_t end, unsigned int new_order) -{ - struct folio *folio = page_folio(page); - struct page *head = &folio->page; - struct lruvec *lruvec; - struct address_space *swap_cache = NULL; - unsigned long offset = 0; - int i, nr_dropped = 0; - unsigned int new_nr = 1 << new_order; - int order = folio_order(folio); - unsigned int nr = 1 << order; - - /* complete memcg works before add pages to LRU */ - split_page_memcg(head, order, new_order); - - if (folio_test_anon(folio) && folio_test_swapcache(folio)) { - offset = swap_cache_index(folio->swap); - swap_cache = swap_address_space(folio->swap); - xa_lock(&swap_cache->i_pages); - } - - /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ - lruvec = folio_lruvec_lock(folio); - - ClearPageHasHWPoisoned(head); - - for (i = nr - new_nr; i >= new_nr; i -= new_nr) { - struct folio *tail; - __split_huge_page_tail(folio, i, lruvec, list, new_order); - tail = page_folio(head + i); - /* Some pages can be beyond EOF: drop them from page cache */ - if (tail->index >= end) { - if (shmem_mapping(folio->mapping)) - nr_dropped += new_nr; - else if (folio_test_clear_dirty(tail)) - folio_account_cleaned(tail, - inode_to_wb(folio->mapping->host)); - __filemap_remove_folio(tail, NULL); - folio_put(tail); - } else if (!folio_test_anon(folio)) { - __xa_store(&folio->mapping->i_pages, tail->index, - tail, 0); - } else if (swap_cache) { - __xa_store(&swap_cache->i_pages, offset + i, - tail, 0); - } - } - - if (!new_order) - ClearPageCompound(head); - else { - struct folio *new_folio = (struct folio *)head; - - folio_set_order(new_folio, new_order); - } - unlock_page_lruvec(lruvec); - /* Caller disabled irqs, so they are still disabled here */ - - split_page_owner(head, order, new_order); - pgalloc_tag_split(folio, order, new_order); - - /* See comment in __split_huge_page_tail() */ - if (folio_test_anon(folio)) { - /* Additional pin to swap cache */ - if (folio_test_swapcache(folio)) { - folio_ref_add(folio, 1 + new_nr); - xa_unlock(&swap_cache->i_pages); - } else { - folio_ref_inc(folio); - } - } else { - /* Additional pin to page cache */ - folio_ref_add(folio, 1 + new_nr); - xa_unlock(&folio->mapping->i_pages); - } - local_irq_enable(); - - if (nr_dropped) - shmem_uncharge(folio->mapping->host, nr_dropped); - remap_page(folio, nr, PageAnon(head) ? RMP_USE_SHARED_ZEROPAGE : 0); - - /* - * set page to its compound_head when split to non order-0 pages, so - * we can skip unlocking it below, since PG_locked is transferred to - * the compound_head of the page and the caller will unlock it. - */ - if (new_order) - page = compound_head(page); - - for (i = 0; i < nr; i += new_nr) { - struct page *subpage = head + i; - struct folio *new_folio = page_folio(subpage); - if (subpage == page) - continue; - folio_unlock(new_folio); - - /* - * Subpages may be freed if there wasn't any mapping - * like if add_to_swap() is running on a lru page that - * had its mapping zapped. And freeing these pages - * requires taking the lru_lock so we do the put_page - * of the tail pages after the split is complete. - */ - free_page_and_swap_cache(subpage); - } -} - /* Racy check whether the huge page can be split */ bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins) { From patchwork Mon Jan 6 16:55:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13927686 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 6F317E77188 for ; Mon, 6 Jan 2025 16:57:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0AB3B6B0083; Mon, 6 Jan 2025 11:57:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 05C4A6B009A; Mon, 6 Jan 2025 11:57:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF1456B00A0; Mon, 6 Jan 2025 11:57:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BC1786B0083 for ; Mon, 6 Jan 2025 11:57:44 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7F8EF40DC8 for ; Mon, 6 Jan 2025 16:57:44 +0000 (UTC) X-FDA: 82977633648.26.8B375AC Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2052.outbound.protection.outlook.com [40.107.95.52]) by imf05.hostedemail.com (Postfix) with ESMTP id B4E42100006 for ; Mon, 6 Jan 2025 16:57:41 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=MvlTcKML; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf05.hostedemail.com: domain of ziy@nvidia.com designates 40.107.95.52 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736182661; a=rsa-sha256; cv=pass; b=5IGU72OW++rCPPaQ5vv4gbDs4pGLHrj7xfG5GymfWbJ+aNuACAXxdgBqggO0rm+GkaGEB7 tp4VRL6OsecLLr7nccUnFAz10Xuxf0buCWX6umveaBVlNCxmVobgUfNPi/IOSzS24OEM5m MSZh78/Y2xWU9Blo03kdi9A5UYAJxgE= ARC-Authentication-Results: i=2; imf05.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=MvlTcKML; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf05.hostedemail.com: domain of ziy@nvidia.com designates 40.107.95.52 as permitted sender) smtp.mailfrom=ziy@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736182661; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8aaxMyT9ASTV30k4qhW4SCI939ummtaihJVCjY+zCFo=; b=XuDJ3f3x3qfcBv4nelTQOinZVSVV5uD8fS51R6aAW8H5W3nxlBqCPUCoElPntV+4bjwjNz hZdNWkdUAGU/VDP6RrTPtszvP6bfCs9QkXahZq1AVYsrlma1XdVRcvErjTsVcM0/el/0Km chV1UtwUSBN+TB7dr6bBgUCkSDwTaxM= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=d3qlnpOQPG6esOfrgMsuLtr7uLeDwmVZa1bFGEfw178PIR6Cy9DW8o9DFDteNbcHlE9CcX2XMZj/Bw+LoSYfSZtJExU8yBGDpy550zTPA+ULzF2h9DRbDMB14JeCqRij5dVdXyEX/k/i0EVu+c091yIZbzBFYU+nBCdbrEekU8j3uEOjns79OTPFz4QFzOPC8YndzmT7j6rS6chfWcbixvTURYHoYBM4skDG3+h3/mH/8V/eh4t6I7C1QS6kQ1BUPsZf7qDRQAOdIqPQpMYQRQEaeRiOp6G4Od6lXlLMss37Warr8lhHpjU3tus/5jM/WW9f1cA1SNaEjYoIHON4LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8aaxMyT9ASTV30k4qhW4SCI939ummtaihJVCjY+zCFo=; b=pEFjmgUjM+l1kIpNlgY8Qm5ipXJ1+NMMlbBw2x6Qxcolx8na6o1M5Dhse7UVHrKdbyM3FUSkVMj262dmeHT1zN1uW8XCdKN3Q5H1ipzqSA8KSTJtt29rsTbCi4xeaAdziHoD1GpcWYHrEEPPDczM/SZmhgNwhBMndjtK/GOcqotZKupZ+YHLJO58wPYpRRQ+u+hNWazBm67dgTCl58dEqre1nxwbORK+vPRy9JNeXNMf8RIGrX2jY9EC5FnHX7ZGLUwhsLjD2y/LR8dChj0NJ7ZyZuogccCpgIZMbqfi4BIjzNaxVb3N6YcdvNTyWa7Sfzogojp1o9LlnhOL6QNxRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8aaxMyT9ASTV30k4qhW4SCI939ummtaihJVCjY+zCFo=; b=MvlTcKML8VSLq6mt9mjtbmUlW5Z5verRUGQdf1OM0CaruCjB9bs7cqzYqe+/O6BjTqpbr8Az+Hbtgc1H7o9r3TAIBYjc9w9w5Tv6qZtl4nO0O+j+KmmG0QuPa+sJ/oBkuSb7xp0/12JPkK9zX8qiZXc6wqxfLvZ2TnnbwT2qOZJzvHInYx2gpD1F1Fir7QX//6UKJpjRF80CnE4u2MQa2Vq2MLNyQJcb2OIh61OUOzmwk7psJm864Zh4TTnvls91halMP8BYghan1MP4fmNesP5X1FhdUcDL72D6fJzn5GFpaa3Zd+JL+tmafwq42FkJDNcG9GPs2rzSqbtg/DlUbA== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by PH7PR12MB6634.namprd12.prod.outlook.com (2603:10b6:510:211::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Mon, 6 Jan 2025 16:55:31 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8314.018; Mon, 6 Jan 2025 16:55:31 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v4 08/10] mm/huge_memory: add folio_split() to debugfs testing interface. Date: Mon, 6 Jan 2025 11:55:11 -0500 Message-ID: <20250106165513.104899-9-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106165513.104899-1-ziy@nvidia.com> References: <20250106165513.104899-1-ziy@nvidia.com> X-ClientProxiedBy: BL1PR13CA0102.namprd13.prod.outlook.com (2603:10b6:208:2b9::17) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|PH7PR12MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: 119351f5-9689-44fd-4f4e-08dd2e72ee4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: mJtcRpNtk0qP1M8FqfIIa27c7jntiSARN7wCZH/AhBn5LFniQY3NKq+AIzVmCQHe4zXwd+QQHew/xWxGdwyRlGynvDX4qFJqtF2plb1S0U0ErbDRj9PBqaIiNDWNgtzjdNuzgA+UCfH/DsK1yBwTgIfhMjcEUq2YFnhJqHrmUSoG7Cy5OudnaT9HhkfAN79iV148a/luMVeZR6+UjJXu16I8GoVS+iNYZ1nIEBzhrfuzFCT26mzOaqlLTKbcTz869WSWja5DEU+/CgX5DojJSZ0sMH+JPGqQCD4mgqRVxpchQxBjiNzS4ncaKT26500QA2ZucwXHnS2t1c6d3uPlUIYzjJ+CWxDRHonUvBzkQxfyuD8PyrcJOfrhEpikz9eTAMgHhA2WxHWeoMoMlnv7IU9RUgxNF+ZHRRJHSTzPNlrv7l24p0h51m7PE1pHWv3xD9jC+X2q1HKM5WJa89OFQ204Ei6PWboR6fN+aKF1n8akBml2lXV5ZJmK7NxkRnwwVJRVyqB5NrU0+wJBKLkCCAvWfrPIFBruTgqomyYpRwJjlOIgsyDaL5aCRbTN+03htu5u95dv+9LAcm+8X1RYhh1eV2sMN8wZyBZmcYcIO24cwqC7mZl+CwBA0FeDfevOwWRhlbx/NDsllhEizTmRUHeVSGntZiDrReCTu6pMGU3EaVDq8JFbU+zl8Jj5R+//4T90EzGng4myscOaOU+YLUW/Nv2u/y3zhrd9TvRUEnUyQQOgam+IMX9rl569b55ZkUeaQAELtFW9dSflrMU5kEVPfZGrcF6/WP0LDh4+OXRW3/BU5eMivxh+fZMSCCO7LxrtetX1T3nc+Xt6IRILFs3brtwSmuhVO5Zi4LX2HEXp6Kk0EZLDB2UUJuGq2EV2c4h+yMyw2NtlxM+0+pBMRfiN7BhznNciN8JAPe98QaSahVQBkyLDgYvNKWdiJqUoV4E8EiUat94HSNjDQ6f9SrvjBkeGjYikdjZGAm+7Z3e8tFweUfiSYpgEg2UQlCXgvOtE9qXL/ZTjRKvXdMr66ZmslYwi2+FSSKgX8xSpcgXUH1LyHfymJM84/736WHS4UADI63cXAuGmN4/kA/VeTRopITvD8wrhKcxgZq7j2kRlwiyhMvQaLip5untnle+aWMpGPopN6xCZN3uFGnIM0q61qSfO4altMRuX+6oaGBgvQK8/zenFbYeGdHHJJh6o76SbVN2ThRzFQ1vfSvS8+5qlwH03Tf7S4r8+w7MNGVxEy1NLN2Pryr56c8+IDFzV2FZ3idS4GgQpv/egfUfIF66CF0kRiitrL88O7DTRpx4dnxuLwJ0DJWukK33U43PBExfixDfJs6STO77lrMKjgcVhZqzjUygonQccfXGcjvyTfaNVvPqmCV5rEdLwNbv6 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6e2voy+EqzX8Ga2kAACPDTGOGiN6AQhVuELsOcKkQScrWxHavum6yRB+r7+nZM6wdIWBgGLWziij00T4soCJxXtyOS6vPq1cEhyJvbZ1W2ppHilrHqgAqwt7z+kEMsBfyRTFyOvkWCdBFsbwP8Pl07b/Etx8QiXSy6TAiFE38vUhVjh+EMbEKN5TpfgbFLNb3Fv+gYtTtk4ENcf8KOhJKU9g5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ftbNUQu9NmNdAinb4pf8n6LaXnldQpKASELz1WLqGeYFzKPV1Yx/CVEaBFnpJn0tHGzOzCzYbnzdTc4/G42r2cMEzDNKtvWt6hSgwoK8kSuuIXTbW1LxQ+s53ycBdPwK1ZHhjT3tQCn8zIK0HVg69i/rNXKUWSIQYIpATHam8HPqgSMm+Vq4ty1F7blxkIn4alxYCKKkk7gyc9BOsxYOpx6it6Q/fwTezfWV7pREG9/RyAFPs0NgWaN41Z6JbscfWfSug9r3l5Dm/lxny3HH18rKcDB1wWD8MJIf1+BhT/sXYt X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 119351f5-9689-44fd-4f4e-08dd2e72ee4e X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 16:55:31.6621 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 47Ev82kxyOY3AqI7Twpg85W6AXcd8ZTxLEGWP62szpimCOCEINOrFx9E8A2Wv9yL X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6634 X-Stat-Signature: wd1dxqg9w3wexz8t3iood6bm7mthurtg X-Rspam-User: X-Rspamd-Queue-Id: B4E42100006 X-Rspamd-Server: rspam08 X-HE-Tag: 1736182661-150962 X-HE-Meta: U2FsdGVkX1/PheE6nquWlvGZ/jqnAFasNB20bDvNdP+DrGzBEpZr/RsWntXRhgyjIiDGJS4+deDHC/wrLctSclmraC3aZ8KgmHhOgtup8BwFwIevYNZUBJQXYd77UL7QtGwqq+6dK7faRt7gs6nktlILJxbzU4UFnR/L9KO+hEXcn4pBXHGMO5RVtYQooSwyO8Y2aNCgem+RNGmZvwj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H1qAjUzsnHaoDZ5rowh45ea2/xcylATGfEwfgK/nb7vMIVGUNs+BT5BI/IF8tXfvHruJybTuzosN1zecw/nwq2wbMTmt3dIzdGGR63wclPv/l6xrC/igGczbPs= 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: This allows to test folio_split() by specifying an additional in folio page offset parameter to split_huge_page debugfs interface. Signed-off-by: Zi Yan --- mm/huge_memory.c | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ec27287b7cbb..50f268741c4f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -4125,7 +4125,8 @@ static inline bool vma_not_suitable_for_thp_split(struct vm_area_struct *vma) } static int split_huge_pages_pid(int pid, unsigned long vaddr_start, - unsigned long vaddr_end, unsigned int new_order) + unsigned long vaddr_end, unsigned int new_order, + long in_folio_offset) { int ret = 0; struct task_struct *task; @@ -4209,8 +4210,16 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, if (!folio_test_anon(folio) && folio->mapping != mapping) goto unlock; - if (!split_folio_to_order(folio, target_order)) - split++; + if (in_folio_offset < 0 || + in_folio_offset >= folio_nr_pages(folio)) { + if (!split_folio_to_order(folio, target_order)) + split++; + } else { + struct page *split_at = folio_page(folio, + in_folio_offset); + if (!folio_split(folio, target_order, split_at, NULL)) + split++; + } unlock: @@ -4233,7 +4242,8 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, } static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, - pgoff_t off_end, unsigned int new_order) + pgoff_t off_end, unsigned int new_order, + long in_folio_offset) { struct filename *file; struct file *candidate; @@ -4282,8 +4292,15 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, if (folio->mapping != mapping) goto unlock; - if (!split_folio_to_order(folio, target_order)) - split++; + if (in_folio_offset < 0 || in_folio_offset >= nr_pages) { + if (!split_folio_to_order(folio, target_order)) + split++; + } else { + struct page *split_at = folio_page(folio, + in_folio_offset); + if (!folio_split(folio, target_order, split_at, NULL)) + split++; + } unlock: folio_unlock(folio); @@ -4316,6 +4333,7 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, int pid; unsigned long vaddr_start, vaddr_end; unsigned int new_order = 0; + long in_folio_offset = -1; ret = mutex_lock_interruptible(&split_debug_mutex); if (ret) @@ -4344,30 +4362,33 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, goto out; } - ret = sscanf(tok_buf, "0x%lx,0x%lx,%d", &off_start, - &off_end, &new_order); - if (ret != 2 && ret != 3) { + ret = sscanf(tok_buf, "0x%lx,0x%lx,%d,%ld", &off_start, &off_end, + &new_order, &in_folio_offset); + if (ret != 2 && ret != 3 && ret != 4) { ret = -EINVAL; goto out; } - ret = split_huge_pages_in_file(file_path, off_start, off_end, new_order); + ret = split_huge_pages_in_file(file_path, off_start, off_end, + new_order, in_folio_offset); if (!ret) ret = input_len; goto out; } - ret = sscanf(input_buf, "%d,0x%lx,0x%lx,%d", &pid, &vaddr_start, &vaddr_end, &new_order); + ret = sscanf(input_buf, "%d,0x%lx,0x%lx,%d,%ld", &pid, &vaddr_start, + &vaddr_end, &new_order, &in_folio_offset); if (ret == 1 && pid == 1) { split_huge_pages_all(); ret = strlen(input_buf); goto out; - } else if (ret != 3 && ret != 4) { + } else if (ret != 3 && ret != 4 && ret != 5) { ret = -EINVAL; goto out; } - ret = split_huge_pages_pid(pid, vaddr_start, vaddr_end, new_order); + ret = split_huge_pages_pid(pid, vaddr_start, vaddr_end, new_order, + in_folio_offset); if (!ret) ret = strlen(input_buf); out: From patchwork Mon Jan 6 16:55:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13927682 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 F041CE77199 for ; Mon, 6 Jan 2025 16:56:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 824E26B0099; Mon, 6 Jan 2025 11:56:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D5CB6B009A; Mon, 6 Jan 2025 11:56:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64ED96B009B; Mon, 6 Jan 2025 11:56:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 47F3D6B0099 for ; Mon, 6 Jan 2025 11:56:04 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EE5A740DCA for ; Mon, 6 Jan 2025 16:56:03 +0000 (UTC) X-FDA: 82977629406.03.49EDB6B Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2070.outbound.protection.outlook.com [40.107.96.70]) by imf01.hostedemail.com (Postfix) with ESMTP id 0A1D540007 for ; Mon, 6 Jan 2025 16:56:00 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=JPaYvEby; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf01.hostedemail.com: domain of ziy@nvidia.com designates 40.107.96.70 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736182561; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ufgh35zpABvHcri2rikCwKTSNZOwz1LsK/G4HcgWwbc=; b=xYIwwYOHMxJonMKaKrojcBg6BeFLXt2MeFrOncef2oTDSqi5w71afnTw6YqQbUSdX1reGk rLZRlnzyXN6XPcpG7VsEM15NJdQ3p51RYJSAfjolbBESGWDPEvEmMbFj/4V8iO4CyDALl9 24wIYZli4Z72vKZHKAwDDgSZ1AUAdZk= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736182561; a=rsa-sha256; cv=pass; b=TSyPoMCpnqI4fY6677MMVtUWyy5N3iOpILno+H4ERPa80m6epxNUhXDHIjKuUwfkDCL4Sa LXIjxOOdrQjpXIAsg1fhC2G0iUFukGCfhFTQkGJh/HvCPEKeDneRqbTH6LEBXjK+qZXupS K1PL8LlFO4EzYiQkY2mHJ6kn9iOq5io= ARC-Authentication-Results: i=2; imf01.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=JPaYvEby; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf01.hostedemail.com: domain of ziy@nvidia.com designates 40.107.96.70 as permitted sender) smtp.mailfrom=ziy@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Fc8N1zZGzV1jertEE3r2Ax/C8iTJjDE8lzjlYMZAtcRFpfQedykj/0xQebOu9uFS06Ie8qKJg1s5kSs+kjeN4mE0RqBbW7Ko6vcn6Fzw0ICju57H9Bbh5VbSQLjw+bKtT4Y7rwjffyKZS+52I4FJJlPyLtmhVgJto3gdSvUtCuPvLu44P7dkXp6Qsb123JzandKdrLD0gIbizpdDExiDSlKdQ39PhrYH1XeMqWL+bLmG+5aTHFN728cT8WCWAkR5/Bjck4Frgwb9TRZWBahQltX1XszDn6qbu+87nuq9TLp9gIdeNqgGeyZNcnGnhQf5hdZXNX7BotKkvuxvsmWFtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ufgh35zpABvHcri2rikCwKTSNZOwz1LsK/G4HcgWwbc=; b=RqmChzOtBGSHLAdxU6sQlvA0Ga3eR2nPalXsDPXCeMNychR77u2Y8KqPmGbVAPx2Utegbep1dcLkKrPqQPdtn0JXrDQIxUZtVYOs1PR1ivp0rgfrIRrpnlK3DM19b7VVliGhjqS5OS4VGIJrmdtRDZhnMn/MkxxVleBbkc1h3bKWK8A9r9fRSQtMBbMTMKNsL6S20Qf7Ft3Qy3VMFvYnlsxyZQ4aK+nkJarwUxy36VarPsByFj6fdhhNeew4/s8Vfv4Vw3KVeMx9gTPJX6JNb4jE+2TsG+5XHww98yEBmjjQmyWeJ/jTQNhufa1tibL8SqYvcyWyNT3GRJMdu4Dypg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ufgh35zpABvHcri2rikCwKTSNZOwz1LsK/G4HcgWwbc=; b=JPaYvEby9U+bK9AZoHeCHANxVwRBPuuHh7+VpO1UlGSHcdm1y8PKhiev0EqLmAW1Mi62VP4vH5Rc7JXczKnksA/gGdTb6JEO+QmTx2zhTUZYaHfL/kJrOIFCDfw2d02iobDLa69gf8axQu2/PbAoSLCQIldhpKgZtWr96LuftRTEZSL+shQH1FpHIGnhinPBGZ90TwYzD1Cly5tjSE8tZndrKtinS3SPc+2BKJukJQ6N/qLPndyIKVMQiej5a3e5EaGmnd/k1uAbbsVKAY9NlFZmy3Q4l5XEBofhvt/KB0nj3qU89MvX7L5J5Wf2bJSDdL84UzWwN8ACtUVt6nZZDg== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by PH7PR12MB6634.namprd12.prod.outlook.com (2603:10b6:510:211::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Mon, 6 Jan 2025 16:55:33 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8314.018; Mon, 6 Jan 2025 16:55:33 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v4 09/10] mm/truncate: use folio_split() for truncate operation. Date: Mon, 6 Jan 2025 11:55:12 -0500 Message-ID: <20250106165513.104899-10-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106165513.104899-1-ziy@nvidia.com> References: <20250106165513.104899-1-ziy@nvidia.com> X-ClientProxiedBy: BL1PR13CA0119.namprd13.prod.outlook.com (2603:10b6:208:2b9::34) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|PH7PR12MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: 50d48514-a24c-4957-ec86-08dd2e72ef40 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230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EdQzfDTC1uKkF0XchB3FqFRrsFvIX4WaOUnYoICy/oJoJbGXpAY7yQSdnDKohT5c/ec3OcBZ96xVSaVV/Z+h4TPtg4MJ6PQMZHHo2DZr0p2cD6tmXbPmLIeLjKqTlN96kCkPGCZmSR8YPC+DIuasaedeL74ASSP46jnTy4Wb9mwTaA+aB/2QZ/XhB9dXH+06i/D1V/kKIqAfSdDYUAegvPKI9mQgWYYQncYymYEEy7CdWIDN8ySCdWTlCwfnRWjHZt7Z1HPTaPj7xwRhizAwFRwEW9QhjWWaWDbJEHBDBeVd/rl3OYvmc4BNXBm0gTC8ZSkoMkEFOpPgmanR6F74lOIDR76yirUfs96PGGvKlA X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RaRhGp/RMA1k7ZlpJ6PrM1n9CD9J1tRy4a8tM3Nk2Co7roPgzKx6tfTqXVXQWdsRwpWx89jRgTkemHKpAU8ys6j4woE4UfF0qCST+A/GFvzWrouXMIxdfDW1xvgaq0xWmhRfrlDLKZ8nHvh91ixEQmlQx8C9uzzNNBG1QJd4ur4FPXj2HjeB3/4SUYB7oDyqOejiSmrzRgGNJB2ZI/bkW8vLGGoqQD5fql6w7WLdtux70CCxwn4iaZs1siHC7BiYurq9OoiLvc7uKRxJ+xupVAypbseuf96Q4fBedWrX3wRjK5HHvygadv8UKfHpi2+U+jzwYhZMnmFqaRFOCIGGN+PJEq48mBfymGNJ1StKhjq+7zyYmG//M11rI8WQWBs9miMTeRH1ykdOYKqA2r7F+IB60gKYA7Trcktjf7zp+xQl1s+lsMert68SvYImYzRv/acuVqm2cbieQR15uag54/d8a6Op7vq5gyVt8tZHKLiu5nNSP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FdC/oYWxVg30DmcC0FMPg/kBCB7uKot X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50d48514-a24c-4957-ec86-08dd2e72ef40 X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 16:55:33.2831 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: U+Vx6PtZ+JcDPsFGsC8cVLFM93QE5xIv8ml+/o97Z4LorHoVJUnBlFjT6jVig9wI X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6634 X-Stat-Signature: 7c91e3d6fj9stwp37bwtu1zf4898r3yu X-Rspamd-Queue-Id: 0A1D540007 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1736182560-853956 X-HE-Meta: U2FsdGVkX1/5/8o4a0xRCy98BAhShAoweDwvEK6QQN28JoYJq4/PM4mBa/MYzvmXQe/RsZMd02wqkp9DOeqrwwZZqPkY3B+WmqQhdFb4xIhlZGtnFgvMf08E8aRf5J1p501fM/izCYTztW1gaAJu+L8Ij1kti//pGh2oo/+YnfBvIAWvJc/iI7bxXEOswiHTjnwvZC1Kv0S74OAq8Y6/ehsnRRQxtK59bsZztSkbujtzAyLeNFWWiwF7ym9PGo7SIJMNI/474Nwuu9AewePEJL60AqS5lMurscq63gzY5yAYmDornFt++O+u5wA6Kb+Iu+qLOE0gWb7xUBGvGQqh5BHGxHIUylufIIovhbeeaufALhTG7U1of4Q0kAHUqFdshKzcp4jPw+GXDrqgeHeN0CXpznk+meDZQj6i7DxUczi4vle+VU0dz+3Xgxp5cPOOCpwqnnHT5634iKfxfUjH4XfhzJXpgUKJZ2l4oA27lleqheuj1m5YKVgHEwHRRSpIBEmiTTzgjbqHlhnOE40rZ0KFO1r16re9oh8STlBp+YgXHzNYP9u8ZDq9XOrl4cqtZJaoOfC5s98lk3FShqREPV+PzLd77kin1WiUQvaTNSE6NdHkz5+v96isOoVIcipWLolcLryxkewv+MxT+qqGbYexjKI0ywm4CiQl74z9ONigaQCBuB6RsZeY2KDiNVVnU9fIBoEOqquKAiQp12hNX5tlaHuEzBoaVFirOWqux45JqRdAxui3ILJcNH3NYDLMyTRHws3bHsf4nlWAMx0vcgE1PIe04Dg07tAaBKJ6tucq69Ei4RxM4DswIAbQk323ZRqLM2xnpbbAFazIdJVDkvtYGHZ9dgRl62UtoBtc2ysJ1jmRoBvqHjtpxIAA57f8ljRi+iSFgSSVtmg/kuvFrXYaQlBHZKLed9/DlJyzt1ksKEWXU0ISFdP0lrzwI0d+NxRYJ0nGOf0cYMONNgC sp+Lad7u seepxcD8CwsdmOwNACgtmmpErd0Pw2T3ueQW6nIsSow9mMzi1OXxBCh9lYgNPLzp7DBJEDEXL2qaa1+20DpNaI/mv6xqyxFwnciT5LF0JTsfOoPM9mjiDcLvD9WSYPP2nipLX0SLp2pt/J5nMGFH5YmzRNQJJBl5P2J+Tk38cY7DejdIUvUF07MzUw9oKsoRnpUVFGgu/ERf5BiQaFLnSEkf5+nKLHarWgo9+uMobCoT+JlEiJ4w4JjoJC5bH/pumwnDEqLDJ9NWiPh7wP4pDwym2+y0CBfbtA0hmb9j5Z1kVrLs/0+6KyigI57SJoxhKPtbcp2uHLULLSqXZe6na0yY2kUBD/L/jjUu0hG9Ophksr7BRcU5JgJDIEL4VJstpdlfe4YsLN5YvfBc= 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: Instead of splitting the large folio uniformly during truncation, use buddy allocator like split at the start of truncation range to minimize the number of resulting folios. For example, to truncate a order-4 folio [0, 1, 2, 3, 4, 5, ..., 15] between [3, 10] (inclusive), folio_split() splits the folio to [0,1], [2], [3], [4..7], [8..15] and [3], [4..7] can be dropped and [8..15] is kept with zeros in [8..10], then another folio_split() is done at 10, so [8..10] can be dropped. One possible optimization is to make folio_split() to split a folio based on a given range, like [3..10] above. But that complicates folio_split(), so it will be investigated when necessary. Signed-off-by: Zi Yan --- include/linux/huge_mm.h | 17 +++++++++++++++++ mm/truncate.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 93e509b6c00e..e5693820cb0d 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -341,6 +341,17 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, unsigned int new_order); int min_order_for_split(struct folio *folio); int split_folio_to_list(struct folio *folio, struct list_head *list); +int folio_split(struct folio *folio, unsigned int new_order, struct page *page, + struct list_head *list); +static inline int split_folio_at(struct folio *folio, struct page *page, + struct list_head *list) +{ + int ret = min_order_for_split(folio); + + if (ret < 0) + return ret; + return folio_split(folio, ret, page, list); +} static inline int split_huge_page(struct page *page) { struct folio *folio = page_folio(page); @@ -533,6 +544,12 @@ static inline int split_folio_to_list(struct folio *folio, struct list_head *lis return 0; } +static inline int split_folio_at(struct folio *folio, struct page *page, + struct list_head *list) +{ + return 0; +} + static inline void deferred_split_folio(struct folio *folio, bool partially_mapped) {} #define split_huge_pmd(__vma, __pmd, __address) \ do { } while (0) diff --git a/mm/truncate.c b/mm/truncate.c index 7c304d2f0052..a8bb0c6e685d 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -178,6 +178,7 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end) { loff_t pos = folio_pos(folio); unsigned int offset, length; + struct page *split_at, *split_at2; if (pos < start) offset = start - pos; @@ -207,8 +208,36 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end) folio_invalidate(folio, offset, length); if (!folio_test_large(folio)) return true; - if (split_folio(folio) == 0) + + split_at = folio_page(folio, PAGE_ALIGN_DOWN(offset) / PAGE_SIZE); + split_at2 = folio_page(folio, + PAGE_ALIGN_DOWN(offset + length) / PAGE_SIZE); + + if (!split_folio_at(folio, split_at, NULL)) { + /* + * try to split at offset + length to make sure folios within + * the range can be dropped, especially to avoid memory waste + * for shmem truncate + */ + struct folio *folio2 = page_folio(split_at2); + + if (!folio_try_get(folio2)) + goto no_split; + + if (!folio_test_large(folio2)) + goto out; + + if (!folio_trylock(folio2)) + goto out; + + /* split result does not matter here */ + split_folio_at(folio2, split_at2, NULL); + folio_unlock(folio2); +out: + folio_put(folio2); +no_split: return true; + } if (folio_test_dirty(folio)) return false; truncate_inode_folio(folio->mapping, folio); From patchwork Mon Jan 6 16:55:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13927704 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 6E829E77198 for ; Mon, 6 Jan 2025 16:59:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDE4A6B00A5; Mon, 6 Jan 2025 11:59:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E66D56B00A6; Mon, 6 Jan 2025 11:59:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C942F6B00A7; Mon, 6 Jan 2025 11:59:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A7A186B00A5 for ; Mon, 6 Jan 2025 11:59:13 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 59B35C0110 for ; Mon, 6 Jan 2025 16:59:13 +0000 (UTC) X-FDA: 82977637386.16.E5CEFD5 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2061.outbound.protection.outlook.com [40.107.96.61]) by imf05.hostedemail.com (Postfix) with ESMTP id 955EC100006 for ; Mon, 6 Jan 2025 16:59:10 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=mVh1w725; spf=pass (imf05.hostedemail.com: domain of ziy@nvidia.com designates 40.107.96.61 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736182750; a=rsa-sha256; cv=pass; b=7f4vTcKZN3GAVL3+GehNuY1J6Xd/phGAZfWpJcdbM9eMk+eNNVDnNUJ4NhyxRKqESM2Lfb ckpaQTXsGY6Ji/6RhVNlFck5k4a/1z/lJuCWZJk79FD+Sn/RnPQ8OxdOMUCe3igpd8Lqb2 qi/TGEousbkSEve1ggpJcYTAYlsDWLU= ARC-Authentication-Results: i=2; imf05.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=mVh1w725; spf=pass (imf05.hostedemail.com: domain of ziy@nvidia.com designates 40.107.96.61 as permitted sender) smtp.mailfrom=ziy@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736182750; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7vfodItUcrcyLrOMU+QPVr1fQyMNwn6ddi+gcaz99x8=; b=6jsuLVJ5noknCH+yRBgjEoxfWAOT98vFja8+DEj/qsxUYp3CtnSPLSfJqkEl+nF5w2921k XIiAKIO7r8r7cPP8ZslwWPMpyt9tJuclSsa0IslmTgF4z8xaBg90TbHeuMk3ZXehvH916l SMykDORUNAU38ZJ3jS5rQPtooBP9wRU= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hnuQa55IlJjKzRhfJnlWdEdpTaHswO1WQ0MyCib7jpMWqHHAlOFEXWv0eGEjEEa+3U04BRRAzaHpJJBU7P3FdbHKVfxW+DgyHqYu8ZUEUgg4qQ5hueq/7Fm6hLnvK/QbdQF1f4DY01D40rZ2C6hLP498dOyXCMV/zpPW80A0f4BeTmLOOI3n7Xp4oxEANcQldSFeoWSPK0qZtpvRFtgUDSKRkGGlNDIOOtgJgxKFf40uLhMiJBVuTkSTw8vNC2vDvjUNzRuK7hC3eHU3mvY6dEQPLrmm9pvrIQxmZ1Mcqc7JIWzcxZS3b7JDutrVZXxO7a10m+b6ubOn4n75yw2kPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7vfodItUcrcyLrOMU+QPVr1fQyMNwn6ddi+gcaz99x8=; b=o2N1owjpYRBm+xS5Hb65Tph9kXsaaTpyFz+MpCXy4rTHPCSeNb9d9m68lrZPHxveXTKjsbgSsf+aHPg16G2H8wIWQSvQwOrg5a4lPtWwIlfsAiFg8eUlc/oONanhOeGW1oMjDOk3t2ec8eJ2kRIBFUDzQKNDyEuVssG6XzcpqHiRR6E/HvmbDdyvDfyhlNL/l5YOFT3TOJD/N3t3diCYBD97pLs13wPkxICgut0rdV1g21zAv9wJ6+5rqg1jQLOmeR0pvisKeXd0U5eRtBkAwk/EiuIKgbV8sCjeX8HYpoC2HPm+mKNBsbHMSKMdu2xrDDap/Ggw+H3GZou4fh5mRg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7vfodItUcrcyLrOMU+QPVr1fQyMNwn6ddi+gcaz99x8=; b=mVh1w725mam9Jyhv4hHUb77GDc9OxmSqI98IbcSlEZIcmb8eY0l+DlxYBNz5j+1isH8UTB4XWyinKlzAh1zPpjyBQQ07MobxHXsP7Rq8+IimAVu32B+dBkXUTHr0kPPF/CQxSUbK6jXfEDugRp7k8+EEJbPHYfU3wVn1g3xTtnHCydB9LUJbQZnKZ2f79PJSMarIcRQrCRIXRVpGZRd5KSNgVUNHbGzqR0o5WyP+mIJqmrk7x0fBzP554Y0HZVpnAKP/d/M9vZ7TUhxWLmBgOQdX8Pyy2PL/6GNfhCkywCJeBoOEGVyE9bhfRTlsqm1rsXVX7XU5Kg1QwG942gkJpA== Received: from DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) by PH7PR12MB6634.namprd12.prod.outlook.com (2603:10b6:510:211::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Mon, 6 Jan 2025 16:55:34 +0000 Received: from DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a]) by DS7PR12MB9473.namprd12.prod.outlook.com ([fe80::5189:ecec:d84a:133a%3]) with mapi id 15.20.8314.018; Mon, 6 Jan 2025 16:55:34 +0000 From: Zi Yan To: linux-mm@kvack.org, "Kirill A . Shutemov" , "Matthew Wilcox (Oracle)" Cc: Ryan Roberts , Hugh Dickins , David Hildenbrand , Yang Shi , Miaohe Lin , Kefeng Wang , Yu Zhao , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v4 10/10] selftests/mm: add tests for folio_split(), buddy allocator like split. Date: Mon, 6 Jan 2025 11:55:13 -0500 Message-ID: <20250106165513.104899-11-ziy@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250106165513.104899-1-ziy@nvidia.com> References: <20250106165513.104899-1-ziy@nvidia.com> X-ClientProxiedBy: BL1PR13CA0107.namprd13.prod.outlook.com (2603:10b6:208:2b9::22) To DS7PR12MB9473.namprd12.prod.outlook.com (2603:10b6:8:252::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB9473:EE_|PH7PR12MB6634:EE_ X-MS-Office365-Filtering-Correlation-Id: 4eeac6b7-9412-472c-b56a-08dd2e72effb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: ZVOy/AeOm0/S/Gp6gXaU8sv6onEPQLrByenWjq0ay54zck3wRyuLYWKZMzFRNCK7O1pRKMx4MKd8XweCwc/0bwbdLUM0l3MOrH9MwA+FBQGhVCPNRGhTmF157omlPC57TUM9vFxg1B+2UCbm+mBDNeEyfGVEi8kkEcw1gzhrfqZ5iR6eE3Q3MF9axPRLbZK17bJmN3eSwrzx4x/v2JbK/pGIzuLyRtEORgfFHtw7z6UnxTQLGbFSTtES7ZDQp9fsDTMUfQUSg6rmCWYToOuoNQxRL/MEEElRscwPBgOsa5fkHgquMqyIrj+Xw2YN++86hQr19a7i70of5vlkhh9StYPLyDPXAlrRCXDYjclGG6NQHDO/hYcoqD0QJFyNojNn0bd7/gxFdGEVApY2zMY4iZgRi7OmbqQDU1Mg+Y+lElOctZA5CcGZdDaJN7I7Aaiztn9n3f5ZX/P8ijTsR5VGus0yJC9aXVl8Z3GK/xehbP0kA12ukWj3mXROiPJwCeJw2P4Sc7Qd6eQDiOdhKFKRu8OcoWc0ojNEO17FSisO0oN5hPzljoveYT/NhhanvZhBaNBQWCf5MkTpbgZ1kKJQoRG6LRwdxElWDKC68W1i71WPgQRTC9udy166iinKkFwAfL24JIDKvCN1J5LncFGQOhkvETS0XxXrQoC9FeqeABGuawICIF+IX+VC6LZOdtc4riKg3HAGujga5WSA9tpOJbYVnvw6efoX0OWlr53v01LOkR8tM6VflJKHWvxt9j0gxHeXNybUEOFP30RrBWPj3tj1UoKpxwFlJTfgen3G05XqwFuJG7SlsobF9AuJtLp1OwBCOGcuu+bP8ocssrDnPHyRRDTMXtHLeZsznJp1DrGBX4DNfIKkqtVM0dfIwoZ+V3T7oWxikZqROgm6ZmNXq0/QwWmJBFzco6r0LJKX2ZRV/q/46qcot/j9yC2lkrDrogg8K741AGK+2+0u+Y68HTZVapCDT5Y8ce01xmorb819/G4glrBSGJEIA3I0LNg0vaNAFHfpT4UcL0eUcQ9htY36bZfqtGGzKdMaKiQqwWSviQVlypksRbQXM/qG3CAW2OYodENnrSoECinWFuKmFUyKa7NCyXsG7iCmJASklw+cciJS6el5S5fd9lKKn2Jar4NYU+Ok4qO29D4IDNgN870rNAqLHZ5ZfoarUrHsauIWMiWdA+K7AC/mZj5WpCr9khz+Ou0KQjDuHiG4lGjGl5/baJd4y4FJ1q/Gd4hssde6Ki9D7OMo5Pj5NodqypE0EVs7LpIDTivg4XkMSFqfbyffMEZqdC8DVP81miNxnMUWxvqUoVAFsEYNFMaj3UAHu5tIlxZj4UFjOrOEVSE6j72SfCM/Nmk2iXWmbC4a3mcyTxJO811pMkBCL22X0eUs X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR12MB9473.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(376014)(1800799024);DIR:OU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ytoF2XO7dvY629D7aFTEv3nzoEbWpKg9K1+oTKQiKPKRnEWieUhhsS4TFNL5i38QlloLeGpgpUJwNbCGqKgEnzl9P96dSdyMBPw5QP7/p5odwnY5H0Zel6HzPXxs6o8f3K7vk60rGYSbfp42DbeDliiaStgf2v0SDgu+zde+qv8Tzmhi5x3W7lJbwowhWdPUAdFwESQj0Iyd75Z1vNDQ836ZOXARHV1CRmJY4XQjybEIMRbvOZy1vnH6oYf4gyO/tAe45oN8/+wy6bclKojdvUshWtDZBn1SGNRkLfcTjUKa/gVMPfzG8EWLkLhRofy0p6/NnghQQPXOm4QrPeLKBJl6gkWmoD/LpBepAHKUpWkUcHQHfNQWa+J3JEfGq0VY4vmapd4CMeYMokvnuxZXQGakBWTgLGFmXPWGpn3fntceNcA1iO5on3Ba9jEBg38SngmXxvQIirZkS4YbwGcZx9u1F6ec2QRsnc94nx4aXPpSEhf5wdzkBChEZhHmF1AgUyZCFgRoH7vZbK6RKVrN3JAwqbHThEys1Cowbyuq8SQOyqZg/gytmD+KBrlrSgfdg76BEdV8/XSJen X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4eeac6b7-9412-472c-b56a-08dd2e72effb X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB9473.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 16:55:34.4870 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5XDjjv8x84r+sE9A9jCFVWjS7KoEo4/qE2ZTWA+14xAKUOeavbCBtra+Fw+6beT8 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6634 X-Rspamd-Queue-Id: 955EC100006 X-Stat-Signature: bqoigf67rfqjn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njpEVJghHloszI2AIPOjKgObNTLKWJXasZRm+JwXN8xmhjTRSObcL2YsPCfSpQ4lcSD5OXMxMlKL/bE86cNA2ZRYSJktDDI7uRIbLJ7P83BrCcHkf9OVDhRsJt/90bOQ2AFfOBeDXJKAOPnwjSl1awvdGxDMaZebBs6McyDZuxrePSlc3/C/TmK7+hQo+N4ve2RRW5v4/i10pFcGny1CFNdC7W2+j+FMIWega2/wegjPfKjr20uCx7IgDj6o0ZP+bdex16srIB7o64pcso6lQG4gKPQ2urgFuY7/z0qyFdwfCe0RjD3bNlMPIhK2nGUrI0RJysjwwGK02m5UDxoUZbQGy9X2vURWOb+OS7YC0DNiq3O2Q+aG5vNbPrGM= 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: It splits page cache folios to orders from 0 to 8 at different in-folio offset. Signed-off-by: Zi Yan --- .../selftests/mm/split_huge_page_test.c | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index 5bb159ebc83d..1af8d6fa4465 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -420,7 +421,8 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd, return -1; } -void split_thp_in_pagecache_to_order(size_t fd_size, int order, const char *fs_loc) +void split_thp_in_pagecache_to_order_at(size_t fd_size, const char *fs_loc, + int order, int offset) { int fd; char *addr; @@ -438,7 +440,12 @@ void split_thp_in_pagecache_to_order(size_t fd_size, int order, const char *fs_l return; err = 0; - write_debugfs(PID_FMT, getpid(), (uint64_t)addr, (uint64_t)addr + fd_size, order); + if (offset == -1) + write_debugfs(PID_FMT, getpid(), (uint64_t)addr, + (uint64_t)addr + fd_size, order); + else + write_debugfs(PID_FMT, getpid(), (uint64_t)addr, + (uint64_t)addr + fd_size, order, offset); for (i = 0; i < fd_size; i++) if (*(addr + i) != (char)i) { @@ -458,8 +465,8 @@ void split_thp_in_pagecache_to_order(size_t fd_size, int order, const char *fs_l close(fd); unlink(testfile); if (err) - ksft_exit_fail_msg("Split PMD-mapped pagecache folio to order %d failed\n", order); - ksft_test_result_pass("Split PMD-mapped pagecache folio to order %d passed\n", order); + ksft_exit_fail_msg("Split PMD-mapped pagecache folio to order %d at in-folio offset %d failed\n", order, offset); + ksft_test_result_pass("Split PMD-mapped pagecache folio to order %d at in-folio offset %d passed\n", order, offset); } int main(int argc, char **argv) @@ -470,6 +477,7 @@ int main(int argc, char **argv) char fs_loc_template[] = "/tmp/thp_fs_XXXXXX"; const char *fs_loc; bool created_tmp; + int offset; ksft_print_header(); @@ -481,7 +489,7 @@ int main(int argc, char **argv) if (argc > 1) optional_xfs_path = argv[1]; - ksft_set_plan(1+9+2+9); + ksft_set_plan(1+8+2+9+8*4+2); pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; @@ -494,7 +502,8 @@ int main(int argc, char **argv) split_pmd_zero_pages(); for (i = 0; i < 9; i++) - split_pmd_thp_to_order(i); + if (i != 1) + split_pmd_thp_to_order(i); split_pte_mapped_thp(); split_file_backed_thp(); @@ -502,7 +511,13 @@ int main(int argc, char **argv) created_tmp = prepare_thp_fs(optional_xfs_path, fs_loc_template, &fs_loc); for (i = 8; i >= 0; i--) - split_thp_in_pagecache_to_order(fd_size, i, fs_loc); + split_thp_in_pagecache_to_order_at(fd_size, fs_loc, i, -1); + + for (i = 0; i < 9; i++) + for (offset = 0; + offset < pmd_pagesize / pagesize; + offset += MAX(pmd_pagesize / pagesize / 4, 1 << i)) + split_thp_in_pagecache_to_order_at(fd_size, fs_loc, i, offset); cleanup_thp_fs(fs_loc, created_tmp); ksft_finished();