Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp264570rdb; Thu, 30 Nov 2023 04:26:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFITd8jU1bepA80wuw6v0DSAqQZEao0NthGqD0GeuylmVjuNmOn5K8KEtFOaeucpf8u8wG8 X-Received: by 2002:ac8:507:0:b0:423:a86b:ac70 with SMTP id u7-20020ac80507000000b00423a86bac70mr16033927qtg.16.1701347210188; Thu, 30 Nov 2023 04:26:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701347210; cv=none; d=google.com; s=arc-20160816; b=UuM8CbtB8rDZ6NufWtBQ6bzWX/cFGM2Xll+Uw2/yL4Bd0N+fnU5UrvlnFSXNbAWZlp F8v5fNCG4fYZnTGylyIKBiK6irtv2w+1w+taLIUe9i+9zhmo4bqfkXm2FfhikQ0WHIO2 395kcAKco1mUJoKJn2k7q9QEd7svo0YlgDR59S45yYZqw5enCw1jJDDz6qcxcpBpULLL RB8s18pWDIqyA+VHG6iAkcbcwagi5ufdk7NKnI4/9QO2Z2U4ZYQKRp1ysyUN8ym3GrL2 vXOcY2CU7kKyJ2S1DsJwXHF4U02rGb4s2jsB8dgAuoRA/ku+yWz/1GmaPSosVaMcGtlz JR0Q== ARC-Message-Signature: i=1; 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=74ORtPCphuPuFcwbhhuPPqm0xB81eqa5IW15TMBCW6g=; fh=WB8hadsiHvDG6UT8fXpmPMFcLdghfsNPkTdDY2he0Bg=; b=WNZCpPE6yPGpkXbtU0WMnaI9xiTP/Fd5Xx/mie5Agcd0I47GKIElnM2edIKnccWtYL cU0oqS3QlEpt7TB+yX41XM4r5PUcR7cDxQs6hq6deKXPYZ1kLrwfZklgcG5duM4q/hMM bRyfLmKKYhJEmHM1ZztxPcSjMC2wGbad8tefsm0sXBmfd6r5ydvgTJ6K9PYeDSUQMPMr sya6r7+y9o+IJbxYYpYFgW3xP+OGOQwN/DTEgxVOOFan34K5YLLv1M+ni9cznzwS8mSe GVN5gpSLW/RxGwgmdWkdnpuS/gQd3dnktnWCNT+gW+CyQAUtP6O1wFEjwhGs4aw2UGcV 9jsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-238-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-238-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ch10-20020a05622a40ca00b0042377f4f464si972283qtb.647.2023.11.30.04.26.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 04:26:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-238-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-238-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-238-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EDF391C2093B for ; Thu, 30 Nov 2023 12:26:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E04574778F; Thu, 30 Nov 2023 12:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90E1C10F8; Thu, 30 Nov 2023 04:26:33 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4SgwR83CWnz4f3lwS; Thu, 30 Nov 2023 20:26:28 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 6C9E21A087A; Thu, 30 Nov 2023 20:26:30 +0800 (CST) Received: from [10.174.176.34] (unknown [10.174.176.34]) by APP1 (Coremail) with SMTP id cCh0CgDX2xF0f2hlDKFrCQ--.55161S3; Thu, 30 Nov 2023 20:26:30 +0800 (CST) Subject: Re: [RFC PATCH 12/18] iomap: don't increase i_size if it's not a write operation To: Christoph Hellwig Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, djwong@kernel.org, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com References: <20231123125121.4064694-1-yi.zhang@huaweicloud.com> <20231123125121.4064694-13-yi.zhang@huaweicloud.com> From: Zhang Yi Message-ID: <8c697498-8c29-b752-5b6b-5698d916d056@huaweicloud.com> Date: Thu, 30 Nov 2023 20:26:28 +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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CM-TRANSID:cCh0CgDX2xF0f2hlDKFrCQ--.55161S3 X-Coremail-Antispam: 1UD129KBjvJXoW7Aw1DXry7tw1UXF47try5Arb_yoW8AF1rpr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hellwig wrote: > On Thu, Nov 23, 2023 at 08:51:14PM +0800, Zhang Yi wrote: >> index fd4d43bafd1b..3b9ba390dd1b 100644 >> --- a/fs/iomap/buffered-io.c >> +++ b/fs/iomap/buffered-io.c >> @@ -852,13 +852,13 @@ static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, >> * cache. It's up to the file system to write the updated size to disk, >> * preferably after I/O completion so that no stale data is exposed. >> */ >> - if (pos + ret > old_size) { >> + if ((iter->flags & IOMAP_WRITE) && pos + ret > old_size) { >> i_size_write(iter->inode, pos + ret); >> iter->iomap.flags |= IOMAP_F_SIZE_CHANGED; >> } >> __iomap_put_folio(iter, pos, ret, folio); >> >> - if (old_size < pos) >> + if ((iter->flags & IOMAP_WRITE) && old_size < pos) >> pagecache_isize_extended(iter->inode, old_size, pos); >> if (ret < len) >> iomap_write_failed(iter->inode, pos + ret, len - ret); > > I agree with your rationale, but I hate how this code ends up > looking. In many ways iomap_write_end seems like the wrong > place to update the inode size anyway. I've not done a deep > analysis, but I think there shouldn't really be any major blocker > to only setting IOMAP_F_SIZE_CHANGED in iomap_write_end, and then > move updating i_size and calling pagecache_isize_extended to > iomap_write_iter. > Think about it in depth, I think we cannot move updating i_size to iomap_write_iter() because we have to do this under folio lock, otherwise, once we unlock folio, the writeback process could start writing back and call folio_zero_segment() to zero out the valid data beyond the unupdated i_size. Only if we move __iomap_put_folio() out together, but I suppose it's not a good way. Thanks, Yi.