From mboxrd@z Thu Jan 1 00:00:00 1970 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 A0A2FC83F17 for ; Tue, 15 Jul 2025 14:37:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41EB16B009D; Tue, 15 Jul 2025 10:37:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CF2B6B009E; Tue, 15 Jul 2025 10:37:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E5646B009F; Tue, 15 Jul 2025 10:37:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 213A16B009D for ; Tue, 15 Jul 2025 10:37:37 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DF17E80538 for ; Tue, 15 Jul 2025 14:37:36 +0000 (UTC) X-FDA: 83666752512.24.9FAC694 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf04.hostedemail.com (Postfix) with ESMTP id 26CB64000F for ; Tue, 15 Jul 2025 14:37:34 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="hkhtV5n/"; spf=pass (imf04.hostedemail.com: domain of djwong@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752590255; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ESI8G5ew9rNP/1F9ZqqvQpGQAO4Xo4Ksc68S9eGrvZE=; b=I2fkG+aRg2mm1eiY3HFjgLmRCKS63BQ2tHGHcu2cSKtN+pL4d74sYnVKG/2EKC9O7o9t3m Sz0I14nKDAgswYIiHkRD6k3K/HoELNoln8lvhSTtZ0YEHVXzHBCCP/PrBoVtGY220wEssf fgT9fEW52/fs7kY6pRgJDfSjHSue3HI= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="hkhtV5n/"; spf=pass (imf04.hostedemail.com: domain of djwong@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752590255; a=rsa-sha256; cv=none; b=c6J5mi4SFIsf2SZjGhoy+LoYsY+1ncExk479cRjq7hxNGG9ByklVO/3F8Ue9+2rb4Phf/U SaOpAY1JbqD2kHLfEFsuPErA3rwioI+A/v46VdfmHN+2UyevZ1oJXpEQlhd8E8RHabdmtK KtiDuzY49sxy63tMJe8IHGI12JmNCAA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id CF5564443E; Tue, 15 Jul 2025 14:37:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A87E8C4CEE3; Tue, 15 Jul 2025 14:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752590253; bh=4xv5/UPT8nXhMWZuxQNTUwAJ/ZNAv+qsk6EDFikuCRQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hkhtV5n/j7MM3TN5WebjgziDEpogVIRekHXMAFmCH4qnPaAQhc44rxsI8QOr0JSmJ ZoLT7k7cseFjT2FcAnSsu4oTRaDhp/JrhAKoxbyhZj9VRpPGGSp5tUFLrwMU0g7xCt PLhoJYuX1a/ySv0n7UA9mrOJ4wmYWtMiLTKy6fMlkk0cIJ2vdme+dnW38s81S7PaVR ZRlXhrDRe596qHchhv3nbtsGAAl7L/y3rYOce0M9SCGq4dK9e7vlVfmjDU1IBHxTBU iD8fXYQyMl+kzM2DLKOcCwt3rCHW61e1kHKzE3zfBIM6wFP5zZkpHDleTpJRyGAdhn bydIIM1Jgx9JA== Date: Tue, 15 Jul 2025 07:37:33 -0700 From: "Darrick J. Wong" To: Brian Foster Cc: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, hch@infradead.org, willy@infradead.org Subject: Re: [PATCH v3 6/7] iomap: remove old partial eof zeroing optimization Message-ID: <20250715143733.GO2672029@frogsfrogsfrogs> References: <20250714204122.349582-1-bfoster@redhat.com> <20250714204122.349582-7-bfoster@redhat.com> <20250715053417.GR2672049@frogsfrogsfrogs> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: 26CB64000F X-Rspamd-Server: rspam06 X-Stat-Signature: jxdtk9ujm4g5qtjewfoy1f6drdyn8irt X-HE-Tag: 1752590254-997080 X-HE-Meta: U2FsdGVkX19+s0IgB+U8qQR/Hm+vv3zQUVHSrCKShenxWHS/6U/IjRFlxUuPWxWaFS5ADQmYz8tr3mCT0uNaC2s/gpAUowcetB777/pSsnQ5KUTURTCRqg1BPlbg73MR1GL+C4zsoYwYPTafrjoKogZGaqJi5MDv840Fc1HFMawiHG96FGs65V8O9yfRuF3n6uaBcK5BSIKHah1LagM1l4wkQ6jEJ1uRHqt+2wndWIwEpRmILkxJ+bSPqKwmkZWSzRGTe8XDU9q6Txmqs+vCRLXRoZ8YMR14Oj6d4ckveByCretEmNIrE3wkY8RFMDm7FAvb86m7cBiyla3kIQxDMdn3Ohf1OORrQuZkM+wczRlZSaPiipWRn1W9yGCYevbMVzG9ppc4QHqd4ufViuaOTB639X/HghzX/fxd6ojShXfjnUb7563xtkVohLzifLNvRU3R+d5Zu/LEH+utbHpWSqiUwSe8/pgHP+nDUT01bkPzQ6XeJUiZJ7E83pqtCm+CZQhu3DzbsTSWUIHn6BvylHHD8EMdYvkD/cwp1tPLgVsUFuEtPGf9qR2m3KmfupEJVeJ1Rf74tLhHsOK1O+iyjpRK1Jvr1d2mquE3THFgdB/FwVv4VzI7Cm7DJ7suSpq+ejOVXxMPwQb8L6VwXKGKA3zkswHmWUBF+QyOn6NjoTvDEovr7X9PeujZ57fUKS24Q9Kcnu6BOEMO+mVv5qlmn/kkde3mdD/+o78/9pOFjcd+wHJBz/qYuwLUgT/wFlBFINwnXOwCjj+3bru6QsLc5k/Cykt9K9Ugn7Nw86R1tyHLg/XYVqZ4MkVzx3sqZoWs3RM10dNBT/4WgwKrg2yq/mD7ZOsxh0YfPPH6kLGb0rcoYWrdtk3cN6N3zibGYPocCPA6Ua1Pgjv4TE9wjwi32dN7V0e7QCVAC5Rd3Ckz2fFJgDha4H/PsNexlhvxgednBRyqblxWW+fPxve47Dd csFptYCh xTPFT9qFlpRwqV5wbjP161wIGkCYTxTrsRex6VGho9PcfbD5WYwGSBVzkbl6IYXgcJffuoTnCymRw6GfP5hHfnji8mlzCBknVoReum0ibXPzfb5YZo8EEwKpyf26PfE9c0BfWaDHtigwKVKfJF39kgeUPcgwzxzT+Y99w9fl6oYSnN0iqlMQjnDWdm5UoKWE6NWuKhFSbCz9sHxAybbbWNX9WPKEWP67rqft0namF5fZOxbbM21Dy8iu6jaxrBe12L1/3ghSlWAXoFxbiqTCvuBZ0ImOMHGhXez4oADJHsINs/yo= 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: On Tue, Jul 15, 2025 at 08:36:54AM -0400, Brian Foster wrote: > On Mon, Jul 14, 2025 at 10:34:17PM -0700, Darrick J. Wong wrote: > > On Mon, Jul 14, 2025 at 04:41:21PM -0400, Brian Foster wrote: > > > iomap_zero_range() optimizes the partial eof block zeroing use case > > > by force zeroing if the mapping is dirty. This is to avoid frequent > > > flushing on file extending workloads, which hurts performance. > > > > > > Now that the folio batch mechanism provides a more generic solution > > > and is used by the only real zero range user (XFS), this isolated > > > optimization is no longer needed. Remove the unnecessary code and > > > let callers use the folio batch or fall back to flushing by default. > > > > > > Signed-off-by: Brian Foster > > > Reviewed-by: Christoph Hellwig > > > > Heh, I was staring at this last Friday chasing fuse+iomap bugs in > > fallocate zerorange and straining to remember what this does. > > Is this chunk still needed if the ->iomap_begin implementation doesn't > > (or forgets to) grab the folio batch for iomap? > > > > No, the hunk removed by this patch is just an optimization. The fallback > code here flushes the range if it's dirty and retries the lookup (i.e. > picking up unwritten conversions that were pending via dirty pagecache). > That flush logic caused a performance regression in a particular > workload, so this was introduced to mitigate that regression by just > doing the zeroing for the first block or so if the folio is dirty. [1] > > The reason for removing it is more just for maintainability. XFS is > really the only user here and it is changing over to the more generic > batch mechanism, which effectively provides the same optimization, so > this basically becomes dead/duplicate code. If an fs doesn't use the > batch mechanism it will just fall back to the flush and retry approach, > which can be slower but is functionally correct. Oh ok thanks for the reminder. Reviewed-by: "Darrick J. Wong" > > My bug turned out to be a bug in my fuse+iomap design -- with the way > > iomap_zero_range does things, you have to flush+unmap, punch the range > > and zero the range. If you punch and realloc the range and *then* try > > to zero the range, the new unwritten extents cause iomap to miss dirty > > pages that fuse should've unmapped. Ooops. > > > > I don't quite follow. How do you mean it misses dirty pages? Oops, I misspoke, the folios were clean. Let's say the pagecache is sparsely populated with some folios for written space: -------fffff-------fffffff wwwwwwwwwwwwwwwwwwwwwwwwww Now you tell it to go zero range the middle. fuse's fallocate code issues the upcall to userspace, whch changes some mappings: -------fffff-------fffffff wwwwwuuuuuuuuuuuwwwwwwwwww Only after the upcall returns does the kernel try to do the pagecache zeroing. Unfortunately, the mapping changed to unwritten so iomap_zero_range doesn't see the "fffff" and leaves its contents intact. (Note: Non-iomap fuse defers everything to the fuse server so this isn't a problem if the fuse server does all the zeroing itself.) --D > Brian > > [1] Details described in the commit log of fde4c4c3ec1c ("iomap: elide > flush from partial eof zero range"). > > > --D > > > > > --- > > > fs/iomap/buffered-io.c | 24 ------------------------ > > > 1 file changed, 24 deletions(-) > > > > > > diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c > > > index 194e3cc0857f..d2bbed692c06 100644 > > > --- a/fs/iomap/buffered-io.c > > > +++ b/fs/iomap/buffered-io.c > > > @@ -1484,33 +1484,9 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, > > > .private = private, > > > }; > > > struct address_space *mapping = inode->i_mapping; > > > - unsigned int blocksize = i_blocksize(inode); > > > - unsigned int off = pos & (blocksize - 1); > > > - loff_t plen = min_t(loff_t, len, blocksize - off); > > > int ret; > > > bool range_dirty; > > > > > > - /* > > > - * Zero range can skip mappings that are zero on disk so long as > > > - * pagecache is clean. If pagecache was dirty prior to zero range, the > > > - * mapping converts on writeback completion and so must be zeroed. > > > - * > > > - * The simplest way to deal with this across a range is to flush > > > - * pagecache and process the updated mappings. To avoid excessive > > > - * flushing on partial eof zeroing, special case it to zero the > > > - * unaligned start portion if already dirty in pagecache. > > > - */ > > > - if (!iter.fbatch && off && > > > - filemap_range_needs_writeback(mapping, pos, pos + plen - 1)) { > > > - iter.len = plen; > > > - while ((ret = iomap_iter(&iter, ops)) > 0) > > > - iter.status = iomap_zero_iter(&iter, did_zero); > > > - > > > - iter.len = len - (iter.pos - pos); > > > - if (ret || !iter.len) > > > - return ret; > > > - } > > > - > > > /* > > > * To avoid an unconditional flush, check pagecache state and only flush > > > * if dirty and the fs returns a mapping that might convert on > > > -- > > > 2.50.0 > > > > > > > > > >