mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Nanzhe Zhao <zhaonanzhe@xiaomi.com>,
	linux-f2fs-devel@lists.sourceforge.net,
	Jaegeuk Kim <jaegeuk@kernel.org>
Cc: chao@kernel.org, Barry Song <baohua@kernel.org>,
	Nanzhe Zhao <nzzhao@126.com>, Juan Yescas <jyescas@google.com>,
	Dev Jain <Dev.Jain@arm.com>,
	linux-kernel@vger.kernel.org,
	David Hildenbrand <David.Hildenbrand@arm.com>,
	Bo Zhang <zhangbo56@xiaomi.com>,
	Kalesh Singh <kaleshsingh@google.com>,
	Ryan Roberts <Ryan.Roberts@arm.com>,
	Pengfei Li <lipengfei28@xiaomi.com>
Subject: Re: [PATCH 04/14] f2fs: support atomic file large folios buffered write
Date: Thu, 27 Aug 2026 17:24:06 +0800	[thread overview]
Message-ID: <9a00f46d-1fc6-454d-9c77-89ae51266c01@kernel.org> (raw)
In-Reply-To: <20260826082641.2007658-5-zhaonanzhe@xiaomi.com>

On 8/26/26 16:26, Nanzhe Zhao wrote:
> ioctl can convert an inode with large folio support into an atomic
> file. Support large folio buffered writes for atomic files as well.
> 
> Add a large folio atomic write_begin helper that reserves COW mappings
> for the write range. For partial head and tail subpages, read the
> existing data from either the COW inode or the original inode before
> marking the subpage uptodate.
> 
> Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
> ---
>  fs/f2fs/data.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 121 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 7ce96ae02cfc..dff802725544 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -4211,6 +4211,117 @@ static int prepare_large_folio_write_begin(struct inode *inode,
>  	return 0;
>  }
>  
> +static int prepare_large_folio_atomic_write_begin(struct inode *inode,
> +		struct address_space *mapping, struct folio *folio, loff_t pos,
> +		unsigned int len)
> +{
> +	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
> +	struct inode *cow_inode = F2FS_I(inode)->cow_inode;
> +	size_t ori_off = offset_in_folio(folio, pos);
> +	size_t need_off = ori_off;
> +	pgoff_t index;
> +	int err = 0;
> +	unsigned int orig_order;
> +	bool need_balance = false;
> +
> +	len = min_t(unsigned int, len, folio_size(folio) - ori_off);
> +
> +	f2fs_ffs_find_or_alloc(folio);
> +
> +	/* Inline data must have been converted before reaching here. */
> +	f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
> +
> +	/* Reserve COW blocks for all covered 4K subpages first. */
> +	pgoff_t start_index = folio->index + (ori_off >> PAGE_SHIFT);
> +	pgoff_t end_index = folio->index +
> +		((ori_off + len - 1) >> PAGE_SHIFT);
> +
> +	for (index = start_index; index <= end_index; index++) {
> +		block_t cow_blkaddr = NULL_ADDR;
> +		bool node_changed = false;
> +		int ret;
> +
> +		ret = __find_data_block(cow_inode, index, &cow_blkaddr);
> +		if (ret)
> +			return ret;
> +		if (cow_blkaddr != NULL_ADDR)
> +			continue;
> +
> +		ret = __reserve_data_block(cow_inode, index, &cow_blkaddr,
> +					   &node_changed);
> +		if (ret)
> +			return ret;
> +
> +		inc_atomic_write_cnt(inode);

In order to not miss any logic in prepare_atomic_write_begin(), can you reuse
prepare_atomic_write_begin() as much as possible? needs to change parameters
a bit there.

	for (...) {
		err = prepare_atomic_write_begin(sbi, inode, index, pos, len, ...);
		...
	}

> +		need_balance |= node_changed;
> +	}
> +
> +	if (need_balance && !IS_NOQUOTA(inode) &&
> +				       has_not_enough_free_secs(sbi, 0, 0)) {
> +		orig_order = folio_order(folio);
> +		folio_unlock(folio);
> +		f2fs_balance_fs(sbi, true);
> +		folio_lock(folio);
> +		if (unlikely(folio->mapping != mapping ||
> +			     folio_order(folio) != orig_order))
> +			return -EAGAIN;
> +	}
> +
> +	if (folio_test_uptodate(folio) || len == folio_size(folio))
> +		return 0;
> +
> +	/* Then read partial 4K subpages. */
> +	while (find_next_valid_block(folio, ori_off, &need_off, len)) {

Can we record first and last blkaddr in first loop of
prepare_large_folio_atomic_write_begin(), and then we can avoid lot of complexity
below to find target blkaddr?

We really don't want to miss any corner case of atomic write + large folio, please
consider that.

Thanks,

> +		size_t off;
> +		block_t cow_blkaddr = NULL_ADDR;
> +		block_t ori_blkaddr = NULL_ADDR;
> +		struct inode *read_inode = NULL;
> +		block_t read_blkaddr = NULL_ADDR;
> +
> +		index = folio->index + (need_off >> PAGE_SHIFT);
> +		off = offset_in_folio(folio, index << PAGE_SHIFT);
> +
> +		err = __find_data_block(cow_inode, index, &cow_blkaddr);
> +		if (err)
> +			return err;
> +
> +		if (__is_valid_data_blkaddr(cow_blkaddr)) {
> +			if (!f2fs_is_valid_blkaddr(sbi, cow_blkaddr,
> +						  DATA_GENERIC_ENHANCE_READ))
> +				return -EFSCORRUPTED;
> +			read_inode = cow_inode;
> +			read_blkaddr = cow_blkaddr;
> +		} else if (is_inode_flag_set(inode, FI_ATOMIC_REPLACE)) {
> +			folio_zero_segment(folio, off, off + PAGE_SIZE);
> +			f2fs_ffs_mark_subrange_uptodate(folio, off, PAGE_SIZE);
> +			continue;
> +		} else {
> +			err = __find_data_block(inode, index, &ori_blkaddr);
> +			if (err)
> +				return err;
> +
> +			if (!__is_valid_data_blkaddr(ori_blkaddr)) {
> +				folio_zero_segment(folio, off, off + PAGE_SIZE);
> +				f2fs_ffs_mark_subrange_uptodate(folio, off, PAGE_SIZE);
> +				continue;
> +			}
> +
> +			if (!f2fs_is_valid_blkaddr(sbi, ori_blkaddr,
> +						  DATA_GENERIC_ENHANCE_READ))
> +				return -EFSCORRUPTED;
> +			read_inode = inode;
> +			read_blkaddr = ori_blkaddr;
> +		}
> +
> +		err = f2fs_submit_page_read_sync(read_inode, folio,
> +						 index, read_blkaddr);
> +		if (err)
> +			return err;
> +	}
> +
> +	return 0;
> +}
> +
>  static int f2fs_write_begin(const struct kiocb *iocb,
>  			    struct address_space *mapping,
>  			    loff_t pos, unsigned len, struct folio **foliop,
> @@ -4282,7 +4393,7 @@ static int f2fs_write_begin(const struct kiocb *iocb,
>  
>  	*foliop = folio;
>  
> -	if (f2fs_is_atomic_file(inode))
> +	if (f2fs_is_atomic_file(inode) && !folio_test_large(folio))
>  		err = prepare_atomic_write_begin(sbi, folio, pos, len,
>  					&blkaddr, &need_balance);
>  	else if (!folio_test_large(folio))
> @@ -4307,10 +4418,18 @@ static int f2fs_write_begin(const struct kiocb *iocb,
>  	f2fs_folio_wait_writeback(folio, DATA, false, true);
>  
>  	if (folio_test_large(folio)) {
> -		err = prepare_large_folio_write_begin(inode,
> +		if (f2fs_is_atomic_file(inode))
> +			err = prepare_large_folio_atomic_write_begin(inode,
> +					mapping, folio, pos, len);
> +		else
> +			err = prepare_large_folio_write_begin(inode,
>  					folio, pos, len);
>  		if (!err)
>  			return 0;
> +		if (err == -EAGAIN) {
> +			f2fs_folio_put(folio, true);
> +			goto repeat;
> +		}
>  		goto put_folio;
>  	}
>  


  reply	other threads:[~2026-08-27  9:24 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26  8:26 [PATCH 00/14] f2fs: support & optimize large folios for writable files Nanzhe Zhao
2026-08-26  8:26 ` [PATCH 01/14] f2fs: extend folio state for large folio write path Nanzhe Zhao
2026-08-27  6:57   ` Chao Yu
2026-08-27 20:51     ` [f2fs-dev] " Daeho Jeong
2026-08-26  8:26 ` [PATCH 02/14] f2fs: carry subpage offset and count in write IO Nanzhe Zhao
2026-08-27  7:16   ` Chao Yu
2026-08-27 21:06     ` [f2fs-dev] " Daeho Jeong
2026-08-26  8:26 ` [PATCH 03/14] f2fs: support regular file buffered writes on large folios Nanzhe Zhao
2026-08-27  8:56   ` Chao Yu
2026-08-27 21:13     ` [f2fs-dev] " Daeho Jeong
2026-08-26  8:26 ` [PATCH 04/14] f2fs: support atomic file large folios buffered write Nanzhe Zhao
2026-08-27  9:24   ` Chao Yu [this message]
2026-08-26  8:26 ` [PATCH 05/14] f2fs: support large folio writeback Nanzhe Zhao
2026-08-27 11:17   ` Chao Yu
2026-08-27 22:39     ` [f2fs-dev] " Daeho Jeong
2026-08-26  8:26 ` [PATCH 06/14] f2fs: prepare mmap write faults for large folios Nanzhe Zhao
2026-08-27 12:36   ` Chao Yu
2026-08-28 17:18     ` [f2fs-dev] " Daeho Jeong
2026-08-26  8:26 ` [PATCH 07/14] f2fs: make GC migration large-folio aware Nanzhe Zhao
2026-08-28 17:20   ` [f2fs-dev] " Daeho Jeong
2026-08-26  8:26 ` [PATCH 08/14] f2fs: optimize small block size large folio read Nanzhe Zhao
2026-08-26  8:26 ` [PATCH 09/14] f2fs: support partial uptodate " Nanzhe Zhao
2026-08-26  8:26 ` [PATCH 10/14] f2fs: handle partial truncate of large folio dirty subpages Nanzhe Zhao
2026-08-26 13:09 ` [PATCH 11/14] f2fs: fix zeroing paths for large folios Nanzhe Zhao
2026-08-26 13:09 ` [PATCH 12/14] f2fs: handle block cloning within the same large folio Nanzhe Zhao
2026-08-26 13:09 ` [PATCH 13/14] f2fs: allow large folio support to writeable files Nanzhe Zhao
2026-08-28 17:44   ` [f2fs-dev] " Daeho Jeong
2026-08-26 13:09 ` [PATCH 14/14] f2fs: make compressed files compatible with large folio Nanzhe Zhao
2026-08-28 17:52   ` [f2fs-dev] " Daeho Jeong

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=9a00f46d-1fc6-454d-9c77-89ae51266c01@kernel.org \
    --to=chao@kernel.org \
    --cc=David.Hildenbrand@arm.com \
    --cc=Dev.Jain@arm.com \
    --cc=Ryan.Roberts@arm.com \
    --cc=baohua@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=jyescas@google.com \
    --cc=kaleshsingh@google.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lipengfei28@xiaomi.com \
    --cc=nzzhao@126.com \
    --cc=zhangbo56@xiaomi.com \
    --cc=zhaonanzhe@xiaomi.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

all inboxes | Powered by JetHome®