From patchwork Tue May 21 11:36:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13668881 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2042.outbound.protection.outlook.com [40.107.6.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6678717C6D; Tue, 21 May 2024 03:28:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.6.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716262106; cv=fail; b=J1zfeIzjO/X9konG+lGsLrJzbSAsKANvTaH+ppY1J1PjN0g1LHwLUyi+ANUpWDrdPbqzMC+o+yW7t2JSKN8Gh1unylPU9/kBun4nNtssy3NCTuQ5wPZ0qWi4P8P1E1TmHvUEeFl0JElzzLFyVnU/JCJKrWlCMD4EdUIkcGrsWrs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716262106; c=relaxed/simple; bh=MzPB7ZZ6Z5IdenVabdWi9YtXEVUNaX4sVy16S8Rv2K4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=IycSvGJzTLuNW/DeJWP1ZITmfNAtKd71ntDJ+jZ9J0zAhZ7io4laz11JTJcBohi3/LMITpQe7WXHhXpDnqUTvvk+b3Zby8TE4bjuXQy+rrRPb1lTw6ZcNY3PSVT8U/7GcaHbx0HgBBErU3/qKv0Ns5/YctNXzsrWVu+3DrDvJVc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=UVPo1Zb2; arc=fail smtp.client-ip=40.107.6.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="UVPo1Zb2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YOsKWZF19KLSmWu208QqdOHaEtg7AfUmOf1+uD8fl6c3ZghHIFQ7GeJ1fLuVQio19OnYPxq4q90GpPPu01gZSc5wIP7fF62SwLRpXN7wfOdKwDd0A/ygPZu97FyH10YSbeIew2bJ8e0yhKRaREO82+Ep9JuQ1ZoNGy0TkwLBBUEtAkaVNJDRLazcI4ybSC6zmXCSZMDETbJSVEzhSsh0Kvn409GawRA32mdU2gG9muesiD7V4+qEcBffwE8h3bSB1wbIYgGUP2BMt1oZ/5bJtC+MPKA7lmUVG3/yJfn5d3mAow1jjW2hN4U4XLIubOH9ZOpw6yRYmo+sYZOQqHQmaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=WochignTIwIPyyTdxOzcLlmWpQ7M5ZVQRhp2E5OLnAQ=; b=j7KykuDttWzGPZTsvhGRRfy1WYIK2rTNjcnvurgaKru1cbpPbbLA4gSnGAVkf74ypC7IHVNjBZbrLGS92lppD/2++zicGzYU6zPOKQ2L8jQhXY6slk+66jTG9P48a2Z38Dd/MYdN1PFuTyw5XqVj+THg7pETDIu2LzIjpu2fokd+twRrjYcJkb6mypaJIoBo4gZGnE9GYVdIUKj4f9vPIsANBsbcbqenx44aRBMCaSAKD44+yi8o5gjhjPU78ngM1DgXxLepICuvUnQ3cgTE/ySYbg5ETGKq7efb88XL33a1rwiVx+owcAJiGT8B1E016klXB6ypO6vHLg41//xzsw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WochignTIwIPyyTdxOzcLlmWpQ7M5ZVQRhp2E5OLnAQ=; b=UVPo1Zb2eq/rhEHN6lYLXFXba7TIjrJEAB8e7zKG+AtaaCtvjHOtU7x7tMyceT3FWKN+LCn+4jrgvHsfKMtpk1XRa+oZzt0oUc1jx1gN0AUfgFvLWGPJE5mJ9xVIU4k9e+VmJvFid5RI+DseNW21oceBuQam8t/y4m9IoCW9wvA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) by PAXPR04MB8606.eurprd04.prod.outlook.com (2603:10a6:102:219::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36; Tue, 21 May 2024 03:28:21 +0000 Received: from DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::8d2f:ac7e:966a:2f5f]) by DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::8d2f:ac7e:966a:2f5f%6]) with mapi id 15.20.7587.035; Tue, 21 May 2024 03:28:21 +0000 From: Xu Yang To: brauner@kernel.org, djwong@kernel.org, willy@infradead.org, kpm@linux-foundation.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, jun.li@nxp.com Subject: [PATCH v4 2/2] iomap: fault in smaller chunks for non-large folio mappings Date: Tue, 21 May 2024 19:36:24 +0800 Message-Id: <20240521113624.2538951-2-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240521113624.2538951-1-xu.yang_2@nxp.com> References: <20240521113624.2538951-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SI2P153CA0022.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::8) To DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8822:EE_|PAXPR04MB8606:EE_ X-MS-Office365-Filtering-Correlation-Id: b283f680-2b96-4a97-fa65-08dc794610a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|52116005|366007|38350700005; X-Microsoft-Antispam-Message-Info: mtIuQs436rEL/iPQ6cnC7nMG5A3Y0WK5ehJTqVlacpNpwpMqWdRJwY9X9GEFlG6AOE1CKDUq5VVnltqYT4MLroEdhUmkj4Bsd7TdfvSpUBZjs9SazwUKYQwchL4G3ZiWeAyT86mIviEsXwQDvZUL8EEPbn9L4wsz4/kbtQH0Nb/DXXqMQk14f9xsS8TTaFn+SmOxgA4iNv7v+WYNSeTxfQ16NPcvDJ0+kqobZdcsy6OEPfYqQdHp1uTW4tn/PAscJGoqqBqDd29nYbQZ2YHx8jQwpJgCE9K1yI+KeRaYTw3HRaryl/8YhNcu5h/dsoWZr8KAYgh06znGW89IX4VPR0ja1xGTBUnK6zP4+Au1sM3skI4uWWfSX07PfUshDDi5nLAnCnwnytvWGlOaYFCSYhDBVivYYwzcfrA8fcIQECGW4C9qG6woj0kaeQ2aTy+7Ug3TAuawhubfJnBjpHFMOkcioflSfoHlwQfbGlagFoVO6FdrvrfChQd631W7IJoymRMk6h9sm8OxdwCjyOuzdeRUsBMfXkTQYBnCQ3TxNHgY29EPg/aMhtM6nBS6s8F0DrV3QxaWSZf4O8vdPvxYlweyRLUxKDp/OI31/L8y6JbhWA8e8kDWiIGdSbfh/iOa4yjoDkD/No8RdCRJhGgI/xvg5NEf4U+WlOrRobZKoO6gkd5CQEzZ1uh4sMWgQ5pbMgTZhj8ZJtRJViu6j1zMh2AcWUhjrlC6YKqy3fccFeN+hgIy07gQYveCX1kaZiTNNqG1JZoNI6nffkIYJvSXATmdwzRVa+2J7OXQBGdHweVAkECKkKfDT+QA1u6DuAcSsfHfw5RwInfnivIdBe73Vt7ntdh8la+EqNV6EiZS78zIyO67LugMuk/Eq4EuqJvN3EO56FrEJek61v8h3vO04LE2KALrhLJtQW/e7CYKFQf4eq2uk3pOpHjVdwWevbJwcp+DGC5YMMnJK9J6YX3IE8+NjBz5T1P8S6Qq1+Rg7i2UJLcVDxjEX9sz0iGjEg1bJdlD9xLlPMC9hlKpcB7UVo+KY1EC4MdVKdOOeyPiQUTriI9yBayVHx96KvNgr6mpCGSBIaXz1Y1xGyDwJW2PvgSvEp1E3VvU10aa8IjR35SJGn+2xpdGwptsNnF5SVPdgfTmqekCKIa2zV24AA64Hm3XsMJzzMgwzJdVVkNrCDBXNWg3EZoUDmhVgx3v0XTNQCsGRQX2JEQKfZ0G48EVStZknS1FDjOqquc6d+L/ZafcyDPkTP6cYpPGLYHgxmGNfztsnpTO0h/Te0di1evaKA3Q4jA78WfIseU1dI9U+TTLcoWFMGsaqaVgBhAAIe+j/JADP1MahHmyNJT3MZqDSg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8822.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(52116005)(366007)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DZ+VDfzlbLPa3j43FmSht4mwUDXDTVZoCUwjHcrxZylmYUBvzDRdEvdyW9Bu/ysuCNdHfE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/IPMwvgdQQjdU/BoqNOjNGv/GPm+PVQkCLQyFP8ziHd8EcYCXFXZTcN+oAUKWIh5TDjql437h/tJgFJrocWlSnDAc62RfUawpTSO4ny79Kan7VeDSSRcJAwcay9VOSHgxI71BiKgJHkZLCbfBfvJkLHA1FHgwHQt/1L4akMUbTZ5L8WjG/V85HcLMsg+HSg3VDKt1cY7yDHwApYgyzu6MapHdDmUiox+xl6sZcvCX+bZr7qS5imb+CxQMuTDhhqXyhib0JTPC9DdTRYCPAjL2xMabRnYcSK9GRCMrJLnZxoACvGKgFzXEGPOxxUB7q83MmNwT0uXMQKqPlaGwDSpPCy6W4wK9JQB1HE0Xw6vgrKp80qUgeBDJq8QXxAd4rX90heMzfxZa2ygrCwpTcrQyKf+drbFR3sqNB3X7qvHYZAW9P1EwK18kQjDcZ3Nl0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b283f680-2b96-4a97-fa65-08dc794610a4 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8822.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2024 03:28:21.6777 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kXuiFbf7TgqmUIn09s4fmFe7zwhLC2ErouoZ2cUEe6zXl773XL+xRnxYsMJd9OUo70UnHiYjBIwBjiy5xUDEZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8606 Since commit (5d8edfb900d5 "iomap: Copy larger chunks from userspace"), iomap will try to copy in larger chunks than PAGE_SIZE. However, if the mapping doesn't support large folio, only one page of maximum 4KB will be created and 4KB data will be writen to pagecache each time. Then, next 4KB will be handled in next iteration. This will cause potential write performance problem. If chunk is 2MB, total 512 pages need to be handled finally. During this period, fault_in_iov_iter_readable() is called to check iov_iter readable validity. Since only 4KB will be handled each time, below address space will be checked over and over again: start end - buf, buf+2MB buf+4KB, buf+2MB buf+8KB, buf+2MB ... buf+2044KB buf+2MB Obviously the checking size is wrong since only 4KB will be handled each time. So this will get a correct chunk to let iomap work well in non-large folio case. With this change, the write speed will be stable. Tested on ARM64 device. Before: - dd if=/dev/zero of=/dev/sda bs=400K count=10485 (334 MB/s) - dd if=/dev/zero of=/dev/sda bs=800K count=5242 (278 MB/s) - dd if=/dev/zero of=/dev/sda bs=1600K count=2621 (204 MB/s) - dd if=/dev/zero of=/dev/sda bs=2200K count=1906 (170 MB/s) - dd if=/dev/zero of=/dev/sda bs=3000K count=1398 (150 MB/s) - dd if=/dev/zero of=/dev/sda bs=4500K count=932 (139 MB/s) After: - dd if=/dev/zero of=/dev/sda bs=400K count=10485 (339 MB/s) - dd if=/dev/zero of=/dev/sda bs=800K count=5242 (330 MB/s) - dd if=/dev/zero of=/dev/sda bs=1600K count=2621 (332 MB/s) - dd if=/dev/zero of=/dev/sda bs=2200K count=1906 (333 MB/s) - dd if=/dev/zero of=/dev/sda bs=3000K count=1398 (333 MB/s) - dd if=/dev/zero of=/dev/sda bs=4500K count=932 (333 MB/s) Fixes: 5d8edfb900d5 ("iomap: Copy larger chunks from userspace") Cc: stable@vger.kernel.org Reviewed-by: Darrick J. Wong Signed-off-by: Xu Yang --- Changes in v2: - fix address space description in message Changes in v3: - adjust 'chunk' and add mapping_max_folio_size() in header file as suggested by Matthew - add write performance results in commit message Changes in v4: - split mapping_max_folio_size() into a single patch 1/2 - adjust subject - add Rb tag --- fs/iomap/buffered-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 41c8f0c68ef5..c5802a459334 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -898,11 +898,11 @@ static bool iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) { loff_t length = iomap_length(iter); - size_t chunk = PAGE_SIZE << MAX_PAGECACHE_ORDER; loff_t pos = iter->pos; ssize_t total_written = 0; long status = 0; struct address_space *mapping = iter->inode->i_mapping; + size_t chunk = mapping_max_folio_size(mapping); unsigned int bdp_flags = (iter->flags & IOMAP_NOWAIT) ? BDP_ASYNC : 0; do {