Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1537672lql; Wed, 13 Mar 2024 00:09:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVo5gp+h1zQf50E9+Rgo7+Vw/2F8cs4WYLtCnSHsCJ34Bp4evibOXTGrTRkDCxMQWpA+BIOGnNvSUkik9oYnA2CIsPzyCy1fK+CdGNd+g== X-Google-Smtp-Source: AGHT+IFhSoQbAJRiy6vL+zV3z07kXMWX/n9dS2z+6k8Foh2LkGQSCWMeQZ5hC372zpKkR9Wkt5kj X-Received: by 2002:a05:6a00:929c:b0:6e6:2dc9:dcbc with SMTP id jw28-20020a056a00929c00b006e62dc9dcbcmr2553447pfb.10.1710313776573; Wed, 13 Mar 2024 00:09:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710313776; cv=pass; d=google.com; s=arc-20160816; b=qCRSIu/McZ3Vw2arZPCOvyD8Aa5ZK6tSjPQSA7HcFvePOGpX4xVLiJFVj6zHQnwp++ y4zVwynFZYQCmuh36i66cuWV887ir67IUONtRS1xdgAFBt7sV3DJHrvrWkk+gTh+Ni3H T8ti1Ccg6+vgaTnTOVv2/xmyG0LlPjJGKNusUyUV9i9M6KdOW7zVn9KYA8gKDGtNFp+c ox9IxjTi7BVFGOwMUo/xDLqyQKMtDcLL1nttQ1cYaCh0VT0IXToVc8DDCP/tCnHxlsVv o/C1EEbeN5oCIWrtdt12aARF15900rJvnw1m9CBvEusbxadol1vaxPkvA0GFYctuSBuj ukIg== 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=IP11FVG2PV8+t7NEbxsJnZrj2XZmc624wPDiZvvJMdk=; fh=+dID43e+zysSUQt2Cn5xtLzOUM3ZysVQHoyNPERjLwE=; b=X4kRkm+anyfQUv4NrxJCr3VWKt+qNNETTssrMxwy2TlAdZ5A2iMHuCCR+d0jFkenSY SqCdRL5PVXI3x8abVBZxqxfKTnLqG1GfwW8CKOiopUBuOL1arh47+prH+HUuY0vkC9l2 ofN1pGMy2znc+hx6RnWyl5n/VyxTd3sLqI+vihxVp1lEa6T/K9TDRW4PkrfLe2UjUNFk 6IxMiP6/wWyB0HMNw8kzdY1okag+8aYzvYc1Y3wkXRFLVyeYUxr4cjTvX7FYtH+def+U xInauJ86jjkKiHlsbL0MRYUz0HUMkGjPSg9w43cGJL9S2BhQkdMnlu4kbrt9IMjO4aff Y7/Q==; 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-kernel+bounces-101155-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101155-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z124-20020a636582000000b005dc6d16aba7si7903972pgb.344.2024.03.13.00.09.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 00:09:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101155-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-101155-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101155-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3DDE3281C79 for ; Wed, 13 Mar 2024 07:09:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13B1D168A8; Wed, 13 Mar 2024 07:09:25 +0000 (UTC) Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (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 CB0D614A8C; Wed, 13 Mar 2024 07:09:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710313764; cv=none; b=a1u4oHILG6eK+XCOBqMXzUhVwxpNKjT4wAGIwhvuZKpz33rPh+5RQFhupEG3wDR1SdiZlfzsOPuDk7fA5X/xnyQl8HfKm4uzZxYSK2Sy+Z2xVuL0Hj+I55/LQ7sTUT7rIQUsCiQ50aRt+JbE0v8ZyAY3KmofnYof2HM+9I8BGjI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710313764; c=relaxed/simple; bh=DnVHKZQEGlZsUL1ra8rBA+RZSM3Wki43hGWrTwyDdKI=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=BeQfUgfxp/c39ZFBN6l4u63wq94jYNNPU7rdi3YTQg/nBLXaCEiWHJwmSwCTq0V3uZ3sLbbNFnfL7HulhIRBCBCLH2sJ1nJtUadUjUwhI3YGO0B6PLe+ShoTc0XJZOTBdbeSzxX7k4uTWwIQFRs35gXsxLG0ir49bvVdP1Yai90= 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.51 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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TvhT66Bn7z4f3mWM; Wed, 13 Mar 2024 15:09:14 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 886931A0172; Wed, 13 Mar 2024 15:09:18 +0800 (CST) Received: from [10.174.176.34] (unknown [10.174.176.34]) by APP1 (Coremail) with SMTP id cCh0CgBHGBEdUfFlvR42Gw--.15382S3; Wed, 13 Mar 2024 15:09:18 +0800 (CST) Subject: Re: [PATCH 3/4] iomap: don't increase i_size if it's not a write operation To: "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, hch@infradead.org, brauner@kernel.org, david@fromorbit.com, tytso@mit.edu, jack@suse.cz, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com References: <20240311122255.2637311-1-yi.zhang@huaweicloud.com> <20240311122255.2637311-4-yi.zhang@huaweicloud.com> <20240311154829.GU1927156@frogsfrogsfrogs> <4a9e607e-36d1-4ea7-1754-c443906b3a1c@huaweicloud.com> <20240312162407.GC1927156@frogsfrogsfrogs> From: Zhang Yi Message-ID: <929f44c6-68e0-1a32-26fd-63b0e87f02fc@huaweicloud.com> Date: Wed, 13 Mar 2024 15:09:17 +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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240312162407.GC1927156@frogsfrogsfrogs> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 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fC2KfnxnUUI43ZEXa 7IUbPEf5UUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ On 2024/3/13 0:24, Darrick J. Wong wrote: > On Tue, Mar 12, 2024 at 08:59:15PM +0800, Zhang Yi wrote: >> On 2024/3/11 23:48, Darrick J. Wong wrote: >>> On Mon, Mar 11, 2024 at 08:22:54PM +0800, Zhang Yi wrote: >>>> From: Zhang Yi >>>> [...] >>>> @@ -927,6 +908,24 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) >>>> copied = copy_folio_from_iter_atomic(folio, offset, bytes, i); >>>> status = iomap_write_end(iter, pos, bytes, copied, folio); >>>> >>>> + /* >>>> + * Update the in-memory inode size after copying the data into >>>> + * the page 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. >>>> + */ >>>> + old_size = iter->inode->i_size; >>>> + if (pos + status > old_size) { >>>> + i_size_write(iter->inode, pos + status); >>>> + iter->iomap.flags |= IOMAP_F_SIZE_CHANGED; >>>> + } >>>> + __iomap_put_folio(iter, pos, status, folio); >>> >>> Why is it necessary to hoist the __iomap_put_folio calls from >>> iomap_write_end into iomap_write_iter, iomap_unshare_iter, and >>> iomap_zero_iter? None of those functions seem to use it, and it makes >>> more sense to me that iomap_write_end releases the folio that >>> iomap_write_begin returned. >>> >> >> Because we have to update i_size before __iomap_put_folio() in >> iomap_write_iter(). If not, once we unlock folio, it could be raced >> by the backgroud write back which could start writing back and call >> folio_zero_segment() (please see iomap_writepage_handle_eof()) to >> zero out the valid data beyond the not updated i_size. So we >> have to move out __iomap_put_folio() out together with the i_size >> updating. > > Ahah. Please make a note of that in the comment for dunces like me. > > /* > * Update the in-memory inode size after copying the data into > * the page 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. Only once that's done can we > * unlock and release the folio. > */ > Sure.