Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1293800lqo; Fri, 17 May 2024 19:01:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX/QNY1K5ggy977/JIDWuHkaEv9yALwb6NtnXRZx62PI+MUIwX+0edeDka4O6NQuu5A7cxa9Ym+aQBBRZK2hJ08G0DdL5uuQHu+mHsUDQ== X-Google-Smtp-Source: AGHT+IHh7Y1W82YmUuINosbmxW5r8rHobueU/3zQ3KrHbU5Mn2LzUxalH7OrKk+ASjVEc0rZcGKc X-Received: by 2002:a17:906:33d0:b0:a5a:1562:518c with SMTP id a640c23a62f3a-a5a2d66a7eamr1514849066b.48.1715997684491; Fri, 17 May 2024 19:01:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715997684; cv=pass; d=google.com; s=arc-20160816; b=gYPj8w5q9zyrb6cs2TkrU7WDE5xM1z0iQ62Q+AI5BzS1sB7CpS1ObXt/XLf/jeGJFR 4g7jftKOhAOT5nsQcYr+39THY/QS4qmBonOmRnzyxH1IpVQknwuVuL+UBYlbsZJ95Vyt ATzOc2X2sss1EeMPmPOXQ2DrTQW8MzvHOjt58DUu9Gi73J12HGqrIiYmbAHfvLsmGL+7 jQ9xDfbMtkq5ZVg314diPqpLjF3udQ1vw+sNS6jf/dSVLwpNRmeT/zqxZx8mQYO3QZ6r pD4VAtzkTil15qETpMlz8L0yo+9GYZrfScxWLgRgOTCVU6nhb1GZrUvHYBVM3B5zjKD1 g0gw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=I98PRndqOvnQkNnLwK2xht1WYTg2QVmGODPa/Nu4/W8=; fh=iu489ta4ITrjdec2Erdblz1OEo+oNURxQ8n7/Neke3s=; b=R1JQrK+aD3wsk6Qp8DtZMvKBAw0JP+HcXq/NveaKD2ZfCRqs+0g7ZKpnqSWQt+Of0f 4AqtfXU/5he7zr1Iql9BVMvoA3/oTw6OLubLtKFFKf7wHjxTihWk7eWjNcqo6SkLfpfz 75vk3dxeu0IdwA85/ubP1foY63LTPBCnZYhTyfKmSfRs9eKFuiWUK6+m/5cZopFolN3H uMCBiYcw30uXmV2dQsLHptul96NlTOajEgC3Y427xLelyhwCyWJvRNPyDyxtjLg5P+go EIG81gVgha1+4ltxUgLECvk9P+iM9Q8zZnVsRTf8EEwghm0Z5Juqy4DWY17BDZa7CKN8 KGCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2566-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2566-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5cdd41ef08si309936766b.40.2024.05.17.19.01.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 19:01:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2566-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2566-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2566-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0D83D1F220B9 for ; Sat, 18 May 2024 02:01:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E44A86AA7; Sat, 18 May 2024 02:01:13 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (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 C6A6B10E5; Sat, 18 May 2024 02:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715997673; cv=none; b=NMUIne2BDSOIMW42GNGGFIzVlPH2Ve5yYkr9m7pJBjcjuZwPrXwsFU6UztSIs01nUJh0a1xrfR2CyojGVLqMKXLS4KuWgasOIuuZWyz9syOUlYLsJSNdnv8pT1SXrDW4AyGWFf3fNfTW+N5pGnRtSmoVacE1odhCF3nei+K5lGI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715997673; c=relaxed/simple; bh=W+N7bDWaP8vymfF5B5R5X+wCEHlotFJrTVJmPP7Nhtg=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=risFDVLkKHVjd5DFzbIq7C2E8DpEIpQUr9in8g8KZ1Jnxc+uAqjGdlXcd09Nkw2aXUYsZKLt7+kKXn12mGHpNnrtYvLtW3zdkNMlN6MsX7fXeQYqo1YboJInNrt/nRhh0pk+90pbIyxYzwsxz9b2AvNE/Oyc8w5xZmhANAMzCIg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Vh6Vx66wGz4f3jrg; Sat, 18 May 2024 10:00:57 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 9AF1F1A08FC; Sat, 18 May 2024 10:01:06 +0800 (CST) Received: from [10.174.179.80] (unknown [10.174.179.80]) by APP2 (Coremail) with SMTP id Syh0CgBXfA_gC0hmjqAhNQ--.5912S3; Sat, 18 May 2024 10:01:06 +0800 (CST) Subject: Re: [PATCH v3 1/3] iomap: pass blocksize to iomap_truncate_page() To: "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, hch@infradead.org, brauner@kernel.org, david@fromorbit.com, chandanbabu@kernel.org, jack@suse.cz, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com References: <20240517111355.233085-1-yi.zhang@huaweicloud.com> <20240517111355.233085-2-yi.zhang@huaweicloud.com> <20240517172925.GB360919@frogsfrogsfrogs> From: Zhang Yi Message-ID: Date: Sat, 18 May 2024 10:01:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240517172925.GB360919@frogsfrogsfrogs> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CM-TRANSID:Syh0CgBXfA_gC0hmjqAhNQ--.5912S3 X-Coremail-Antispam: 1UD129KBjvJXoWxXF45WryUAFW5WF1fGr1xXwb_yoWrXrW5pF 1vkF45CFs7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On Fri, May 17, 2024 at 07:13:53PM +0800, Zhang Yi wrote: >> From: Zhang Yi >> >> iomap_truncate_page() always assumes the block size of the truncating >> inode is i_blocksize(), this is not always true for some filesystems, >> e.g. XFS does extent size alignment for realtime inodes. Drop this >> assumption and pass the block size for zeroing into >> iomap_truncate_page(), allow filesystems to indicate the correct block >> size. >> >> Suggested-by: Dave Chinner >> Signed-off-by: Zhang Yi >> --- >> fs/iomap/buffered-io.c | 13 +++++++++---- >> fs/xfs/xfs_iomap.c | 3 ++- >> include/linux/iomap.h | 4 ++-- >> 3 files changed, 13 insertions(+), 7 deletions(-) >> >> diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c >> index 0926d216a5af..a0a0ac2c659c 100644 >> --- a/fs/iomap/buffered-io.c >> +++ b/fs/iomap/buffered-io.c >> @@ -17,6 +17,7 @@ >> #include >> #include >> #include >> +#include >> #include "trace.h" >> >> #include "../internal.h" >> @@ -1445,11 +1446,15 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, >> EXPORT_SYMBOL_GPL(iomap_zero_range); >> >> int >> -iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, >> - const struct iomap_ops *ops) >> +iomap_truncate_page(struct inode *inode, loff_t pos, unsigned int blocksize, >> + bool *did_zero, const struct iomap_ops *ops) >> { >> - unsigned int blocksize = i_blocksize(inode); >> - unsigned int off = pos & (blocksize - 1); >> + unsigned int off; >> + >> + if (is_power_of_2(blocksize)) >> + off = pos & (blocksize - 1); >> + else >> + div_u64_rem(pos, blocksize, &off); > > I wish this was a helper in math64.h somewhere. > > static inline u32 rem_u64(u64 dividend, u32 divisor) > { > if (likely(is_power_of_2(divisor))) > return dividend & (divisor - 1); > > return dividend % divisor; > } > > That way we skip the second division in div_u64_rem entirely, and the > iomap/dax code becomes: > > unsigned int off = rem_u64(pos, blocksize); /* pos in block */ > > Otherwise this looks like a straightforward mechanical change to me. > Yeah, we do need this helper. Thanks, Yi. > >> >> /* Block boundary? Nothing to do */ >> if (!off) >> diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c >> index 2857ef1b0272..31ac07bb8425 100644 >> --- a/fs/xfs/xfs_iomap.c >> +++ b/fs/xfs/xfs_iomap.c >> @@ -1467,10 +1467,11 @@ xfs_truncate_page( >> bool *did_zero) >> { >> struct inode *inode = VFS_I(ip); >> + unsigned int blocksize = i_blocksize(inode); >> >> if (IS_DAX(inode)) >> return dax_truncate_page(inode, pos, did_zero, >> &xfs_dax_write_iomap_ops); >> - return iomap_truncate_page(inode, pos, did_zero, >> + return iomap_truncate_page(inode, pos, blocksize, did_zero, >> &xfs_buffered_write_iomap_ops); >> } >> diff --git a/include/linux/iomap.h b/include/linux/iomap.h >> index 6fc1c858013d..d67bf86ec582 100644 >> --- a/include/linux/iomap.h >> +++ b/include/linux/iomap.h >> @@ -273,8 +273,8 @@ int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, >> const struct iomap_ops *ops); >> int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, >> bool *did_zero, const struct iomap_ops *ops); >> -int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, >> - const struct iomap_ops *ops); >> +int iomap_truncate_page(struct inode *inode, loff_t pos, unsigned int blocksize, >> + bool *did_zero, const struct iomap_ops *ops); >> vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, >> const struct iomap_ops *ops); >> int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, >> -- >> 2.39.2 >> >>