Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp715727lqp; Wed, 22 May 2024 19:00:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVlCki5giyc3y8TnIObGNdaPcpIlnDjGCUZdomrwjQjY5yvpxjZOa9RjELXJzPbQZkgNzOL4Njmtf9w7k+HDgBXSgH1YsyUSjHwWByAmg== X-Google-Smtp-Source: AGHT+IETXCFqgpFWMGBs8l/M9CFwpp5jHwCy+XSj4W14gMfiXdDeRgu8Ik11O4+O4nUxtKQd3B9U X-Received: by 2002:a17:902:c950:b0:1eb:788:b424 with SMTP id d9443c01a7336-1f31c9dc0a1mr39389275ad.43.1716429619909; Wed, 22 May 2024 19:00:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716429619; cv=pass; d=google.com; s=arc-20160816; b=DkSIvjIZ+Ml/j24By1GJ192pMiHyBRcoA0XvwnKcNhaXJ3MXCTHdq7Jiafn7zNZSlm +BgGUqaLquXgyg8tllbUN0yxFxb4sAYW/PhXlscHMMJMElrB+Qn0r/ChgwfekDaHu0Xx Ta3nWzsIJjltsf6zAYyU/QQ/2TY6nJHCSC7JHg5IxN/iWUiKM/DV/Xg8BUChEAAEMzy8 y9HzMXu0zwNKHz01ITxa1LJ1EHif7CZh/1GvSSEuG5QxrB3H2DPyDbL25/jpNwX5sMK1 uTzOV5LPYrFlNCEk7KmBfj5MzOBgfKp1qDNQrFzeiJPyCyoRH1XulyeLeRMqf/fMe8UM U2jQ== 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=m9HYsDlgu+HdBDpm7yeK4ghAruBpAhRSIJladZK4UPw=; fh=nU5+XermzTdnHkLyZ4SXDfAqXv1t+UjCig9N4qy6HJM=; b=c8+JQCr7s/Yus36WEhurkTFVvkwcWKpusFt2B8lKnXhQLVhCEWPhR49cb7mYVaL74I hVKctrNNMXsnx7TcD5xXch8LlkdvNq0oq/iyi1MS0pa6nXnvAGCqEqnY982KtHHnNMCH aHBg5rmFpzwYZuzDwuf3ZmKOHWQ3Aq03sNQjs7UFCMoLUEv2iF0ttNZJ4cjtFEHY09TW 2ZO/USoHLt3Ucs5sdoWWxd0jfVyidYJX4+faxrTv5A7seJOBmVACPyE9fm1f/1WkxDve ggimWB/+Notv6+T1tfUufXQIVkBl/NiiIgZwAH203uCNRXjv5b3FVjLjICuOaJrX2hEt klhg==; 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-2632-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2632-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f33d5b6f1esi3866145ad.278.2024.05.22.19.00.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 19:00:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2632-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2632-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2632-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 124842828AF for ; Thu, 23 May 2024 02:00:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2CB11878; Thu, 23 May 2024 02:00:11 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [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 7CECD6FB9; Thu, 23 May 2024 02:00:08 +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=1716429611; cv=none; b=O002i80YUmthVFMHIxCnArDud8l6unHvgL6afQwx1sZPmqDEnSuMhlj6gSj5naJyFtsEqBTj1u8S/p8Kbma36a94wf6pQVmRAR4LMxYtLQaSBeVfaxQwPYZjq9/3dFINccCQnD4TDR0lFTnc3L8clz4ZqYHsK+6BPfibbsP68cs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716429611; c=relaxed/simple; bh=nhCPewS1z5PaPTyemrch/Z3VzSgGoYpoFUicHPWxQVY=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=H0t5zkbJI8FVlKV6zWEzxI0l6qrGSW+aJ13OuVQ5p0DObiTHfNud9oLgzkq7mj/0mZ2MdzMg2SPqSIPLMXBroaxs+1SxQedrM1mNns1lrfNItyaej+bQ9jQhIavMmED6Mu1DjhDd4uqXTawSgf6O7zDz22OTofKcm/zDfgU+nKc= 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.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VlBFV2NwWz4f3jQd; Thu, 23 May 2024 09:59:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 255B11A0CD9; Thu, 23 May 2024 10:00:04 +0800 (CST) Received: from [10.174.179.80] (unknown [10.174.179.80]) by APP2 (Coremail) with SMTP id Syh0CgCnyw4io05myMQANw--.37203S3; Thu, 23 May 2024 10:00:03 +0800 (CST) Subject: Re: [PATCH v3 3/3] xfs: correct the zeroing truncate range To: Dave Chinner Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, djwong@kernel.org, hch@infradead.org, brauner@kernel.org, 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-4-yi.zhang@huaweicloud.com> <122ab6ed-147b-517c-148d-7cb35f7f888b@huaweicloud.com> From: Zhang Yi Message-ID: <92cec08a-7fe7-1cc7-7a39-7f3d5fbc087b@huaweicloud.com> Date: Thu, 23 May 2024 10:00:02 +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:Syh0CgCnyw4io05myMQANw--.37203S3 X-Coremail-Antispam: 1UD129KBjvJXoWxXr13urW3Cw1xAr45Wr1Utrb_yoW5Cry8pF WUGa4UKr4kA3yDC34IyFn2qw1Fyw1rJrW8uryrtw12kas8X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 2024/5/21 10:38, Dave Chinner wrote: >>> We can do all this with a single writeback operation if we are a >>> little bit smarter about the order of operations we perform and we >>> are a little bit smarter in iomap about zeroing dirty pages in the >>> page cache: >>> >>> 1. change iomap_zero_range() to do the right thing with >>> dirty unwritten and cow extents (the patch I've been working >>> on). >>> >>> 2. pass the range to be zeroed into iomap_truncate_page() >>> (the fundamental change being made here). >>> >>> 3. zero the required range *through the page cache* >>> (iomap_zero_range() already does this). >>> >>> 4. write back the XFS inode from ip->i_disk_size to the end >>> of the range zeroed by iomap_truncate_page() >>> (xfs_setattr_size() already does this). >>> >>> 5. i_size_write(newsize); >>> >>> 6. invalidate_inode_pages2_range(newsize, -1) to trash all >>> the page cache beyond the new EOF without doing any zeroing >>> as we've already done all the zeroing needed to the page >>> cache through iomap_truncate_page(). >>> >>> >>> The patch I'm working on for step 1 is below. It still needs to be >>> extended to handle the cow case, but I'm unclear on how to exercise >>> that case so I haven't written the code to do it. The rest of it is >>> just rearranging the code that we already use just to get the order >>> of operations right. The only notable change in behaviour is using >>> invalidate_inode_pages2_range() instead of truncate_pagecache(), >>> because we don't want the EOF page to be dirtied again once we've >>> already written zeroes to disk.... >>> >> >> Indeed, this sounds like the best solution. Since Darrick recommended >> that we could fix the stale data exposure on realtime inode issue by >> convert the tail extent to unwritten, I suppose we could do this after >> fixing the problem. > > We also need to fix the truncate issue for the upcoming forced > alignment feature (for atomic writes), and in that case we are > required to write zeroes to the entire tail extent. i.e. forced > alignment does not allow partial unwritten extent conversion of > the EOF extent. > Yes, right. I noticed that feature also needs to fix. > Hence I think we want to fix the problem by zeroing the entire EOF > extent first, then optimise the large rtextsize case to use > unwritten extents if that tail zeroing proves to be a performance > issue. > > I say "if" because the large rtextsize case will still need to write > zeroes for the fsb that spans EOF. Adding conversion of the rest of > the extent to unwritten may well be more expensive (in terms of both > CPU and IO requirements for the transactional metadata updates) than > just submitting a slightly larger IO containing real zeroes and > leaving it as a written extent.... > Yeah, if the rtextsize if not large (in most cases), I'm pretty sure that writing zeros would better. If the rtextsize is large enough, I think it deserves a performance test. Thanks, Yi.