Linux-f2fs-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: Nanzhe Zhao <zhaonanzhe@xiaomi.com>,
	linux-f2fs-devel@lists.sourceforge.net,
	Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Barry Song <baohua@kernel.org>, 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>,
	Nanzhe Zhao <nzzhao@126.com>, Pengfei Li <lipengfei28@xiaomi.com>,
	Ryan Roberts <Ryan.Roberts@arm.com>
Subject: Re: [f2fs-dev] [PATCH 11/14] f2fs: fix zeroing paths for large folios
Date: Mon, 31 Aug 2026 15:56:04 +0800	[thread overview]
Message-ID: <3409f516-13a1-4489-ac7d-501936bc0dce@kernel.org> (raw)
In-Reply-To: <20260826130916.2231342-1-zhaonanzhe@xiaomi.com>

On 8/26/26 21:09, Nanzhe Zhao wrote:
> Several f2fs zeroing paths still use PAGE_SIZE based offsets after
> a file mapping can contain large folios.  This is fine for order-0
> folios, but it zeros the wrong range once the target block is not at
> offset 0 in a large folio.
> 
> Use offset_in_folio() to translate the file block index to the folio
> offset before zeroing data in truncate_partial_data_page(), fill_zero(),
> and f2fs_get_new_data_folio().
> 
> Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
> ---
>   fs/f2fs/data.c | 13 ++++++++++---
>   fs/f2fs/f2fs.h |  1 +
>   fs/f2fs/file.c | 27 ++++++++++++++++++++++-----
>   3 files changed, 33 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 15774e8e8795..0b167b14a9a5 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -1582,9 +1582,16 @@ struct folio *f2fs_get_new_data_folio(struct inode *inode,
>   		goto got_it;
>   
>   	if (dn.data_blkaddr == NEW_ADDR) {
> -		folio_zero_segment(folio, 0, folio_size(folio));
> -		if (!folio_test_uptodate(folio))
> +		size_t off = offset_in_folio(folio,
> +					(loff_t)index << PAGE_SHIFT);
> +
> +		folio_zero_segment(folio, off, off + PAGE_SIZE);
> +		if (folio_test_large(folio)) {
> +			f2fs_ffs_find_or_alloc(folio);
> +			f2fs_ffs_mark_subrange_uptodate(folio, off, PAGE_SIZE);
> +		} else if (!folio_test_uptodate(folio)) {
>   			folio_mark_uptodate(folio);
> +		}
>   	} else {
>   		f2fs_folio_put(folio, true);
>   
> @@ -2670,7 +2677,7 @@ static bool __ffs_mark_subrange_uptodate(struct folio *folio,
>   	return bitmap_full(ffs->state, nr_subpages);
>   }
>   
> -static void f2fs_ffs_mark_subrange_uptodate(struct folio *folio, size_t offset,
> +void f2fs_ffs_mark_subrange_uptodate(struct folio *folio, size_t offset,
>   				       size_t len)
>   {
>   	struct f2fs_folio_state *ffs;
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 0ffbe2bd04c8..6ae249bf9aa1 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -4330,6 +4330,7 @@ struct folio *f2fs_get_lock_data_folio(struct inode *inode, pgoff_t index,
>   			bool for_write);
>   struct folio *f2fs_get_new_data_folio(struct inode *inode,
>   			struct folio *ifolio, pgoff_t index, bool new_i_size);
> +void f2fs_ffs_mark_subrange_uptodate(struct folio *folio, size_t offset, size_t len);
>   int f2fs_do_write_data_page(struct f2fs_io_info *fio);
>   int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag);
>   int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 02d687527241..4272013dbe38 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -811,12 +811,12 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
>   static int truncate_partial_data_page(struct inode *inode, u64 from,
>   								bool cache_only)
>   {
> -	loff_t offset = from & (PAGE_SIZE - 1);
>   	pgoff_t index = from >> PAGE_SHIFT;
>   	struct address_space *mapping = inode->i_mapping;
>   	struct folio *folio;
> +	size_t folio_off;
>   
> -	if (!offset && !cache_only)
> +	if (!(from & (PAGE_SIZE - 1)) && !cache_only)
>   		return 0;
>   
>   	if (cache_only) {
> @@ -834,12 +834,21 @@ static int truncate_partial_data_page(struct inode *inode, u64 from,

Actually, I think it tries to truncate partial *data block* post EOF.

>   		return PTR_ERR(folio) == -ENOENT ? 0 : PTR_ERR(folio);
>   truncate_out:
>   	f2fs_folio_wait_writeback(folio, DATA, true, true);
> -	folio_zero_segment(folio, offset, folio_size(folio));
> +	folio_off = offset_in_folio(folio, from);
> +	folio_zero_segment(folio, folio_off, folio_size(folio));
>   
>   	/* An encrypted inode should have a key and truncate the last page. */
>   	f2fs_bug_on(F2FS_I_SB(inode), cache_only && IS_ENCRYPTED(inode));
> -	if (!cache_only)
> +	if (!cache_only) {
> +		if (folio_test_large(folio)) {
> +			f2fs_ffs_find_or_alloc(folio);
> +			f2fs_ffs_mark_subrange_uptodate(folio, folio_off,
> +					folio_size(folio) - folio_off);
> +			f2fs_ffs_mark_subrange_dirty(folio, folio_off,
> +					folio_size(folio) - folio_off);

So I guess we can only mark uptodate/dirty in ffs in extent of (folio_off, PAGE_SIZE)?

> +		}
>   		folio_mark_dirty(folio);
> +	}
>   	f2fs_folio_put(folio, true);
>   	return 0;
>   }
> @@ -1310,6 +1319,7 @@ static int fill_zero(struct inode *inode, pgoff_t index,
>   	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
>   	struct folio *folio;
>   	struct f2fs_lock_context lc;
> +	size_t folio_off;
>   
>   	if (!len)
>   		return 0;
> @@ -1324,7 +1334,14 @@ static int fill_zero(struct inode *inode, pgoff_t index,
>   		return PTR_ERR(folio);
>   
>   	f2fs_folio_wait_writeback(folio, DATA, true, true);
> -	folio_zero_range(folio, start, len);
> +	folio_off = offset_in_folio(folio,
> +				   (loff_t)index << PAGE_SHIFT) + start;
> +	folio_zero_range(folio, folio_off, len);
> +	if (folio_test_large(folio)) {
> +		f2fs_ffs_find_or_alloc(folio);
> +		f2fs_ffs_mark_subrange_uptodate(folio, folio_off, len);
> +		f2fs_ffs_mark_subrange_dirty(folio, folio_off, len);

Ditto,

Thanks,

> +	}
>   	folio_mark_dirty(folio);
>   	f2fs_folio_put(folio, true);
>   	return 0;



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  reply	other threads:[~2026-08-31  7:56 UTC|newest]

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

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=3409f516-13a1-4489-ac7d-501936bc0dce@kernel.org \
    --to=linux-f2fs-devel@lists.sourceforge.net \
    --cc=David.Hildenbrand@arm.com \
    --cc=Dev.Jain@arm.com \
    --cc=Ryan.Roberts@arm.com \
    --cc=baohua@kernel.org \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=jyescas@google.com \
    --cc=kaleshsingh@google.com \
    --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