From: Jan Kara <jack@suse.cz>
To: Zhang Yi <yi.zhang@huaweicloud.com>
Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, tytso@mit.edu,
adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com,
chengzhihao1@huawei.com, yukuai3@huawei.com,
yangerkun@huawei.com
Subject: Re: [PATCH v4 03/10] ext4: don't write back data before punch hole in nojournal mode
Date: Mon, 16 Dec 2024 16:02:22 +0100 [thread overview]
Message-ID: <20241216150222.vrpdnm7ls4bretxl@quack3> (raw)
In-Reply-To: <20241216013915.3392419-4-yi.zhang@huaweicloud.com>
On Mon 16-12-24 09:39:08, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
>
> There is no need to write back all data before punching a hole in
> non-journaled mode since it will be dropped soon after removing space.
> Therefore, the call to filemap_write_and_wait_range() can be eliminated.
> Besides, similar to ext4_zero_range(), we must address the case of
> partially punched folios when block size < page size. It is essential to
> remove writable userspace mappings to ensure that the folio can be
> faulted again during subsequent mmap write access.
>
> In journaled mode, we need to write dirty pages out before discarding
> page cache in case of crash before committing the freeing data
> transaction, which could expose old, stale data, even if synchronization
> has been performed.
>
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/ext4/inode.c | 18 +++++-------------
> 1 file changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index bf735d06b621..a5ba2b71d508 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4018,17 +4018,6 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
>
> trace_ext4_punch_hole(inode, offset, length, 0);
>
> - /*
> - * Write out all dirty pages to avoid race conditions
> - * Then release them.
> - */
> - if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
> - ret = filemap_write_and_wait_range(mapping, offset,
> - offset + length - 1);
> - if (ret)
> - return ret;
> - }
> -
> inode_lock(inode);
>
> /* No need to punch hole beyond i_size */
> @@ -4090,8 +4079,11 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
> ret = ext4_update_disksize_before_punch(inode, offset, length);
> if (ret)
> goto out_dio;
> - truncate_pagecache_range(inode, first_block_offset,
> - last_block_offset);
> +
> + ret = ext4_truncate_page_cache_block_range(inode,
> + first_block_offset, last_block_offset + 1);
> + if (ret)
> + goto out_dio;
> }
>
> if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
> --
> 2.46.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-12-16 15:02 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-16 1:39 [PATCH v4 00/10] ext4: clean up and refactor fallocate Zhang Yi
2024-12-16 1:39 ` [PATCH v4 01/10] ext4: remove writable userspace mappings before truncating page cache Zhang Yi
2024-12-16 15:00 ` Jan Kara
2024-12-17 7:05 ` Zhang Yi
2024-12-16 15:15 ` Matthew Wilcox
2024-12-17 7:38 ` Zhang Yi
2024-12-18 9:56 ` Ojaswin Mujoo
2024-12-18 13:02 ` Zhang Yi
2024-12-19 7:19 ` Ojaswin Mujoo
2024-12-16 1:39 ` [PATCH v4 02/10] ext4: don't explicit update times in ext4_fallocate() Zhang Yi
2024-12-18 9:58 ` Ojaswin Mujoo
2024-12-16 1:39 ` [PATCH v4 03/10] ext4: don't write back data before punch hole in nojournal mode Zhang Yi
2024-12-16 15:02 ` Jan Kara [this message]
2024-12-17 14:31 ` Ojaswin Mujoo
2024-12-17 14:50 ` Ojaswin Mujoo
2024-12-18 7:10 ` Zhang Yi
2024-12-18 10:13 ` Ojaswin Mujoo
2024-12-16 1:39 ` [PATCH v4 04/10] ext4: refactor ext4_punch_hole() Zhang Yi
2024-12-16 15:07 ` Jan Kara
2024-12-18 10:17 ` Ojaswin Mujoo
2024-12-18 13:13 ` Zhang Yi
2024-12-19 7:11 ` Ojaswin Mujoo
2024-12-16 1:39 ` [PATCH v4 05/10] ext4: refactor ext4_zero_range() Zhang Yi
2024-12-16 15:24 ` Jan Kara
2024-12-19 7:12 ` Ojaswin Mujoo
2024-12-16 1:39 ` [PATCH v4 06/10] ext4: refactor ext4_collapse_range() Zhang Yi
2024-12-18 10:18 ` Ojaswin Mujoo
2024-12-16 1:39 ` [PATCH v4 07/10] ext4: refactor ext4_insert_range() Zhang Yi
2024-12-18 10:18 ` Ojaswin Mujoo
2024-12-16 1:39 ` [PATCH v4 08/10] ext4: factor out ext4_do_fallocate() Zhang Yi
2024-12-18 10:18 ` Ojaswin Mujoo
2024-12-16 1:39 ` [PATCH v4 09/10] ext4: move out inode_lock into ext4_fallocate() Zhang Yi
2024-12-18 10:19 ` Ojaswin Mujoo
2024-12-16 1:39 ` [PATCH v4 10/10] ext4: move out common parts " Zhang Yi
2024-12-18 10:20 ` Ojaswin Mujoo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241216150222.vrpdnm7ls4bretxl@quack3 \
--to=jack@suse.cz \
--cc=adilger.kernel@dilger.ca \
--cc=chengzhihao1@huawei.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yi.zhang@huaweicloud.com \
--cc=yukuai3@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox