* [f2fs-dev] [PATCH v5 00/16] f2fs: support & optimize large folios for writable files
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
This series supports large folios for most readable/writable files
in buffered I/O paths, including normal files, block-layer encrypted
files, and atomic files except for inline-data files, compressed files,
and quota files.
It also extends f2fs_folio_state to coexist with f2fs page-private
flags and to handle large folio write path and partial truncate of
large folios correctly. A valid large folio always carries a
f2fs_folio_state at its folio->private in the current implementation.
Benchmark details can be found in the RFC v2 cover letter [1].
Changes in v5:
- Rebased onto the f2fs dev-test branch (d1685c24b6c3).
- Dropped the two prerequisite bug fixes, which are now merged:
c04f209773ec ("f2fs: read i_size once in f2fs_vm_page_mkwrite")
b3c984358925 ("f2fs: remove mappedtodisk flag usage in mmap write path")
- Link to v4: [2]
Many thanks to Chao and Daeho for your extensive reviews and valuable
suggestions!
[1] https://lore.kernel.org/r/20260622160830.324455-1-zhaonanzhe@xiaomi.com
[2] https://lore.kernel.org/linux-f2fs-devel/20261013115621.968742-1-nzzhao.sigma@gmail.com/
Nanzhe Zhao (16):
f2fs: extend folio state for large folio write path
f2fs: carry subpage offset and count in write IO
f2fs: support regular file buffered writes on large folios
f2fs: support atomic file large folios buffered write
f2fs: support large folio writeback
f2fs: account large folio dirty data at block granularity
f2fs: prepare mmap write faults for large folios
f2fs: make GC migration large-folio aware
f2fs: optimize small block size large folio read
f2fs: support partial uptodate large folio read
f2fs: handle partial truncate of large folio dirty subpages
f2fs: wait for folio writeback before ffs_detach_free
f2fs: fix zeroing paths for large folios
f2fs: handle block cloning within the same large folio
f2fs: allow large folio support to writeable files
f2fs: make compressed files compatible with large folio
Documentation/filesystems/f2fs.rst | 10 +
fs/f2fs/checkpoint.c | 40 +-
fs/f2fs/compress.c | 7 +-
fs/f2fs/data.c | 1467 +++++++++++++++++++++++++---
fs/f2fs/dir.c | 2 +-
fs/f2fs/f2fs.h | 170 +++-
fs/f2fs/file.c | 226 +++--
fs/f2fs/gc.c | 38 +-
fs/f2fs/inline.c | 9 +-
fs/f2fs/inode.c | 4 +-
fs/f2fs/namei.c | 1 +
fs/f2fs/node.c | 2 +-
fs/f2fs/segment.c | 5 +-
13 files changed, 1716 insertions(+), 265 deletions(-)
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread* [PATCH v5 01/16] f2fs: extend folio state for large folio write path
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
Large folio write path needs a subpage status bitmap and write
pages pending counter, while keeping compatible with f2fs private
flags.
Move struct f2fs_folio_state to f2fs.h, add private_flags and
subpage state bitmap, and change PAGE_PRIVATE functions to be
compatible with f2fs_folio_state. Allocate f2fs_folio_state via kzalloc
instead of kmem_cache, since the state size depends on the folio order.
Note: Now if a path wants to use f2fs_folio_state, it must call
`folio_has_ffs` instead of `folio_test_large`` to make check.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 52 ++++++++++++++++++++-----------------
fs/f2fs/f2fs.h | 70 +++++++++++++++++++++++++++++++++++++-------------
2 files changed, 80 insertions(+), 42 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index a8d39add5cbe..95212e60f09d 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -32,15 +32,9 @@
static struct kmem_cache *bio_post_read_ctx_cache;
static struct kmem_cache *bio_entry_slab;
-static struct kmem_cache *ffs_entry_slab;
static mempool_t *bio_post_read_ctx_pool;
static struct bio_set f2fs_bioset;
-struct f2fs_folio_state {
- spinlock_t state_lock;
- unsigned int read_pages_pending;
-};
-
#define F2FS_BIO_POOL_SIZE NR_CURSEG_TYPE
int __init f2fs_init_bioset(void)
@@ -2717,17 +2711,31 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
}
#endif
-static struct f2fs_folio_state *ffs_find_or_alloc(struct folio *folio)
+struct f2fs_folio_state *f2fs_ffs_find_or_alloc(struct folio *folio)
{
- struct f2fs_folio_state *ffs = folio->private;
+ struct f2fs_folio_state *ffs;
+ unsigned int nr_subpages = folio_nr_pages(folio);
+ unsigned long private = (unsigned long)folio->private;
- if (ffs)
- return ffs;
+ f2fs_bug_on(F2FS_F_SB(folio), !folio_test_large(folio));
+ f2fs_bug_on(F2FS_F_SB(folio),
+ test_bit(PAGE_PRIVATE_NOT_POINTER, &private));
- ffs = f2fs_kmem_cache_alloc(ffs_entry_slab,
- GFP_NOIO | __GFP_ZERO, true, NULL);
+ if (f2fs_folio_has_ffs(folio))
+ return (struct f2fs_folio_state *)folio->private;
+
+ ffs = f2fs_kmalloc(F2FS_F_SB(folio),
+ struct_size(ffs, state, BITS_TO_LONGS(2 * nr_subpages)),
+ GFP_NOFS | __GFP_ZERO);
+ if (!ffs)
+ return NULL;
spin_lock_init(&ffs->state_lock);
+ if (folio_test_uptodate(folio))
+ bitmap_set(ffs->state, 0, nr_subpages);
+ if (folio_test_dirty(folio))
+ bitmap_set(ffs->state, nr_subpages, nr_subpages);
+
folio_attach_private(folio, ffs);
return ffs;
}
@@ -2736,7 +2744,7 @@ static void ffs_detach_free(struct folio *folio)
{
struct f2fs_folio_state *ffs;
- if (!folio_test_large(folio)) {
+ if (!f2fs_folio_has_ffs(folio)) {
folio_detach_private(folio);
return;
}
@@ -2746,7 +2754,8 @@ static void ffs_detach_free(struct folio *folio)
return;
WARN_ON_ONCE(ffs->read_pages_pending != 0);
- kmem_cache_free(ffs_entry_slab, ffs);
+ WARN_ON_ONCE(atomic_read(&ffs->write_pages_pending));
+ kfree(ffs);
}
static int f2fs_read_data_large_folio(struct inode *inode,
@@ -2835,7 +2844,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
* to prevent from premature folio_end_read() call on folio
*/
if (folio_test_large(folio)) {
- ffs = ffs_find_or_alloc(folio);
+ ffs = f2fs_ffs_find_or_alloc(folio);
+ if (!ffs) {
+ ret = -ENOMEM;
+ goto err_out;
+ }
/* set the bitmap to wait */
spin_lock_irq(&ffs->state_lock);
@@ -4750,21 +4763,12 @@ int __init f2fs_init_bio_entry_cache(void)
if (!bio_entry_slab)
return -ENOMEM;
- ffs_entry_slab = f2fs_kmem_cache_create("f2fs_ffs_slab",
- sizeof(struct f2fs_folio_state));
-
- if (!ffs_entry_slab) {
- kmem_cache_destroy(bio_entry_slab);
- return -ENOMEM;
- }
-
return 0;
}
void f2fs_destroy_bio_entry_cache(void)
{
kmem_cache_destroy(bio_entry_slab);
- kmem_cache_destroy(ffs_entry_slab);
}
static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 631d8ce15203..2fb8ebfa1303 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1621,6 +1621,18 @@ static inline void f2fs_clear_bit(unsigned int nr, char *addr);
* Layout B: lowest bit should be 0
* page.private is a wrapped pointer.
*/
+
+struct f2fs_folio_state {
+ spinlock_t state_lock;
+ unsigned int read_pages_pending;
+ atomic_t write_pages_pending;
+ unsigned long private_flags;
+ /* state[0..nr_subpages - 1] tracks uptodate subpages.
+ * state[nr_subpages..2 * nr_subpages - 1] tracks dirty subpages.
+ */
+ unsigned long state[];
+};
+
enum {
PAGE_PRIVATE_NOT_POINTER, /* private contains non-pointer data */
PAGE_PRIVATE_ONGOING_MIGRATION, /* data page which is on-going migrating */
@@ -1629,6 +1641,13 @@ enum {
PAGE_PRIVATE_MAX
};
+static inline bool f2fs_folio_has_ffs(const struct folio *folio)
+{
+ unsigned long private = (unsigned long)folio->private;
+
+ return folio_test_large(folio) && private;
+}
+
/* For compression */
enum compress_algorithm_type {
COMPRESS_LZO,
@@ -2759,13 +2778,35 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
return -ENOSPC;
}
+static inline unsigned long f2fs_folio_get_private_flags(const struct folio *folio)
+{
+ unsigned long private = (unsigned long)folio->private;
+
+ if (f2fs_folio_has_ffs(folio)) {
+ struct f2fs_folio_state *ffs = (struct f2fs_folio_state *)private;
+
+ return READ_ONCE(ffs->private_flags);
+ }
+
+ if (test_bit(PAGE_PRIVATE_NOT_POINTER, &private))
+ return private;
+
+ return 0;
+}
+
+static inline unsigned long *f2fs_folio_flags_addr(struct folio *folio)
+{
+ if (f2fs_folio_has_ffs(folio))
+ return &((struct f2fs_folio_state *)folio->private)->private_flags;
+
+ return (unsigned long *)&folio->private;
+}
+
#define PAGE_PRIVATE_GET_FUNC(name, flagname) \
static inline bool folio_test_f2fs_##name(const struct folio *folio) \
{ \
- unsigned long priv = (unsigned long)folio->private; \
- unsigned long v = (1UL << PAGE_PRIVATE_NOT_POINTER) | \
- (1UL << PAGE_PRIVATE_##flagname); \
- return (priv & v) == v; \
+ return f2fs_folio_get_private_flags(folio) & \
+ (1UL << PAGE_PRIVATE_##flagname); \
} \
static inline bool page_private_##name(struct page *page) \
{ \
@@ -2777,14 +2818,10 @@ static inline bool page_private_##name(struct page *page) \
#define PAGE_PRIVATE_SET_FUNC(name, flagname) \
static inline void folio_set_f2fs_##name(struct folio *folio) \
{ \
- unsigned long v = (1UL << PAGE_PRIVATE_NOT_POINTER) | \
- (1UL << PAGE_PRIVATE_##flagname); \
if (!folio->private) \
- folio_attach_private(folio, (void *)v); \
- else { \
- v |= (unsigned long)folio->private; \
- folio->private = (void *)v; \
- } \
+ folio_attach_private(folio, \
+ (void *)BIT(PAGE_PRIVATE_NOT_POINTER)); \
+ set_bit(PAGE_PRIVATE_##flagname, f2fs_folio_flags_addr(folio)); \
} \
static inline void set_page_private_##name(struct page *page) \
{ \
@@ -2797,13 +2834,10 @@ static inline void set_page_private_##name(struct page *page) \
#define PAGE_PRIVATE_CLEAR_FUNC(name, flagname) \
static inline void folio_clear_f2fs_##name(struct folio *folio) \
{ \
- unsigned long v = (unsigned long)folio->private; \
- \
- v &= ~(1UL << PAGE_PRIVATE_##flagname); \
- if (v == (1UL << PAGE_PRIVATE_NOT_POINTER)) \
+ clear_bit(PAGE_PRIVATE_##flagname, \
+ f2fs_folio_flags_addr(folio)); \
+ if (folio->private == (void *)BIT(PAGE_PRIVATE_NOT_POINTER)) \
folio_detach_private(folio); \
- else \
- folio->private = (void *)v; \
} \
static inline void clear_page_private_##name(struct page *page) \
{ \
@@ -2826,7 +2860,7 @@ PAGE_PRIVATE_CLEAR_FUNC(atomic, ATOMIC_WRITE);
static inline unsigned long folio_get_f2fs_data(struct folio *folio)
{
- unsigned long data = (unsigned long)folio->private;
+ unsigned long data = f2fs_folio_get_private_flags(folio);
if (!test_bit(PAGE_PRIVATE_NOT_POINTER, &data))
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread* [f2fs-dev] [PATCH v5 01/16] f2fs: extend folio state for large folio write path
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
Large folio write path needs a subpage status bitmap and write
pages pending counter, while keeping compatible with f2fs private
flags.
Move struct f2fs_folio_state to f2fs.h, add private_flags and
subpage state bitmap, and change PAGE_PRIVATE functions to be
compatible with f2fs_folio_state. Allocate f2fs_folio_state via kzalloc
instead of kmem_cache, since the state size depends on the folio order.
Note: Now if a path wants to use f2fs_folio_state, it must call
`folio_has_ffs` instead of `folio_test_large`` to make check.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 52 ++++++++++++++++++++-----------------
fs/f2fs/f2fs.h | 70 +++++++++++++++++++++++++++++++++++++-------------
2 files changed, 80 insertions(+), 42 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index a8d39add5cbe..95212e60f09d 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -32,15 +32,9 @@
static struct kmem_cache *bio_post_read_ctx_cache;
static struct kmem_cache *bio_entry_slab;
-static struct kmem_cache *ffs_entry_slab;
static mempool_t *bio_post_read_ctx_pool;
static struct bio_set f2fs_bioset;
-struct f2fs_folio_state {
- spinlock_t state_lock;
- unsigned int read_pages_pending;
-};
-
#define F2FS_BIO_POOL_SIZE NR_CURSEG_TYPE
int __init f2fs_init_bioset(void)
@@ -2717,17 +2711,31 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
}
#endif
-static struct f2fs_folio_state *ffs_find_or_alloc(struct folio *folio)
+struct f2fs_folio_state *f2fs_ffs_find_or_alloc(struct folio *folio)
{
- struct f2fs_folio_state *ffs = folio->private;
+ struct f2fs_folio_state *ffs;
+ unsigned int nr_subpages = folio_nr_pages(folio);
+ unsigned long private = (unsigned long)folio->private;
- if (ffs)
- return ffs;
+ f2fs_bug_on(F2FS_F_SB(folio), !folio_test_large(folio));
+ f2fs_bug_on(F2FS_F_SB(folio),
+ test_bit(PAGE_PRIVATE_NOT_POINTER, &private));
- ffs = f2fs_kmem_cache_alloc(ffs_entry_slab,
- GFP_NOIO | __GFP_ZERO, true, NULL);
+ if (f2fs_folio_has_ffs(folio))
+ return (struct f2fs_folio_state *)folio->private;
+
+ ffs = f2fs_kmalloc(F2FS_F_SB(folio),
+ struct_size(ffs, state, BITS_TO_LONGS(2 * nr_subpages)),
+ GFP_NOFS | __GFP_ZERO);
+ if (!ffs)
+ return NULL;
spin_lock_init(&ffs->state_lock);
+ if (folio_test_uptodate(folio))
+ bitmap_set(ffs->state, 0, nr_subpages);
+ if (folio_test_dirty(folio))
+ bitmap_set(ffs->state, nr_subpages, nr_subpages);
+
folio_attach_private(folio, ffs);
return ffs;
}
@@ -2736,7 +2744,7 @@ static void ffs_detach_free(struct folio *folio)
{
struct f2fs_folio_state *ffs;
- if (!folio_test_large(folio)) {
+ if (!f2fs_folio_has_ffs(folio)) {
folio_detach_private(folio);
return;
}
@@ -2746,7 +2754,8 @@ static void ffs_detach_free(struct folio *folio)
return;
WARN_ON_ONCE(ffs->read_pages_pending != 0);
- kmem_cache_free(ffs_entry_slab, ffs);
+ WARN_ON_ONCE(atomic_read(&ffs->write_pages_pending));
+ kfree(ffs);
}
static int f2fs_read_data_large_folio(struct inode *inode,
@@ -2835,7 +2844,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
* to prevent from premature folio_end_read() call on folio
*/
if (folio_test_large(folio)) {
- ffs = ffs_find_or_alloc(folio);
+ ffs = f2fs_ffs_find_or_alloc(folio);
+ if (!ffs) {
+ ret = -ENOMEM;
+ goto err_out;
+ }
/* set the bitmap to wait */
spin_lock_irq(&ffs->state_lock);
@@ -4750,21 +4763,12 @@ int __init f2fs_init_bio_entry_cache(void)
if (!bio_entry_slab)
return -ENOMEM;
- ffs_entry_slab = f2fs_kmem_cache_create("f2fs_ffs_slab",
- sizeof(struct f2fs_folio_state));
-
- if (!ffs_entry_slab) {
- kmem_cache_destroy(bio_entry_slab);
- return -ENOMEM;
- }
-
return 0;
}
void f2fs_destroy_bio_entry_cache(void)
{
kmem_cache_destroy(bio_entry_slab);
- kmem_cache_destroy(ffs_entry_slab);
}
static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 631d8ce15203..2fb8ebfa1303 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1621,6 +1621,18 @@ static inline void f2fs_clear_bit(unsigned int nr, char *addr);
* Layout B: lowest bit should be 0
* page.private is a wrapped pointer.
*/
+
+struct f2fs_folio_state {
+ spinlock_t state_lock;
+ unsigned int read_pages_pending;
+ atomic_t write_pages_pending;
+ unsigned long private_flags;
+ /* state[0..nr_subpages - 1] tracks uptodate subpages.
+ * state[nr_subpages..2 * nr_subpages - 1] tracks dirty subpages.
+ */
+ unsigned long state[];
+};
+
enum {
PAGE_PRIVATE_NOT_POINTER, /* private contains non-pointer data */
PAGE_PRIVATE_ONGOING_MIGRATION, /* data page which is on-going migrating */
@@ -1629,6 +1641,13 @@ enum {
PAGE_PRIVATE_MAX
};
+static inline bool f2fs_folio_has_ffs(const struct folio *folio)
+{
+ unsigned long private = (unsigned long)folio->private;
+
+ return folio_test_large(folio) && private;
+}
+
/* For compression */
enum compress_algorithm_type {
COMPRESS_LZO,
@@ -2759,13 +2778,35 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
return -ENOSPC;
}
+static inline unsigned long f2fs_folio_get_private_flags(const struct folio *folio)
+{
+ unsigned long private = (unsigned long)folio->private;
+
+ if (f2fs_folio_has_ffs(folio)) {
+ struct f2fs_folio_state *ffs = (struct f2fs_folio_state *)private;
+
+ return READ_ONCE(ffs->private_flags);
+ }
+
+ if (test_bit(PAGE_PRIVATE_NOT_POINTER, &private))
+ return private;
+
+ return 0;
+}
+
+static inline unsigned long *f2fs_folio_flags_addr(struct folio *folio)
+{
+ if (f2fs_folio_has_ffs(folio))
+ return &((struct f2fs_folio_state *)folio->private)->private_flags;
+
+ return (unsigned long *)&folio->private;
+}
+
#define PAGE_PRIVATE_GET_FUNC(name, flagname) \
static inline bool folio_test_f2fs_##name(const struct folio *folio) \
{ \
- unsigned long priv = (unsigned long)folio->private; \
- unsigned long v = (1UL << PAGE_PRIVATE_NOT_POINTER) | \
- (1UL << PAGE_PRIVATE_##flagname); \
- return (priv & v) == v; \
+ return f2fs_folio_get_private_flags(folio) & \
+ (1UL << PAGE_PRIVATE_##flagname); \
} \
static inline bool page_private_##name(struct page *page) \
{ \
@@ -2777,14 +2818,10 @@ static inline bool page_private_##name(struct page *page) \
#define PAGE_PRIVATE_SET_FUNC(name, flagname) \
static inline void folio_set_f2fs_##name(struct folio *folio) \
{ \
- unsigned long v = (1UL << PAGE_PRIVATE_NOT_POINTER) | \
- (1UL << PAGE_PRIVATE_##flagname); \
if (!folio->private) \
- folio_attach_private(folio, (void *)v); \
- else { \
- v |= (unsigned long)folio->private; \
- folio->private = (void *)v; \
- } \
+ folio_attach_private(folio, \
+ (void *)BIT(PAGE_PRIVATE_NOT_POINTER)); \
+ set_bit(PAGE_PRIVATE_##flagname, f2fs_folio_flags_addr(folio)); \
} \
static inline void set_page_private_##name(struct page *page) \
{ \
@@ -2797,13 +2834,10 @@ static inline void set_page_private_##name(struct page *page) \
#define PAGE_PRIVATE_CLEAR_FUNC(name, flagname) \
static inline void folio_clear_f2fs_##name(struct folio *folio) \
{ \
- unsigned long v = (unsigned long)folio->private; \
- \
- v &= ~(1UL << PAGE_PRIVATE_##flagname); \
- if (v == (1UL << PAGE_PRIVATE_NOT_POINTER)) \
+ clear_bit(PAGE_PRIVATE_##flagname, \
+ f2fs_folio_flags_addr(folio)); \
+ if (folio->private == (void *)BIT(PAGE_PRIVATE_NOT_POINTER)) \
folio_detach_private(folio); \
- else \
- folio->private = (void *)v; \
} \
static inline void clear_page_private_##name(struct page *page) \
{ \
@@ -2826,7 +2860,7 @@ PAGE_PRIVATE_CLEAR_FUNC(atomic, ATOMIC_WRITE);
static inline unsigned long folio_get_f2fs_data(struct folio *folio)
{
- unsigned long data = (unsigned long)folio->private;
+ unsigned long data = f2fs_folio_get_private_flags(folio);
if (!test_bit(PAGE_PRIVATE_NOT_POINTER, &data))
return 0;
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 02/16] f2fs: carry subpage offset and count in write IO
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
Large folio write paths need to submit I/O for a range inside a
folio instead of always submitting the whole folio from offset zero.
Add folio_offset and folio_blkcnt to f2fs_io_info to describe the
block offset inside the folio and the number of contiguous blocks
covered by the I/O.
Apply the new fields to the bio submit paths that need the subpage
offset or contiguous block count.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/checkpoint.c | 2 ++
fs/f2fs/compress.c | 1 +
fs/f2fs/data.c | 65 ++++++++++++++++++++++++++++++--------------
fs/f2fs/f2fs.h | 11 ++++++++
fs/f2fs/gc.c | 2 ++
fs/f2fs/inline.c | 1 +
fs/f2fs/segment.c | 3 +-
7 files changed, 64 insertions(+), 21 deletions(-)
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 5c5b45d3c67b..3ad709f69893 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -264,6 +264,7 @@ static struct f2fs_cached_block *__get_meta_cache(struct f2fs_sb_info *sbi,
.op_flags = REQ_META | REQ_PRIO,
.old_blkaddr = index,
.new_blkaddr = index,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.is_por = !is_meta ? 1 : 0,
.is_cache = 1,
@@ -462,6 +463,7 @@ int f2fs_ra_meta_caches(struct f2fs_sb_info *sbi, block_t start,
.type = META,
.op = REQ_OP_READ,
.op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.in_list = 0,
.is_por = (type == META_POR) ? 1 : 0,
diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 747141c79900..c0e39f580993 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -1282,6 +1282,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
.op_flags = wbc_to_write_flags(wbc),
.old_blkaddr = NEW_ADDR,
.page = NULL,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.compressed_page = NULL,
.io_type = io_type,
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 95212e60f09d..429fe8998ca3 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -849,6 +849,9 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
struct folio *fio_folio = fio->folio;
struct folio *data_folio = fio->encrypted_page ?
page_folio(fio->encrypted_page) : fio_folio;
+ pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
+ size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
+ size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
fio->is_por ? META_POR : (__is_meta_io(fio) ?
@@ -861,11 +864,11 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
bio = __bio_alloc(fio, 1);
f2fs_set_bio_crypt_ctx(bio, fio_folio->mapping->host,
- fio_folio->index, fio, GFP_NOIO);
- bio_add_folio_nofail(bio, data_folio, folio_size(data_folio), 0);
+ fio_lblk, fio, GFP_NOIO);
+ bio_add_folio_nofail(bio, data_folio, bio_len, bio_offset);
if (fio->io_wbc && !is_read_io(fio->op))
- wbc_account_cgroup_owner(fio->io_wbc, fio_folio, PAGE_SIZE);
+ wbc_account_cgroup_owner(fio->io_wbc, fio_folio, bio_len);
inc_cache_count(fio->sbi, is_read_io(fio->op) ?
F2FS_RD_DATA : WB_DATA_TYPE(fio->folio, false));
@@ -924,7 +927,8 @@ static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
}
static void add_bio_entry(struct f2fs_sb_info *sbi, struct bio *bio,
- struct folio *folio, enum temp_type temp)
+ struct folio *folio, size_t len, size_t offset,
+ enum temp_type temp)
{
struct f2fs_bio_info *io = sbi->write_io[DATA] + temp;
struct bio_entry *be;
@@ -933,7 +937,7 @@ static void add_bio_entry(struct f2fs_sb_info *sbi, struct bio *bio,
be->bio = bio;
bio_get(bio);
- bio_add_folio_nofail(bio, folio, folio_size(folio), 0);
+ bio_add_folio_nofail(bio, folio, len, offset);
f2fs_down_write(&io->bio_list_lock);
list_add_tail(&be->list, &io->bio_list);
@@ -950,6 +954,9 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio,
struct folio *folio)
{
struct folio *fio_folio = fio->folio;
+ pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
+ size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
+ size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
struct f2fs_sb_info *sbi = fio->sbi;
enum temp_type temp;
bool found = false;
@@ -972,8 +979,8 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio,
fio->new_blkaddr));
if (f2fs_crypt_mergeable_bio(*bio,
fio_folio->mapping->host,
- fio_folio->index, fio) &&
- bio_add_folio(*bio, folio, folio_size(folio), 0)) {
+ fio_lblk, fio) &&
+ bio_add_folio(*bio, folio, bio_len, bio_offset)) {
ret = 0;
break;
}
@@ -1087,6 +1094,10 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
struct folio *data_folio = fio->encrypted_page ?
page_folio(fio->encrypted_page) : fio->folio;
struct folio *folio = fio->folio;
+ pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
+ unsigned int fio_cnt = F2FS_FIO_BLKCNT(fio);
+ size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
+ size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
__is_meta_io(fio) ? META_GENERIC : DATA_GENERIC))
@@ -1101,20 +1112,21 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
if (!bio) {
bio = __bio_alloc(fio, BIO_MAX_VECS);
f2fs_set_bio_crypt_ctx(bio, folio->mapping->host,
- folio->index, fio, GFP_NOIO);
+ fio_lblk, fio, GFP_NOIO);
- add_bio_entry(fio->sbi, bio, data_folio, fio->temp);
+ add_bio_entry(fio->sbi, bio, data_folio, bio_len,
+ bio_offset, fio->temp);
} else {
if (add_ipu_page(fio, &bio, data_folio))
goto alloc_new;
}
if (fio->io_wbc)
- wbc_account_cgroup_owner(fio->io_wbc, folio, folio_size(folio));
+ wbc_account_cgroup_owner(fio->io_wbc, folio, bio_len);
inc_cache_count(fio->sbi, WB_DATA_TYPE(folio, false));
- *fio->last_block = fio->new_blkaddr;
+ *fio->last_block = fio->new_blkaddr + fio_cnt - 1;
*fio->bio = bio;
return 0;
@@ -1177,6 +1189,10 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
struct folio *bio_folio;
struct f2fs_lock_context lc;
enum count_type type;
+ pgoff_t fio_lblk;
+ unsigned int fio_cnt;
+ size_t bio_offset;
+ size_t bio_len;
f2fs_bug_on(sbi, is_read_io(fio->op));
@@ -1209,24 +1225,31 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
/* set submitted = true as a return value */
fio->submitted = 1;
+ fio_lblk = F2FS_FIO_LBLK(fio);
+ fio_cnt = F2FS_FIO_BLKCNT(fio);
+
type = WB_DATA_TYPE(bio_folio, fio->compressed_page);
- inc_cache_count(sbi, type);
+ for (unsigned int i = 0; i < fio_cnt; i++)
+ inc_cache_count(sbi, type);
if (io->bio &&
(!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio,
fio->new_blkaddr) ||
!f2fs_crypt_mergeable_bio(io->bio, fio_inode(fio),
- bio_folio->index, fio)))
+ fio_lblk, fio)))
__submit_merged_bio(io);
alloc_new:
if (io->bio == NULL) {
io->bio = __bio_alloc(fio, BIO_MAX_VECS);
f2fs_set_bio_crypt_ctx(io->bio, fio_inode(fio),
- bio_folio->index, fio, GFP_NOIO);
+ fio_lblk, fio, GFP_NOIO);
io->fio = *fio;
}
- if (!bio_add_folio(io->bio, bio_folio, folio_size(bio_folio), 0)) {
+ bio_offset = F2FS_FIO_BIO_OFFSET(fio);
+ bio_len = F2FS_FIO_BIO_SIZE(fio);
+
+ if (!bio_add_folio(io->bio, bio_folio, bio_len, bio_offset)) {
__submit_merged_bio(io);
goto alloc_new;
}
@@ -1234,10 +1257,9 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
F2FS_BIO(io->bio)->entry_cnt++;
if (fio->io_wbc)
- wbc_account_cgroup_owner(fio->io_wbc, fio->folio,
- folio_size(fio->folio));
+ wbc_account_cgroup_owner(fio->io_wbc, fio->folio, bio_len);
- io->last_block_in_bio = fio->new_blkaddr;
+ io->last_block_in_bio = fio->new_blkaddr + fio_cnt - 1;
trace_f2fs_submit_folio_write(fio->folio, fio);
#ifdef CONFIG_BLK_DEV_ZONED
@@ -3213,7 +3235,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
set_new_dnode(&dn, inode, NULL, NULL, 0);
if (need_inplace_update(fio) &&
- f2fs_lookup_read_extent_cache_block(inode, folio->index,
+ f2fs_lookup_read_extent_cache_block(inode,
+ F2FS_FIO_LBLK(fio),
&fio->old_blkaddr)) {
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
DATA_GENERIC_ENHANCE))
@@ -3232,7 +3255,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi, &lc))
return -EAGAIN;
- err = f2fs_get_dnode_of_data(&dn, folio->index, LOOKUP_NODE);
+ err = f2fs_get_dnode_of_data(&dn, F2FS_FIO_LBLK(fio),
+ LOOKUP_NODE);
if (err)
goto out;
@@ -3335,6 +3359,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
.op_flags = wbc_to_write_flags(wbc),
.old_blkaddr = NULL_ADDR,
.folio = folio,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.submitted = 0,
.compr_blocks = compr_blocks,
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 2fb8ebfa1303..963cd2cdf7ba 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1350,6 +1350,8 @@ struct f2fs_io_info {
blk_opf_t op_flags; /* req_flag_bits */
block_t new_blkaddr; /* new block address to be written */
block_t old_blkaddr; /* old block address before Cow */
+ pgoff_t folio_offset; /* offset in large folio */
+ unsigned int folio_blkcnt; /* block count in large folio */
union {
struct page *page; /* page to be written */
struct folio *folio;
@@ -1372,6 +1374,15 @@ struct f2fs_io_info {
sector_t *last_block; /* last block number in bio */
};
+#define F2FS_FIO_LBLK(fio) \
+ (((fio)->folio)->index + (fio)->folio_offset)
+#define F2FS_FIO_BLKCNT(fio) \
+ ((fio)->folio_blkcnt)
+#define F2FS_FIO_BIO_OFFSET(fio) \
+ ((fio)->folio_offset << PAGE_SHIFT)
+#define F2FS_FIO_BIO_SIZE(fio) \
+ F2FS_BLK_TO_BYTES((fio)->sbi, F2FS_FIO_BLKCNT(fio))
+
struct bio_entry {
struct bio *bio;
struct list_head list;
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 926e6976bc22..89e50f871b75 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1228,6 +1228,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
.temp = COLD,
.op = REQ_OP_READ,
.op_flags = 0,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.in_list = 0,
.is_cache = 1,
@@ -1338,6 +1339,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
.temp = COLD,
.op = REQ_OP_READ,
.op_flags = 0,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.in_list = 0,
.is_cache = 1,
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index 273b6428c9f9..ab7537ff7ebd 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -151,6 +151,7 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
.op = REQ_OP_WRITE,
.op_flags = REQ_SYNC | REQ_PRIO,
.folio = folio,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.io_type = FS_DATA_IO,
};
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 25785b7626bb..96bfb7d63692 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3876,7 +3876,8 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)
if (file_is_cold(inode) || f2fs_need_compress_data(inode))
return CURSEG_COLD_DATA;
- type = __get_age_segment_type(inode, fio->folio->index);
+ type = __get_age_segment_type(inode,
+ F2FS_FIO_LBLK(fio));
if (type != NO_CHECK_TYPE)
return type;
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 02/16] f2fs: carry subpage offset and count in write IO
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
Large folio write paths need to submit I/O for a range inside a
folio instead of always submitting the whole folio from offset zero.
Add folio_offset and folio_blkcnt to f2fs_io_info to describe the
block offset inside the folio and the number of contiguous blocks
covered by the I/O.
Apply the new fields to the bio submit paths that need the subpage
offset or contiguous block count.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/checkpoint.c | 2 ++
fs/f2fs/compress.c | 1 +
fs/f2fs/data.c | 65 ++++++++++++++++++++++++++++++--------------
fs/f2fs/f2fs.h | 11 ++++++++
fs/f2fs/gc.c | 2 ++
fs/f2fs/inline.c | 1 +
fs/f2fs/segment.c | 3 +-
7 files changed, 64 insertions(+), 21 deletions(-)
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 5c5b45d3c67b..3ad709f69893 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -264,6 +264,7 @@ static struct f2fs_cached_block *__get_meta_cache(struct f2fs_sb_info *sbi,
.op_flags = REQ_META | REQ_PRIO,
.old_blkaddr = index,
.new_blkaddr = index,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.is_por = !is_meta ? 1 : 0,
.is_cache = 1,
@@ -462,6 +463,7 @@ int f2fs_ra_meta_caches(struct f2fs_sb_info *sbi, block_t start,
.type = META,
.op = REQ_OP_READ,
.op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.in_list = 0,
.is_por = (type == META_POR) ? 1 : 0,
diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 747141c79900..c0e39f580993 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -1282,6 +1282,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
.op_flags = wbc_to_write_flags(wbc),
.old_blkaddr = NEW_ADDR,
.page = NULL,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.compressed_page = NULL,
.io_type = io_type,
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 95212e60f09d..429fe8998ca3 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -849,6 +849,9 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
struct folio *fio_folio = fio->folio;
struct folio *data_folio = fio->encrypted_page ?
page_folio(fio->encrypted_page) : fio_folio;
+ pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
+ size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
+ size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
fio->is_por ? META_POR : (__is_meta_io(fio) ?
@@ -861,11 +864,11 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
bio = __bio_alloc(fio, 1);
f2fs_set_bio_crypt_ctx(bio, fio_folio->mapping->host,
- fio_folio->index, fio, GFP_NOIO);
- bio_add_folio_nofail(bio, data_folio, folio_size(data_folio), 0);
+ fio_lblk, fio, GFP_NOIO);
+ bio_add_folio_nofail(bio, data_folio, bio_len, bio_offset);
if (fio->io_wbc && !is_read_io(fio->op))
- wbc_account_cgroup_owner(fio->io_wbc, fio_folio, PAGE_SIZE);
+ wbc_account_cgroup_owner(fio->io_wbc, fio_folio, bio_len);
inc_cache_count(fio->sbi, is_read_io(fio->op) ?
F2FS_RD_DATA : WB_DATA_TYPE(fio->folio, false));
@@ -924,7 +927,8 @@ static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
}
static void add_bio_entry(struct f2fs_sb_info *sbi, struct bio *bio,
- struct folio *folio, enum temp_type temp)
+ struct folio *folio, size_t len, size_t offset,
+ enum temp_type temp)
{
struct f2fs_bio_info *io = sbi->write_io[DATA] + temp;
struct bio_entry *be;
@@ -933,7 +937,7 @@ static void add_bio_entry(struct f2fs_sb_info *sbi, struct bio *bio,
be->bio = bio;
bio_get(bio);
- bio_add_folio_nofail(bio, folio, folio_size(folio), 0);
+ bio_add_folio_nofail(bio, folio, len, offset);
f2fs_down_write(&io->bio_list_lock);
list_add_tail(&be->list, &io->bio_list);
@@ -950,6 +954,9 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio,
struct folio *folio)
{
struct folio *fio_folio = fio->folio;
+ pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
+ size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
+ size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
struct f2fs_sb_info *sbi = fio->sbi;
enum temp_type temp;
bool found = false;
@@ -972,8 +979,8 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio,
fio->new_blkaddr));
if (f2fs_crypt_mergeable_bio(*bio,
fio_folio->mapping->host,
- fio_folio->index, fio) &&
- bio_add_folio(*bio, folio, folio_size(folio), 0)) {
+ fio_lblk, fio) &&
+ bio_add_folio(*bio, folio, bio_len, bio_offset)) {
ret = 0;
break;
}
@@ -1087,6 +1094,10 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
struct folio *data_folio = fio->encrypted_page ?
page_folio(fio->encrypted_page) : fio->folio;
struct folio *folio = fio->folio;
+ pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
+ unsigned int fio_cnt = F2FS_FIO_BLKCNT(fio);
+ size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
+ size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
__is_meta_io(fio) ? META_GENERIC : DATA_GENERIC))
@@ -1101,20 +1112,21 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
if (!bio) {
bio = __bio_alloc(fio, BIO_MAX_VECS);
f2fs_set_bio_crypt_ctx(bio, folio->mapping->host,
- folio->index, fio, GFP_NOIO);
+ fio_lblk, fio, GFP_NOIO);
- add_bio_entry(fio->sbi, bio, data_folio, fio->temp);
+ add_bio_entry(fio->sbi, bio, data_folio, bio_len,
+ bio_offset, fio->temp);
} else {
if (add_ipu_page(fio, &bio, data_folio))
goto alloc_new;
}
if (fio->io_wbc)
- wbc_account_cgroup_owner(fio->io_wbc, folio, folio_size(folio));
+ wbc_account_cgroup_owner(fio->io_wbc, folio, bio_len);
inc_cache_count(fio->sbi, WB_DATA_TYPE(folio, false));
- *fio->last_block = fio->new_blkaddr;
+ *fio->last_block = fio->new_blkaddr + fio_cnt - 1;
*fio->bio = bio;
return 0;
@@ -1177,6 +1189,10 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
struct folio *bio_folio;
struct f2fs_lock_context lc;
enum count_type type;
+ pgoff_t fio_lblk;
+ unsigned int fio_cnt;
+ size_t bio_offset;
+ size_t bio_len;
f2fs_bug_on(sbi, is_read_io(fio->op));
@@ -1209,24 +1225,31 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
/* set submitted = true as a return value */
fio->submitted = 1;
+ fio_lblk = F2FS_FIO_LBLK(fio);
+ fio_cnt = F2FS_FIO_BLKCNT(fio);
+
type = WB_DATA_TYPE(bio_folio, fio->compressed_page);
- inc_cache_count(sbi, type);
+ for (unsigned int i = 0; i < fio_cnt; i++)
+ inc_cache_count(sbi, type);
if (io->bio &&
(!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio,
fio->new_blkaddr) ||
!f2fs_crypt_mergeable_bio(io->bio, fio_inode(fio),
- bio_folio->index, fio)))
+ fio_lblk, fio)))
__submit_merged_bio(io);
alloc_new:
if (io->bio == NULL) {
io->bio = __bio_alloc(fio, BIO_MAX_VECS);
f2fs_set_bio_crypt_ctx(io->bio, fio_inode(fio),
- bio_folio->index, fio, GFP_NOIO);
+ fio_lblk, fio, GFP_NOIO);
io->fio = *fio;
}
- if (!bio_add_folio(io->bio, bio_folio, folio_size(bio_folio), 0)) {
+ bio_offset = F2FS_FIO_BIO_OFFSET(fio);
+ bio_len = F2FS_FIO_BIO_SIZE(fio);
+
+ if (!bio_add_folio(io->bio, bio_folio, bio_len, bio_offset)) {
__submit_merged_bio(io);
goto alloc_new;
}
@@ -1234,10 +1257,9 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
F2FS_BIO(io->bio)->entry_cnt++;
if (fio->io_wbc)
- wbc_account_cgroup_owner(fio->io_wbc, fio->folio,
- folio_size(fio->folio));
+ wbc_account_cgroup_owner(fio->io_wbc, fio->folio, bio_len);
- io->last_block_in_bio = fio->new_blkaddr;
+ io->last_block_in_bio = fio->new_blkaddr + fio_cnt - 1;
trace_f2fs_submit_folio_write(fio->folio, fio);
#ifdef CONFIG_BLK_DEV_ZONED
@@ -3213,7 +3235,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
set_new_dnode(&dn, inode, NULL, NULL, 0);
if (need_inplace_update(fio) &&
- f2fs_lookup_read_extent_cache_block(inode, folio->index,
+ f2fs_lookup_read_extent_cache_block(inode,
+ F2FS_FIO_LBLK(fio),
&fio->old_blkaddr)) {
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
DATA_GENERIC_ENHANCE))
@@ -3232,7 +3255,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi, &lc))
return -EAGAIN;
- err = f2fs_get_dnode_of_data(&dn, folio->index, LOOKUP_NODE);
+ err = f2fs_get_dnode_of_data(&dn, F2FS_FIO_LBLK(fio),
+ LOOKUP_NODE);
if (err)
goto out;
@@ -3335,6 +3359,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
.op_flags = wbc_to_write_flags(wbc),
.old_blkaddr = NULL_ADDR,
.folio = folio,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.submitted = 0,
.compr_blocks = compr_blocks,
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 2fb8ebfa1303..963cd2cdf7ba 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1350,6 +1350,8 @@ struct f2fs_io_info {
blk_opf_t op_flags; /* req_flag_bits */
block_t new_blkaddr; /* new block address to be written */
block_t old_blkaddr; /* old block address before Cow */
+ pgoff_t folio_offset; /* offset in large folio */
+ unsigned int folio_blkcnt; /* block count in large folio */
union {
struct page *page; /* page to be written */
struct folio *folio;
@@ -1372,6 +1374,15 @@ struct f2fs_io_info {
sector_t *last_block; /* last block number in bio */
};
+#define F2FS_FIO_LBLK(fio) \
+ (((fio)->folio)->index + (fio)->folio_offset)
+#define F2FS_FIO_BLKCNT(fio) \
+ ((fio)->folio_blkcnt)
+#define F2FS_FIO_BIO_OFFSET(fio) \
+ ((fio)->folio_offset << PAGE_SHIFT)
+#define F2FS_FIO_BIO_SIZE(fio) \
+ F2FS_BLK_TO_BYTES((fio)->sbi, F2FS_FIO_BLKCNT(fio))
+
struct bio_entry {
struct bio *bio;
struct list_head list;
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 926e6976bc22..89e50f871b75 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1228,6 +1228,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
.temp = COLD,
.op = REQ_OP_READ,
.op_flags = 0,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.in_list = 0,
.is_cache = 1,
@@ -1338,6 +1339,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
.temp = COLD,
.op = REQ_OP_READ,
.op_flags = 0,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.in_list = 0,
.is_cache = 1,
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index 273b6428c9f9..ab7537ff7ebd 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -151,6 +151,7 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
.op = REQ_OP_WRITE,
.op_flags = REQ_SYNC | REQ_PRIO,
.folio = folio,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.io_type = FS_DATA_IO,
};
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 25785b7626bb..96bfb7d63692 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3876,7 +3876,8 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)
if (file_is_cold(inode) || f2fs_need_compress_data(inode))
return CURSEG_COLD_DATA;
- type = __get_age_segment_type(inode, fio->folio->index);
+ type = __get_age_segment_type(inode,
+ F2FS_FIO_LBLK(fio));
if (type != NO_CHECK_TYPE)
return type;
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 02/16] f2fs: carry subpage offset and count in write IO
2026-10-14 6:44 ` Nanzhe Zhao
(?)
@ 2026-10-14 16:18 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 16:18 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu; +Cc: Daeho Jeong
Sashiko says:
> The accounting size uses the full folio size instead of the newly computed bio_len
> for partial large folio writes, causing cgroup over-accounting.
Changes:
@@ -1111,7 +1122,7 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
}
if (fio->io_wbc)
- wbc_account_cgroup_owner(fio->io_wbc, folio, folio_size(folio));
+ wbc_account_cgroup_owner(fio->io_wbc, folio, bio_len);
inc_cache_count(fio->sbi, WB_DATA_TYPE(folio, false));
v4 passed the whole folio size to wbc_account_cgroup_owner().
v5 fixes this by using bio_len.
Sashiko: https://sashiko.dev/#/patchset/20261013115621.968742-1-nzzhao.sigma%40gmail.com
Thanks,
Nanzhe Zhao
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [f2fs-dev] [PATCH v5 02/16] f2fs: carry subpage offset and count in write IO
2026-10-14 6:44 ` Nanzhe Zhao
@ 2026-10-15 2:37 ` Jaegeuk Kim via Linux-f2fs-devel
-1 siblings, 0 replies; 52+ messages in thread
From: Jaegeuk Kim @ 2026-10-15 2:37 UTC (permalink / raw)
To: Nanzhe Zhao
Cc: linux-f2fs-devel, Chao Yu, Barry Song, Juan Yescas, Daeho Jeong,
Pengfei Li, Dev Jain, David Hildenbrand, linux-kernel, Bo Zhang,
Kalesh Singh, Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
On 10/14, Nanzhe Zhao wrote:
> Large folio write paths need to submit I/O for a range inside a
> folio instead of always submitting the whole folio from offset zero.
> Add folio_offset and folio_blkcnt to f2fs_io_info to describe the
> block offset inside the folio and the number of contiguous blocks
> covered by the I/O.
>
> Apply the new fields to the bio submit paths that need the subpage
> offset or contiguous block count.
>
> Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
> ---
> fs/f2fs/checkpoint.c | 2 ++
> fs/f2fs/compress.c | 1 +
> fs/f2fs/data.c | 65 ++++++++++++++++++++++++++++++--------------
> fs/f2fs/f2fs.h | 11 ++++++++
> fs/f2fs/gc.c | 2 ++
> fs/f2fs/inline.c | 1 +
> fs/f2fs/segment.c | 3 +-
> 7 files changed, 64 insertions(+), 21 deletions(-)
>
> diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
> index 5c5b45d3c67b..3ad709f69893 100644
> --- a/fs/f2fs/checkpoint.c
> +++ b/fs/f2fs/checkpoint.c
> @@ -264,6 +264,7 @@ static struct f2fs_cached_block *__get_meta_cache(struct f2fs_sb_info *sbi,
> .op_flags = REQ_META | REQ_PRIO,
> .old_blkaddr = index,
> .new_blkaddr = index,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .is_por = !is_meta ? 1 : 0,
> .is_cache = 1,
> @@ -462,6 +463,7 @@ int f2fs_ra_meta_caches(struct f2fs_sb_info *sbi, block_t start,
> .type = META,
> .op = REQ_OP_READ,
> .op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .in_list = 0,
> .is_por = (type == META_POR) ? 1 : 0,
> diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
> index 747141c79900..c0e39f580993 100644
> --- a/fs/f2fs/compress.c
> +++ b/fs/f2fs/compress.c
> @@ -1282,6 +1282,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
> .op_flags = wbc_to_write_flags(wbc),
> .old_blkaddr = NEW_ADDR,
> .page = NULL,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .compressed_page = NULL,
> .io_type = io_type,
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 95212e60f09d..429fe8998ca3 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -849,6 +849,9 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
> struct folio *fio_folio = fio->folio;
> struct folio *data_folio = fio->encrypted_page ?
> page_folio(fio->encrypted_page) : fio_folio;
> + pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
> + size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
> + size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
>
> if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
> fio->is_por ? META_POR : (__is_meta_io(fio) ?
> @@ -861,11 +864,11 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
> bio = __bio_alloc(fio, 1);
>
> f2fs_set_bio_crypt_ctx(bio, fio_folio->mapping->host,
> - fio_folio->index, fio, GFP_NOIO);
> - bio_add_folio_nofail(bio, data_folio, folio_size(data_folio), 0);
> + fio_lblk, fio, GFP_NOIO);
> + bio_add_folio_nofail(bio, data_folio, bio_len, bio_offset);
bio_len is coming from fio->folio. But, we need to get from data_folio?
>
> if (fio->io_wbc && !is_read_io(fio->op))
> - wbc_account_cgroup_owner(fio->io_wbc, fio_folio, PAGE_SIZE);
> + wbc_account_cgroup_owner(fio->io_wbc, fio_folio, bio_len);
>
> inc_cache_count(fio->sbi, is_read_io(fio->op) ?
> F2FS_RD_DATA : WB_DATA_TYPE(fio->folio, false));
> @@ -924,7 +927,8 @@ static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
> }
>
> static void add_bio_entry(struct f2fs_sb_info *sbi, struct bio *bio,
> - struct folio *folio, enum temp_type temp)
> + struct folio *folio, size_t len, size_t offset,
> + enum temp_type temp)
> {
> struct f2fs_bio_info *io = sbi->write_io[DATA] + temp;
> struct bio_entry *be;
> @@ -933,7 +937,7 @@ static void add_bio_entry(struct f2fs_sb_info *sbi, struct bio *bio,
> be->bio = bio;
> bio_get(bio);
>
> - bio_add_folio_nofail(bio, folio, folio_size(folio), 0);
> + bio_add_folio_nofail(bio, folio, len, offset);
>
> f2fs_down_write(&io->bio_list_lock);
> list_add_tail(&be->list, &io->bio_list);
> @@ -950,6 +954,9 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio,
> struct folio *folio)
> {
> struct folio *fio_folio = fio->folio;
> + pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
> + size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
> + size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
> struct f2fs_sb_info *sbi = fio->sbi;
> enum temp_type temp;
> bool found = false;
> @@ -972,8 +979,8 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio,
> fio->new_blkaddr));
> if (f2fs_crypt_mergeable_bio(*bio,
> fio_folio->mapping->host,
> - fio_folio->index, fio) &&
> - bio_add_folio(*bio, folio, folio_size(folio), 0)) {
> + fio_lblk, fio) &&
> + bio_add_folio(*bio, folio, bio_len, bio_offset)) {
> ret = 0;
> break;
> }
> @@ -1087,6 +1094,10 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
> struct folio *data_folio = fio->encrypted_page ?
> page_folio(fio->encrypted_page) : fio->folio;
> struct folio *folio = fio->folio;
> + pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
> + unsigned int fio_cnt = F2FS_FIO_BLKCNT(fio);
> + size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
> + size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
>
> if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
> __is_meta_io(fio) ? META_GENERIC : DATA_GENERIC))
> @@ -1101,20 +1112,21 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
> if (!bio) {
> bio = __bio_alloc(fio, BIO_MAX_VECS);
> f2fs_set_bio_crypt_ctx(bio, folio->mapping->host,
> - folio->index, fio, GFP_NOIO);
> + fio_lblk, fio, GFP_NOIO);
>
> - add_bio_entry(fio->sbi, bio, data_folio, fio->temp);
> + add_bio_entry(fio->sbi, bio, data_folio, bio_len,
> + bio_offset, fio->temp);
This needs to be from data_folio?
> } else {
> if (add_ipu_page(fio, &bio, data_folio))
> goto alloc_new;
> }
>
> if (fio->io_wbc)
> - wbc_account_cgroup_owner(fio->io_wbc, folio, folio_size(folio));
> + wbc_account_cgroup_owner(fio->io_wbc, folio, bio_len);
>
> inc_cache_count(fio->sbi, WB_DATA_TYPE(folio, false));
>
> - *fio->last_block = fio->new_blkaddr;
> + *fio->last_block = fio->new_blkaddr + fio_cnt - 1;
> *fio->bio = bio;
>
> return 0;
> @@ -1177,6 +1189,10 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
> struct folio *bio_folio;
> struct f2fs_lock_context lc;
> enum count_type type;
> + pgoff_t fio_lblk;
> + unsigned int fio_cnt;
> + size_t bio_offset;
> + size_t bio_len;
>
> f2fs_bug_on(sbi, is_read_io(fio->op));
>
> @@ -1209,24 +1225,31 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
> /* set submitted = true as a return value */
> fio->submitted = 1;
>
> + fio_lblk = F2FS_FIO_LBLK(fio);
> + fio_cnt = F2FS_FIO_BLKCNT(fio);
> +
> type = WB_DATA_TYPE(bio_folio, fio->compressed_page);
> - inc_cache_count(sbi, type);
> + for (unsigned int i = 0; i < fio_cnt; i++)
> + inc_cache_count(sbi, type);
>
> if (io->bio &&
> (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio,
> fio->new_blkaddr) ||
> !f2fs_crypt_mergeable_bio(io->bio, fio_inode(fio),
> - bio_folio->index, fio)))
> + fio_lblk, fio)))
From bio_folio?
> __submit_merged_bio(io);
> alloc_new:
> if (io->bio == NULL) {
> io->bio = __bio_alloc(fio, BIO_MAX_VECS);
> f2fs_set_bio_crypt_ctx(io->bio, fio_inode(fio),
> - bio_folio->index, fio, GFP_NOIO);
> + fio_lblk, fio, GFP_NOIO);
From bio_folio?
> io->fio = *fio;
> }
>
> - if (!bio_add_folio(io->bio, bio_folio, folio_size(bio_folio), 0)) {
> + bio_offset = F2FS_FIO_BIO_OFFSET(fio);
> + bio_len = F2FS_FIO_BIO_SIZE(fio);
> +
> + if (!bio_add_folio(io->bio, bio_folio, bio_len, bio_offset)) {
bio_len/bio_offset need to be from bio_folio?
> __submit_merged_bio(io);
> goto alloc_new;
> }
> @@ -1234,10 +1257,9 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
> F2FS_BIO(io->bio)->entry_cnt++;
>
> if (fio->io_wbc)
> - wbc_account_cgroup_owner(fio->io_wbc, fio->folio,
> - folio_size(fio->folio));
> + wbc_account_cgroup_owner(fio->io_wbc, fio->folio, bio_len);
>
> - io->last_block_in_bio = fio->new_blkaddr;
> + io->last_block_in_bio = fio->new_blkaddr + fio_cnt - 1;
>
> trace_f2fs_submit_folio_write(fio->folio, fio);
> #ifdef CONFIG_BLK_DEV_ZONED
> @@ -3213,7 +3235,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
> set_new_dnode(&dn, inode, NULL, NULL, 0);
>
> if (need_inplace_update(fio) &&
> - f2fs_lookup_read_extent_cache_block(inode, folio->index,
> + f2fs_lookup_read_extent_cache_block(inode,
> + F2FS_FIO_LBLK(fio),
> &fio->old_blkaddr)) {
> if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
> DATA_GENERIC_ENHANCE))
> @@ -3232,7 +3255,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
> if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi, &lc))
> return -EAGAIN;
>
> - err = f2fs_get_dnode_of_data(&dn, folio->index, LOOKUP_NODE);
> + err = f2fs_get_dnode_of_data(&dn, F2FS_FIO_LBLK(fio),
> + LOOKUP_NODE);
> if (err)
> goto out;
>
> @@ -3335,6 +3359,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
> .op_flags = wbc_to_write_flags(wbc),
> .old_blkaddr = NULL_ADDR,
> .folio = folio,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .submitted = 0,
> .compr_blocks = compr_blocks,
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 2fb8ebfa1303..963cd2cdf7ba 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1350,6 +1350,8 @@ struct f2fs_io_info {
> blk_opf_t op_flags; /* req_flag_bits */
> block_t new_blkaddr; /* new block address to be written */
> block_t old_blkaddr; /* old block address before Cow */
> + pgoff_t folio_offset; /* offset in large folio */
> + unsigned int folio_blkcnt; /* block count in large folio */
> union {
> struct page *page; /* page to be written */
> struct folio *folio;
> @@ -1372,6 +1374,15 @@ struct f2fs_io_info {
> sector_t *last_block; /* last block number in bio */
> };
>
> +#define F2FS_FIO_LBLK(fio) \
> + (((fio)->folio)->index + (fio)->folio_offset)
> +#define F2FS_FIO_BLKCNT(fio) \
> + ((fio)->folio_blkcnt)
> +#define F2FS_FIO_BIO_OFFSET(fio) \
> + ((fio)->folio_offset << PAGE_SHIFT)
> +#define F2FS_FIO_BIO_SIZE(fio) \
> + F2FS_BLK_TO_BYTES((fio)->sbi, F2FS_FIO_BLKCNT(fio))
> +
> struct bio_entry {
> struct bio *bio;
> struct list_head list;
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index 926e6976bc22..89e50f871b75 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -1228,6 +1228,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
> .temp = COLD,
> .op = REQ_OP_READ,
> .op_flags = 0,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .in_list = 0,
> .is_cache = 1,
> @@ -1338,6 +1339,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
> .temp = COLD,
> .op = REQ_OP_READ,
> .op_flags = 0,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .in_list = 0,
> .is_cache = 1,
> diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
> index 273b6428c9f9..ab7537ff7ebd 100644
> --- a/fs/f2fs/inline.c
> +++ b/fs/f2fs/inline.c
> @@ -151,6 +151,7 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
> .op = REQ_OP_WRITE,
> .op_flags = REQ_SYNC | REQ_PRIO,
> .folio = folio,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .io_type = FS_DATA_IO,
> };
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 25785b7626bb..96bfb7d63692 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -3876,7 +3876,8 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)
> if (file_is_cold(inode) || f2fs_need_compress_data(inode))
> return CURSEG_COLD_DATA;
>
> - type = __get_age_segment_type(inode, fio->folio->index);
> + type = __get_age_segment_type(inode,
> + F2FS_FIO_LBLK(fio));
> if (type != NO_CHECK_TYPE)
> return type;
>
> --
> 2.43.0
>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 02/16] f2fs: carry subpage offset and count in write IO
@ 2026-10-15 2:37 ` Jaegeuk Kim via Linux-f2fs-devel
0 siblings, 0 replies; 52+ messages in thread
From: Jaegeuk Kim via Linux-f2fs-devel @ 2026-10-15 2:37 UTC (permalink / raw)
To: Nanzhe Zhao
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, linux-kernel,
Dev Jain, David Hildenbrand, Pengfei Li, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, linux-f2fs-devel, Ryan Roberts
On 10/14, Nanzhe Zhao wrote:
> Large folio write paths need to submit I/O for a range inside a
> folio instead of always submitting the whole folio from offset zero.
> Add folio_offset and folio_blkcnt to f2fs_io_info to describe the
> block offset inside the folio and the number of contiguous blocks
> covered by the I/O.
>
> Apply the new fields to the bio submit paths that need the subpage
> offset or contiguous block count.
>
> Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
> ---
> fs/f2fs/checkpoint.c | 2 ++
> fs/f2fs/compress.c | 1 +
> fs/f2fs/data.c | 65 ++++++++++++++++++++++++++++++--------------
> fs/f2fs/f2fs.h | 11 ++++++++
> fs/f2fs/gc.c | 2 ++
> fs/f2fs/inline.c | 1 +
> fs/f2fs/segment.c | 3 +-
> 7 files changed, 64 insertions(+), 21 deletions(-)
>
> diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
> index 5c5b45d3c67b..3ad709f69893 100644
> --- a/fs/f2fs/checkpoint.c
> +++ b/fs/f2fs/checkpoint.c
> @@ -264,6 +264,7 @@ static struct f2fs_cached_block *__get_meta_cache(struct f2fs_sb_info *sbi,
> .op_flags = REQ_META | REQ_PRIO,
> .old_blkaddr = index,
> .new_blkaddr = index,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .is_por = !is_meta ? 1 : 0,
> .is_cache = 1,
> @@ -462,6 +463,7 @@ int f2fs_ra_meta_caches(struct f2fs_sb_info *sbi, block_t start,
> .type = META,
> .op = REQ_OP_READ,
> .op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .in_list = 0,
> .is_por = (type == META_POR) ? 1 : 0,
> diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
> index 747141c79900..c0e39f580993 100644
> --- a/fs/f2fs/compress.c
> +++ b/fs/f2fs/compress.c
> @@ -1282,6 +1282,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
> .op_flags = wbc_to_write_flags(wbc),
> .old_blkaddr = NEW_ADDR,
> .page = NULL,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .compressed_page = NULL,
> .io_type = io_type,
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 95212e60f09d..429fe8998ca3 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -849,6 +849,9 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
> struct folio *fio_folio = fio->folio;
> struct folio *data_folio = fio->encrypted_page ?
> page_folio(fio->encrypted_page) : fio_folio;
> + pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
> + size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
> + size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
>
> if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
> fio->is_por ? META_POR : (__is_meta_io(fio) ?
> @@ -861,11 +864,11 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
> bio = __bio_alloc(fio, 1);
>
> f2fs_set_bio_crypt_ctx(bio, fio_folio->mapping->host,
> - fio_folio->index, fio, GFP_NOIO);
> - bio_add_folio_nofail(bio, data_folio, folio_size(data_folio), 0);
> + fio_lblk, fio, GFP_NOIO);
> + bio_add_folio_nofail(bio, data_folio, bio_len, bio_offset);
bio_len is coming from fio->folio. But, we need to get from data_folio?
>
> if (fio->io_wbc && !is_read_io(fio->op))
> - wbc_account_cgroup_owner(fio->io_wbc, fio_folio, PAGE_SIZE);
> + wbc_account_cgroup_owner(fio->io_wbc, fio_folio, bio_len);
>
> inc_cache_count(fio->sbi, is_read_io(fio->op) ?
> F2FS_RD_DATA : WB_DATA_TYPE(fio->folio, false));
> @@ -924,7 +927,8 @@ static bool io_is_mergeable(struct f2fs_sb_info *sbi, struct bio *bio,
> }
>
> static void add_bio_entry(struct f2fs_sb_info *sbi, struct bio *bio,
> - struct folio *folio, enum temp_type temp)
> + struct folio *folio, size_t len, size_t offset,
> + enum temp_type temp)
> {
> struct f2fs_bio_info *io = sbi->write_io[DATA] + temp;
> struct bio_entry *be;
> @@ -933,7 +937,7 @@ static void add_bio_entry(struct f2fs_sb_info *sbi, struct bio *bio,
> be->bio = bio;
> bio_get(bio);
>
> - bio_add_folio_nofail(bio, folio, folio_size(folio), 0);
> + bio_add_folio_nofail(bio, folio, len, offset);
>
> f2fs_down_write(&io->bio_list_lock);
> list_add_tail(&be->list, &io->bio_list);
> @@ -950,6 +954,9 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio,
> struct folio *folio)
> {
> struct folio *fio_folio = fio->folio;
> + pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
> + size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
> + size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
> struct f2fs_sb_info *sbi = fio->sbi;
> enum temp_type temp;
> bool found = false;
> @@ -972,8 +979,8 @@ static int add_ipu_page(struct f2fs_io_info *fio, struct bio **bio,
> fio->new_blkaddr));
> if (f2fs_crypt_mergeable_bio(*bio,
> fio_folio->mapping->host,
> - fio_folio->index, fio) &&
> - bio_add_folio(*bio, folio, folio_size(folio), 0)) {
> + fio_lblk, fio) &&
> + bio_add_folio(*bio, folio, bio_len, bio_offset)) {
> ret = 0;
> break;
> }
> @@ -1087,6 +1094,10 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
> struct folio *data_folio = fio->encrypted_page ?
> page_folio(fio->encrypted_page) : fio->folio;
> struct folio *folio = fio->folio;
> + pgoff_t fio_lblk = F2FS_FIO_LBLK(fio);
> + unsigned int fio_cnt = F2FS_FIO_BLKCNT(fio);
> + size_t bio_offset = F2FS_FIO_BIO_OFFSET(fio);
> + size_t bio_len = F2FS_FIO_BIO_SIZE(fio);
>
> if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
> __is_meta_io(fio) ? META_GENERIC : DATA_GENERIC))
> @@ -1101,20 +1112,21 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
> if (!bio) {
> bio = __bio_alloc(fio, BIO_MAX_VECS);
> f2fs_set_bio_crypt_ctx(bio, folio->mapping->host,
> - folio->index, fio, GFP_NOIO);
> + fio_lblk, fio, GFP_NOIO);
>
> - add_bio_entry(fio->sbi, bio, data_folio, fio->temp);
> + add_bio_entry(fio->sbi, bio, data_folio, bio_len,
> + bio_offset, fio->temp);
This needs to be from data_folio?
> } else {
> if (add_ipu_page(fio, &bio, data_folio))
> goto alloc_new;
> }
>
> if (fio->io_wbc)
> - wbc_account_cgroup_owner(fio->io_wbc, folio, folio_size(folio));
> + wbc_account_cgroup_owner(fio->io_wbc, folio, bio_len);
>
> inc_cache_count(fio->sbi, WB_DATA_TYPE(folio, false));
>
> - *fio->last_block = fio->new_blkaddr;
> + *fio->last_block = fio->new_blkaddr + fio_cnt - 1;
> *fio->bio = bio;
>
> return 0;
> @@ -1177,6 +1189,10 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
> struct folio *bio_folio;
> struct f2fs_lock_context lc;
> enum count_type type;
> + pgoff_t fio_lblk;
> + unsigned int fio_cnt;
> + size_t bio_offset;
> + size_t bio_len;
>
> f2fs_bug_on(sbi, is_read_io(fio->op));
>
> @@ -1209,24 +1225,31 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
> /* set submitted = true as a return value */
> fio->submitted = 1;
>
> + fio_lblk = F2FS_FIO_LBLK(fio);
> + fio_cnt = F2FS_FIO_BLKCNT(fio);
> +
> type = WB_DATA_TYPE(bio_folio, fio->compressed_page);
> - inc_cache_count(sbi, type);
> + for (unsigned int i = 0; i < fio_cnt; i++)
> + inc_cache_count(sbi, type);
>
> if (io->bio &&
> (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio,
> fio->new_blkaddr) ||
> !f2fs_crypt_mergeable_bio(io->bio, fio_inode(fio),
> - bio_folio->index, fio)))
> + fio_lblk, fio)))
From bio_folio?
> __submit_merged_bio(io);
> alloc_new:
> if (io->bio == NULL) {
> io->bio = __bio_alloc(fio, BIO_MAX_VECS);
> f2fs_set_bio_crypt_ctx(io->bio, fio_inode(fio),
> - bio_folio->index, fio, GFP_NOIO);
> + fio_lblk, fio, GFP_NOIO);
From bio_folio?
> io->fio = *fio;
> }
>
> - if (!bio_add_folio(io->bio, bio_folio, folio_size(bio_folio), 0)) {
> + bio_offset = F2FS_FIO_BIO_OFFSET(fio);
> + bio_len = F2FS_FIO_BIO_SIZE(fio);
> +
> + if (!bio_add_folio(io->bio, bio_folio, bio_len, bio_offset)) {
bio_len/bio_offset need to be from bio_folio?
> __submit_merged_bio(io);
> goto alloc_new;
> }
> @@ -1234,10 +1257,9 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
> F2FS_BIO(io->bio)->entry_cnt++;
>
> if (fio->io_wbc)
> - wbc_account_cgroup_owner(fio->io_wbc, fio->folio,
> - folio_size(fio->folio));
> + wbc_account_cgroup_owner(fio->io_wbc, fio->folio, bio_len);
>
> - io->last_block_in_bio = fio->new_blkaddr;
> + io->last_block_in_bio = fio->new_blkaddr + fio_cnt - 1;
>
> trace_f2fs_submit_folio_write(fio->folio, fio);
> #ifdef CONFIG_BLK_DEV_ZONED
> @@ -3213,7 +3235,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
> set_new_dnode(&dn, inode, NULL, NULL, 0);
>
> if (need_inplace_update(fio) &&
> - f2fs_lookup_read_extent_cache_block(inode, folio->index,
> + f2fs_lookup_read_extent_cache_block(inode,
> + F2FS_FIO_LBLK(fio),
> &fio->old_blkaddr)) {
> if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
> DATA_GENERIC_ENHANCE))
> @@ -3232,7 +3255,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
> if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi, &lc))
> return -EAGAIN;
>
> - err = f2fs_get_dnode_of_data(&dn, folio->index, LOOKUP_NODE);
> + err = f2fs_get_dnode_of_data(&dn, F2FS_FIO_LBLK(fio),
> + LOOKUP_NODE);
> if (err)
> goto out;
>
> @@ -3335,6 +3359,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
> .op_flags = wbc_to_write_flags(wbc),
> .old_blkaddr = NULL_ADDR,
> .folio = folio,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .submitted = 0,
> .compr_blocks = compr_blocks,
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 2fb8ebfa1303..963cd2cdf7ba 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1350,6 +1350,8 @@ struct f2fs_io_info {
> blk_opf_t op_flags; /* req_flag_bits */
> block_t new_blkaddr; /* new block address to be written */
> block_t old_blkaddr; /* old block address before Cow */
> + pgoff_t folio_offset; /* offset in large folio */
> + unsigned int folio_blkcnt; /* block count in large folio */
> union {
> struct page *page; /* page to be written */
> struct folio *folio;
> @@ -1372,6 +1374,15 @@ struct f2fs_io_info {
> sector_t *last_block; /* last block number in bio */
> };
>
> +#define F2FS_FIO_LBLK(fio) \
> + (((fio)->folio)->index + (fio)->folio_offset)
> +#define F2FS_FIO_BLKCNT(fio) \
> + ((fio)->folio_blkcnt)
> +#define F2FS_FIO_BIO_OFFSET(fio) \
> + ((fio)->folio_offset << PAGE_SHIFT)
> +#define F2FS_FIO_BIO_SIZE(fio) \
> + F2FS_BLK_TO_BYTES((fio)->sbi, F2FS_FIO_BLKCNT(fio))
> +
> struct bio_entry {
> struct bio *bio;
> struct list_head list;
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index 926e6976bc22..89e50f871b75 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -1228,6 +1228,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
> .temp = COLD,
> .op = REQ_OP_READ,
> .op_flags = 0,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .in_list = 0,
> .is_cache = 1,
> @@ -1338,6 +1339,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
> .temp = COLD,
> .op = REQ_OP_READ,
> .op_flags = 0,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .in_list = 0,
> .is_cache = 1,
> diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
> index 273b6428c9f9..ab7537ff7ebd 100644
> --- a/fs/f2fs/inline.c
> +++ b/fs/f2fs/inline.c
> @@ -151,6 +151,7 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
> .op = REQ_OP_WRITE,
> .op_flags = REQ_SYNC | REQ_PRIO,
> .folio = folio,
> + .folio_blkcnt = 1,
> .encrypted_page = NULL,
> .io_type = FS_DATA_IO,
> };
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 25785b7626bb..96bfb7d63692 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -3876,7 +3876,8 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)
> if (file_is_cold(inode) || f2fs_need_compress_data(inode))
> return CURSEG_COLD_DATA;
>
> - type = __get_age_segment_type(inode, fio->folio->index);
> + type = __get_age_segment_type(inode,
> + F2FS_FIO_LBLK(fio));
> if (type != NO_CHECK_TYPE)
> return type;
>
> --
> 2.43.0
>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 03/16] f2fs: support regular file buffered writes on large folios
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
To avoid the complexity of unlocking a large folio in write_begin,
preallocate partial blocks for inodes that can use large folios.
During write_begin, read only the partial head and tail 4K subpages
that need read-before-write, and skip read I/O for the full middle
subpages covered by the write.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 405 ++++++++++++++++++++++++++++++++++++++++++++++---
fs/f2fs/f2fs.h | 1 +
fs/f2fs/file.c | 17 ++-
3 files changed, 399 insertions(+), 24 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 429fe8998ca3..a1d2f3b7d9df 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -93,6 +93,20 @@ struct bio_post_read_ctx {
block_t fs_blkaddr;
};
+static bool __ffs_mark_subrange_uptodate(struct folio *folio,
+ struct f2fs_folio_state *ffs, size_t offset, size_t len)
+{
+ unsigned int nr_subpages = folio_nr_pages(folio);
+ unsigned int start, end;
+
+ start = offset >> PAGE_SHIFT;
+ end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ end = min(end, nr_subpages);
+
+ bitmap_set(ffs->state, start, end - start);
+ return bitmap_full(ffs->state, nr_subpages);
+}
+
/*
* Update and unlock a bio's pages, and free the bio.
*
@@ -107,6 +121,23 @@ struct bio_post_read_ctx {
* called (i.e., I/O error or decryption error, but *not* verity error), and
* release the bio's reference to the decompress_io_ctx of the page's cluster.
*/
+/*
+ * Update read_pages_pending.
+ */
+static inline void f2fs_update_read_folio_pending(struct folio *folio, int nr)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned long flags;
+
+ if (!f2fs_folio_has_ffs(folio))
+ return;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ ffs->read_pages_pending += nr;
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+}
+
static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
{
struct folio_iter fi;
@@ -128,7 +159,8 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
}
if (folio_test_large(folio)) {
- struct f2fs_folio_state *ffs = folio->private;
+ struct f2fs_folio_state *ffs =
+ (struct f2fs_folio_state *)folio->private;
spin_lock_irqsave(&ffs->state_lock, flags);
ffs->read_pages_pending -= nr_pages;
@@ -1424,19 +1456,26 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode,
/* This can handle encryption stuffs */
static void f2fs_submit_page_read(struct inode *inode, struct fsverity_info *vi,
- struct folio *folio, block_t blkaddr,
- blk_opf_t op_flags, bool for_write)
+ struct folio *folio, pgoff_t index,
+ block_t blkaddr, blk_opf_t op_flags,
+ bool for_write)
{
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct bio *bio;
+ size_t offset = 0;
+
+ if (f2fs_folio_has_ffs(folio)) {
+ offset = offset_in_folio(folio, (loff_t)index << PAGE_SHIFT);
+ f2fs_update_read_folio_pending(folio, 1);
+ }
- bio = f2fs_grab_read_bio(inode, vi, blkaddr, 1, op_flags, folio->index,
+ bio = f2fs_grab_read_bio(inode, vi, blkaddr, 1, op_flags, index,
for_write);
/* wait for GCed page writeback via generic cache */
f2fs_wait_on_block_writeback(inode, blkaddr);
- if (!bio_add_folio(bio, folio, PAGE_SIZE, 0))
+ if (!bio_add_folio(bio, folio, PAGE_SIZE, offset))
f2fs_bug_on(sbi, 1);
inc_cache_count(sbi, F2FS_RD_DATA);
@@ -1444,6 +1483,39 @@ static void f2fs_submit_page_read(struct inode *inode, struct fsverity_info *vi,
f2fs_submit_read_bio(sbi, bio, DATA);
}
+/*
+ * Synchronously read a single 4K subpage by reusing f2fs_submit_page_read()
+ * so that iostat, trace, blk-crypto and post-read handling are all preserved.
+ * The caller must have already allocated ffs for the folio.
+ */
+static int f2fs_submit_page_read_sync(struct inode *inode, struct folio *folio,
+ pgoff_t index, block_t blkaddr)
+{
+ struct f2fs_folio_state *ffs =
+ (struct f2fs_folio_state *)folio->private;
+
+ if (folio_test_large(folio) && !f2fs_folio_has_ffs(folio))
+ return -EAGAIN;
+
+ /* Add bias so end_io does not call folio_end_read(). */
+ f2fs_update_read_folio_pending(folio, 1);
+
+ f2fs_submit_page_read(inode, NULL, folio, index, blkaddr,
+ REQ_OP_READ, false);
+
+ /* Wait until all bios have completed (pending drops back to our bias). */
+ while (READ_ONCE(ffs->read_pages_pending) != 1)
+ f2fs_io_schedule_timeout(DEFAULT_SCHEDULE_TIMEOUT);
+
+ /* Remove the bias. */
+ f2fs_update_read_folio_pending(folio, -1);
+
+ if (!f2fs_ffs_test_blk_uptodate(folio, index))
+ return -EIO;
+
+ return 0;
+}
+
static void __set_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
{
__le32 *addr = get_dnode_addr(dn->inode, dn->node_entry);
@@ -1617,8 +1689,8 @@ struct folio *f2fs_get_read_data_folio(struct inode *inode, pgoff_t index,
return folio;
}
- f2fs_submit_page_read(inode, f2fs_need_verity(inode, folio->index),
- folio, dn.data_blkaddr, op_flags, for_write);
+ f2fs_submit_page_read(inode, f2fs_need_verity(inode, index),
+ folio, index, dn.data_blkaddr, op_flags, for_write);
return folio;
put_err:
@@ -2780,6 +2852,110 @@ static void ffs_detach_free(struct folio *folio)
kfree(ffs);
}
+bool f2fs_ffs_test_blk_uptodate(const struct folio *folio, pgoff_t index)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned int idx;
+
+ f2fs_bug_on(F2FS_F_SB(folio), !folio_contains(folio, index));
+
+ if (folio_test_uptodate(folio))
+ return true;
+
+ if (!f2fs_folio_has_ffs(folio))
+ return false;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ idx = index - folio->index;
+ return test_bit(idx, ffs->state);
+}
+
+static void f2fs_ffs_mark_subrange_uptodate(struct folio *folio, size_t offset,
+ size_t len)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned long flags;
+ bool mark_uptodate = false;
+
+ f2fs_bug_on(F2FS_F_SB(folio), offset + len > folio_size(folio));
+
+ if (!f2fs_folio_has_ffs(folio)) {
+ folio_mark_uptodate(folio);
+ return;
+ }
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ mark_uptodate = __ffs_mark_subrange_uptodate(folio, ffs, offset, len) &&
+ !ffs->read_pages_pending;
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+ if (mark_uptodate)
+ folio_mark_uptodate(folio);
+}
+
+static unsigned int __ffs_mark_subrange_dirty(struct folio *folio,
+ struct f2fs_folio_state *ffs, size_t offset, size_t len)
+{
+ unsigned int nr_subpages = folio_nr_pages(folio);
+ unsigned int start, end, before;
+
+ start = offset >> PAGE_SHIFT;
+ end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ end = min(end, nr_subpages);
+
+ before = bitmap_weight(ffs->state, 2 * nr_subpages);
+ bitmap_set(ffs->state, nr_subpages + start, end - start);
+ return bitmap_weight(ffs->state, 2 * nr_subpages) - before;
+}
+
+static void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
+ size_t offset, size_t len)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned long flags;
+
+ f2fs_bug_on(F2FS_F_SB(folio), offset + len > folio_size(folio));
+
+ if (!f2fs_folio_has_ffs(folio))
+ return;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ __ffs_mark_subrange_dirty(folio, ffs, offset, len);
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+}
+
+static bool find_next_valid_block(const struct folio *folio,
+ size_t orig_off, size_t *need_off,
+ size_t len)
+{
+ size_t start = orig_off;
+ size_t end = start + len;
+ size_t head, tail;
+ pgoff_t index;
+
+ if (start & (PAGE_SIZE - 1)) {
+ head = round_down(start, PAGE_SIZE);
+ index = folio->index + (head >> PAGE_SHIFT);
+ if (!f2fs_ffs_test_blk_uptodate(folio, index)) {
+ *need_off = head;
+ return true;
+ }
+ }
+
+ if (end & (PAGE_SIZE - 1)) {
+ tail = round_down(end, PAGE_SIZE);
+ index = folio->index + (tail >> PAGE_SHIFT);
+ if (!f2fs_ffs_test_blk_uptodate(folio, index)) {
+ *need_off = tail;
+ return true;
+ }
+ }
+
+ return false;
+}
+
static int f2fs_read_data_large_folio(struct inode *inode,
struct fsverity_info *vi,
struct readahead_control *rac, struct folio *folio)
@@ -4145,6 +4321,147 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
return 0;
}
+/*
+ * Drop the folio lock when a node was changed, then balance the
+ * filesystem and reacquire the lock.
+ *
+ * Return: true if the folio became unusable while unlocked (being
+ * truncated), false if the folio is still usable.
+ */
+static bool f2fs_balance_fs_folio_locked(struct folio *folio,
+ struct address_space *mapping, bool node_changed)
+{
+ struct inode *inode = folio->mapping->host;
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ unsigned int orig_order;
+ bool had_ffs;
+
+ if (!node_changed || IS_NOQUOTA(inode) ||
+ !has_not_enough_free_secs(sbi, 0, 0))
+ return false;
+
+ had_ffs = f2fs_folio_has_ffs(folio);
+ orig_order = folio_order(folio);
+ folio_unlock(folio);
+ f2fs_balance_fs(sbi, true);
+ folio_lock(folio);
+
+ /*
+ * Writeback may have started on the folio during the unlock
+ * window, so wait for it before the caller proceeds.
+ */
+ f2fs_folio_wait_writeback(folio, true, true);
+
+ if (folio->mapping != mapping)
+ return true;
+
+ if (folio_order(folio) != orig_order)
+ return true;
+
+ /* large folio was released */
+ if (had_ffs && !f2fs_folio_has_ffs(folio))
+ return true;
+
+ return false;
+}
+
+static int prepare_large_folio_write_begin(struct inode *inode,
+ struct folio *folio, loff_t pos,
+ unsigned int len)
+{
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ struct f2fs_folio_state *ffs;
+ size_t ori_off = offset_in_folio(folio, pos);
+ size_t need_off = ori_off;
+ int err = 0;
+
+ /*
+ * when the write did not come through f2fs_write_iter, we preallocate all
+ * blocks in the write range here.
+ */
+ if (!is_inode_flag_set(inode, FI_PREALLOCATED_ALL) &&
+ !IS_DEVICE_ALIASING(inode)) {
+ pgoff_t first = F2FS_BYTES_TO_BLK(sbi, pos);
+ pgoff_t last = F2FS_BLK_ALIGN(sbi, pos + len);
+ pgoff_t idx;
+
+ for (idx = first; idx < last; idx++) {
+ block_t blkaddr = NULL_ADDR;
+ bool node_changed = false;
+
+ err = __reserve_data_block(inode, idx, &blkaddr,
+ &node_changed);
+ if (err)
+ return err;
+ if (f2fs_balance_fs_folio_locked(folio, folio->mapping,
+ node_changed))
+ return -EAGAIN;
+ }
+ }
+
+ ffs = f2fs_ffs_find_or_alloc(folio);
+ if (!ffs)
+ return -ENOMEM;
+
+ /* Skip read if the folio is already fully uptodate or the write
+ * covers the entire folio.
+ */
+ if (folio_test_uptodate(folio) || len == folio_size(folio))
+ return 0;
+
+ if (!f2fs_verity_in_progress(inode) &&
+ !(pos & (PAGE_SIZE - 1)) && (pos + len) >= i_size_read(inode)) {
+ size_t zoff = ori_off + len;
+
+ if (zoff < folio_size(folio))
+ folio_zero_segment(folio, zoff, folio_size(folio));
+ return 0;
+ }
+
+ /* Inline data must have been converted before reaching here. */
+ f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
+
+ while (find_next_valid_block(folio, ori_off,
+ &need_off, len)) {
+ struct dnode_of_data dn;
+ pgoff_t index = folio->index + (need_off >> PAGE_SHIFT);
+ block_t blkaddr;
+
+ if (!f2fs_lookup_read_extent_cache_block(inode, index,
+ &blkaddr)) {
+ if (IS_DEVICE_ALIASING(inode))
+ return -ENODATA;
+
+ set_new_dnode(&dn, inode, NULL, NULL, 0);
+ err = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE);
+ if (err)
+ return err;
+ blkaddr = dn.data_blkaddr;
+ f2fs_put_dnode(&dn);
+
+ if (blkaddr == NEW_ADDR) {
+ size_t off = offset_in_folio(folio,
+ (loff_t)index << PAGE_SHIFT);
+
+ folio_zero_segment(folio, off, off + PAGE_SIZE);
+ f2fs_ffs_mark_subrange_uptodate(folio, off,
+ PAGE_SIZE);
+ continue;
+ }
+
+ if (!f2fs_is_valid_blkaddr(sbi, blkaddr,
+ DATA_GENERIC_ENHANCE_READ))
+ return -EFSCORRUPTED;
+ }
+
+ err = f2fs_submit_page_read_sync(inode, folio, index, 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,
@@ -4156,6 +4473,8 @@ static int f2fs_write_begin(const struct kiocb *iocb,
pgoff_t index = pos >> PAGE_SHIFT;
bool need_balance = false;
block_t blkaddr = NULL_ADDR;
+ fgf_t fgp = FGP_LOCK | FGP_WRITE | FGP_CREAT;
+ unsigned int blen;
int err = 0;
trace_f2fs_write_begin(inode, pos, len);
@@ -4203,9 +4522,15 @@ static int f2fs_write_begin(const struct kiocb *iocb,
* Do not use FGP_STABLE to avoid deadlock.
* Will wait that below with our IO control.
*/
- folio = f2fs_filemap_get_folio(mapping, index,
- FGP_LOCK | FGP_WRITE | FGP_CREAT,
- mapping_gfp_mask(mapping));
+ /*
+ * Inline data is carried in the first subpage. Keep the index #0
+ * folio order-0 so that the existing inline read/convert paths
+ * (prepare_write_begin()) still apply; large folios are used from
+ * the second folio on.
+ */
+ fgp |= fgf_set_order(f2fs_has_inline_data(inode) ? PAGE_SIZE : len);
+ folio = f2fs_filemap_get_folio(mapping, index, fgp,
+ mapping_gfp_mask(mapping));
if (IS_ERR(folio)) {
err = PTR_ERR(folio);
goto fail;
@@ -4215,11 +4540,15 @@ static int f2fs_write_begin(const struct kiocb *iocb,
*foliop = folio;
+ /* Clamp the write length to the folio size. */
+ blen = min_t(unsigned int, len,
+ folio_size(folio) - offset_in_folio(folio, pos));
+
if (f2fs_is_atomic_file(inode))
err = prepare_atomic_write_begin(sbi, folio, pos, len,
&blkaddr, &need_balance);
- else
- err = prepare_write_begin(sbi, folio, pos, len,
+ else if (!folio_test_large(folio))
+ err = prepare_write_begin(sbi, folio, pos, blen,
&blkaddr, &need_balance);
if (err)
goto put_folio;
@@ -4239,7 +4568,19 @@ static int f2fs_write_begin(const struct kiocb *iocb,
f2fs_folio_wait_writeback(folio, false, true);
- if (len == folio_size(folio) || folio_test_uptodate(folio))
+ if (folio_test_large(folio)) {
+ err = prepare_large_folio_write_begin(inode,
+ folio, pos, blen);
+ if (!err)
+ return 0;
+ if (err == -EAGAIN) {
+ f2fs_folio_put(folio, true);
+ goto repeat;
+ }
+ goto put_folio;
+ }
+
+ if (blen == folio_size(folio) || folio_test_uptodate(folio))
return 0;
if (!(pos & (PAGE_SIZE - 1)) && (pos + len) >= i_size_read(inode) &&
@@ -4267,7 +4608,7 @@ static int f2fs_write_begin(const struct kiocb *iocb,
*/
f2fs_submit_page_read(inode,
NULL, /* can't write to fsverity files */
- folio, blkaddr, 0, true);
+ folio, index, blkaddr, 0, true);
folio_lock(folio);
if (unlikely(folio->mapping != mapping)) {
@@ -4299,15 +4640,20 @@ static int f2fs_write_end(const struct kiocb *iocb,
trace_f2fs_write_end(inode, pos, len, copied);
/*
- * This should be come from len == PAGE_SIZE, and we expect copied
- * should be PAGE_SIZE. Otherwise, we treat it with zero copied and
- * let generic_perform_write() try to copy data again through copied=0.
+ * If a short copy happens on a folio that isn't uptodate, we treat
+ * it with zero copied and let generic_perform_write() try to copy
+ * data again through copied=0.
*/
if (!folio_test_uptodate(folio)) {
- if (unlikely(copied != len))
+ if (unlikely(copied != len)) {
copied = 0;
- else
+ } else if (folio_test_large(folio)) {
+ f2fs_ffs_mark_subrange_uptodate(folio,
+ offset_in_folio(folio, pos), len);
+ } else {
+ /* This should be come from len == PAGE_SIZE */
folio_mark_uptodate(folio);
+ }
}
#ifdef CONFIG_F2FS_FS_COMPRESSION
@@ -4326,6 +4672,9 @@ static int f2fs_write_end(const struct kiocb *iocb,
if (!copied)
goto unlock_out;
+ if (folio_test_large(folio))
+ f2fs_ffs_mark_subrange_dirty(folio, offset_in_folio(folio, pos),
+ copied);
folio_mark_dirty(folio);
if (f2fs_is_atomic_file(inode))
@@ -4382,8 +4731,22 @@ static bool f2fs_dirty_data_folio(struct address_space *mapping,
trace_f2fs_set_page_dirty(folio, DATA);
- if (!folio_test_uptodate(folio))
- folio_mark_uptodate(folio);
+ if (!folio_test_uptodate(folio)) {
+ bool uptodate = true;
+
+ if (f2fs_folio_has_ffs(folio)) {
+ struct f2fs_folio_state *ffs =
+ (struct f2fs_folio_state *)folio->private;
+ unsigned long flags;
+
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ uptodate = bitmap_full(ffs->state, folio_nr_pages(folio)) &&
+ !ffs->read_pages_pending;
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+ }
+ if (uptodate)
+ folio_mark_uptodate(folio);
+ }
BUG_ON(folio_test_swapcache(folio));
if (filemap_dirty_folio(mapping, folio)) {
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 963cd2cdf7ba..6db23a3c25a9 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4454,6 +4454,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
struct writeback_control *wbc,
enum iostat_type io_type,
int compr_blocks, bool allow_balance);
+bool f2fs_ffs_test_blk_uptodate(const struct folio *folio, pgoff_t index);
void f2fs_write_failed(struct inode *inode, loff_t to);
void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length);
bool f2fs_release_folio(struct folio *folio, gfp_t wait);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 1ff505e4ba11..e53cdb4467b4 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -5424,9 +5424,20 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,
return ret;
}
- /* Do not preallocate blocks that will be written partially in 4KB. */
- map.m_lblk = F2FS_BLK_ALIGN(sbi, pos);
- map.m_len = F2FS_BYTES_TO_BLK(sbi, pos + count);
+ if (!dio && mapping_large_folio_support(inode->i_mapping)) {
+ /*
+ * Preallocate all blocks touched by a large-folio buffered write so
+ * the regular write_begin path does not need to unlock the folio for
+ * f2fs_balance_fs(). Rechecking large-folio state after unlock is
+ * unreliable since partial truncation can split the folio.
+ */
+ map.m_lblk = F2FS_BYTES_TO_BLK(sbi, pos);
+ map.m_len = F2FS_BLK_ALIGN(sbi, pos + count);
+ } else {
+ /* Do not preallocate blocks that will be written partially in 4KB. */
+ map.m_lblk = F2FS_BLK_ALIGN(sbi, pos);
+ map.m_len = F2FS_BYTES_TO_BLK(sbi, pos + count);
+ }
if (map.m_len > map.m_lblk)
map.m_len -= map.m_lblk;
else
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 03/16] f2fs: support regular file buffered writes on large folios
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
To avoid the complexity of unlocking a large folio in write_begin,
preallocate partial blocks for inodes that can use large folios.
During write_begin, read only the partial head and tail 4K subpages
that need read-before-write, and skip read I/O for the full middle
subpages covered by the write.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 405 ++++++++++++++++++++++++++++++++++++++++++++++---
fs/f2fs/f2fs.h | 1 +
fs/f2fs/file.c | 17 ++-
3 files changed, 399 insertions(+), 24 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 429fe8998ca3..a1d2f3b7d9df 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -93,6 +93,20 @@ struct bio_post_read_ctx {
block_t fs_blkaddr;
};
+static bool __ffs_mark_subrange_uptodate(struct folio *folio,
+ struct f2fs_folio_state *ffs, size_t offset, size_t len)
+{
+ unsigned int nr_subpages = folio_nr_pages(folio);
+ unsigned int start, end;
+
+ start = offset >> PAGE_SHIFT;
+ end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ end = min(end, nr_subpages);
+
+ bitmap_set(ffs->state, start, end - start);
+ return bitmap_full(ffs->state, nr_subpages);
+}
+
/*
* Update and unlock a bio's pages, and free the bio.
*
@@ -107,6 +121,23 @@ struct bio_post_read_ctx {
* called (i.e., I/O error or decryption error, but *not* verity error), and
* release the bio's reference to the decompress_io_ctx of the page's cluster.
*/
+/*
+ * Update read_pages_pending.
+ */
+static inline void f2fs_update_read_folio_pending(struct folio *folio, int nr)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned long flags;
+
+ if (!f2fs_folio_has_ffs(folio))
+ return;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ ffs->read_pages_pending += nr;
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+}
+
static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
{
struct folio_iter fi;
@@ -128,7 +159,8 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
}
if (folio_test_large(folio)) {
- struct f2fs_folio_state *ffs = folio->private;
+ struct f2fs_folio_state *ffs =
+ (struct f2fs_folio_state *)folio->private;
spin_lock_irqsave(&ffs->state_lock, flags);
ffs->read_pages_pending -= nr_pages;
@@ -1424,19 +1456,26 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode,
/* This can handle encryption stuffs */
static void f2fs_submit_page_read(struct inode *inode, struct fsverity_info *vi,
- struct folio *folio, block_t blkaddr,
- blk_opf_t op_flags, bool for_write)
+ struct folio *folio, pgoff_t index,
+ block_t blkaddr, blk_opf_t op_flags,
+ bool for_write)
{
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct bio *bio;
+ size_t offset = 0;
+
+ if (f2fs_folio_has_ffs(folio)) {
+ offset = offset_in_folio(folio, (loff_t)index << PAGE_SHIFT);
+ f2fs_update_read_folio_pending(folio, 1);
+ }
- bio = f2fs_grab_read_bio(inode, vi, blkaddr, 1, op_flags, folio->index,
+ bio = f2fs_grab_read_bio(inode, vi, blkaddr, 1, op_flags, index,
for_write);
/* wait for GCed page writeback via generic cache */
f2fs_wait_on_block_writeback(inode, blkaddr);
- if (!bio_add_folio(bio, folio, PAGE_SIZE, 0))
+ if (!bio_add_folio(bio, folio, PAGE_SIZE, offset))
f2fs_bug_on(sbi, 1);
inc_cache_count(sbi, F2FS_RD_DATA);
@@ -1444,6 +1483,39 @@ static void f2fs_submit_page_read(struct inode *inode, struct fsverity_info *vi,
f2fs_submit_read_bio(sbi, bio, DATA);
}
+/*
+ * Synchronously read a single 4K subpage by reusing f2fs_submit_page_read()
+ * so that iostat, trace, blk-crypto and post-read handling are all preserved.
+ * The caller must have already allocated ffs for the folio.
+ */
+static int f2fs_submit_page_read_sync(struct inode *inode, struct folio *folio,
+ pgoff_t index, block_t blkaddr)
+{
+ struct f2fs_folio_state *ffs =
+ (struct f2fs_folio_state *)folio->private;
+
+ if (folio_test_large(folio) && !f2fs_folio_has_ffs(folio))
+ return -EAGAIN;
+
+ /* Add bias so end_io does not call folio_end_read(). */
+ f2fs_update_read_folio_pending(folio, 1);
+
+ f2fs_submit_page_read(inode, NULL, folio, index, blkaddr,
+ REQ_OP_READ, false);
+
+ /* Wait until all bios have completed (pending drops back to our bias). */
+ while (READ_ONCE(ffs->read_pages_pending) != 1)
+ f2fs_io_schedule_timeout(DEFAULT_SCHEDULE_TIMEOUT);
+
+ /* Remove the bias. */
+ f2fs_update_read_folio_pending(folio, -1);
+
+ if (!f2fs_ffs_test_blk_uptodate(folio, index))
+ return -EIO;
+
+ return 0;
+}
+
static void __set_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
{
__le32 *addr = get_dnode_addr(dn->inode, dn->node_entry);
@@ -1617,8 +1689,8 @@ struct folio *f2fs_get_read_data_folio(struct inode *inode, pgoff_t index,
return folio;
}
- f2fs_submit_page_read(inode, f2fs_need_verity(inode, folio->index),
- folio, dn.data_blkaddr, op_flags, for_write);
+ f2fs_submit_page_read(inode, f2fs_need_verity(inode, index),
+ folio, index, dn.data_blkaddr, op_flags, for_write);
return folio;
put_err:
@@ -2780,6 +2852,110 @@ static void ffs_detach_free(struct folio *folio)
kfree(ffs);
}
+bool f2fs_ffs_test_blk_uptodate(const struct folio *folio, pgoff_t index)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned int idx;
+
+ f2fs_bug_on(F2FS_F_SB(folio), !folio_contains(folio, index));
+
+ if (folio_test_uptodate(folio))
+ return true;
+
+ if (!f2fs_folio_has_ffs(folio))
+ return false;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ idx = index - folio->index;
+ return test_bit(idx, ffs->state);
+}
+
+static void f2fs_ffs_mark_subrange_uptodate(struct folio *folio, size_t offset,
+ size_t len)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned long flags;
+ bool mark_uptodate = false;
+
+ f2fs_bug_on(F2FS_F_SB(folio), offset + len > folio_size(folio));
+
+ if (!f2fs_folio_has_ffs(folio)) {
+ folio_mark_uptodate(folio);
+ return;
+ }
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ mark_uptodate = __ffs_mark_subrange_uptodate(folio, ffs, offset, len) &&
+ !ffs->read_pages_pending;
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+ if (mark_uptodate)
+ folio_mark_uptodate(folio);
+}
+
+static unsigned int __ffs_mark_subrange_dirty(struct folio *folio,
+ struct f2fs_folio_state *ffs, size_t offset, size_t len)
+{
+ unsigned int nr_subpages = folio_nr_pages(folio);
+ unsigned int start, end, before;
+
+ start = offset >> PAGE_SHIFT;
+ end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ end = min(end, nr_subpages);
+
+ before = bitmap_weight(ffs->state, 2 * nr_subpages);
+ bitmap_set(ffs->state, nr_subpages + start, end - start);
+ return bitmap_weight(ffs->state, 2 * nr_subpages) - before;
+}
+
+static void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
+ size_t offset, size_t len)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned long flags;
+
+ f2fs_bug_on(F2FS_F_SB(folio), offset + len > folio_size(folio));
+
+ if (!f2fs_folio_has_ffs(folio))
+ return;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ __ffs_mark_subrange_dirty(folio, ffs, offset, len);
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+}
+
+static bool find_next_valid_block(const struct folio *folio,
+ size_t orig_off, size_t *need_off,
+ size_t len)
+{
+ size_t start = orig_off;
+ size_t end = start + len;
+ size_t head, tail;
+ pgoff_t index;
+
+ if (start & (PAGE_SIZE - 1)) {
+ head = round_down(start, PAGE_SIZE);
+ index = folio->index + (head >> PAGE_SHIFT);
+ if (!f2fs_ffs_test_blk_uptodate(folio, index)) {
+ *need_off = head;
+ return true;
+ }
+ }
+
+ if (end & (PAGE_SIZE - 1)) {
+ tail = round_down(end, PAGE_SIZE);
+ index = folio->index + (tail >> PAGE_SHIFT);
+ if (!f2fs_ffs_test_blk_uptodate(folio, index)) {
+ *need_off = tail;
+ return true;
+ }
+ }
+
+ return false;
+}
+
static int f2fs_read_data_large_folio(struct inode *inode,
struct fsverity_info *vi,
struct readahead_control *rac, struct folio *folio)
@@ -4145,6 +4321,147 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
return 0;
}
+/*
+ * Drop the folio lock when a node was changed, then balance the
+ * filesystem and reacquire the lock.
+ *
+ * Return: true if the folio became unusable while unlocked (being
+ * truncated), false if the folio is still usable.
+ */
+static bool f2fs_balance_fs_folio_locked(struct folio *folio,
+ struct address_space *mapping, bool node_changed)
+{
+ struct inode *inode = folio->mapping->host;
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ unsigned int orig_order;
+ bool had_ffs;
+
+ if (!node_changed || IS_NOQUOTA(inode) ||
+ !has_not_enough_free_secs(sbi, 0, 0))
+ return false;
+
+ had_ffs = f2fs_folio_has_ffs(folio);
+ orig_order = folio_order(folio);
+ folio_unlock(folio);
+ f2fs_balance_fs(sbi, true);
+ folio_lock(folio);
+
+ /*
+ * Writeback may have started on the folio during the unlock
+ * window, so wait for it before the caller proceeds.
+ */
+ f2fs_folio_wait_writeback(folio, true, true);
+
+ if (folio->mapping != mapping)
+ return true;
+
+ if (folio_order(folio) != orig_order)
+ return true;
+
+ /* large folio was released */
+ if (had_ffs && !f2fs_folio_has_ffs(folio))
+ return true;
+
+ return false;
+}
+
+static int prepare_large_folio_write_begin(struct inode *inode,
+ struct folio *folio, loff_t pos,
+ unsigned int len)
+{
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ struct f2fs_folio_state *ffs;
+ size_t ori_off = offset_in_folio(folio, pos);
+ size_t need_off = ori_off;
+ int err = 0;
+
+ /*
+ * when the write did not come through f2fs_write_iter, we preallocate all
+ * blocks in the write range here.
+ */
+ if (!is_inode_flag_set(inode, FI_PREALLOCATED_ALL) &&
+ !IS_DEVICE_ALIASING(inode)) {
+ pgoff_t first = F2FS_BYTES_TO_BLK(sbi, pos);
+ pgoff_t last = F2FS_BLK_ALIGN(sbi, pos + len);
+ pgoff_t idx;
+
+ for (idx = first; idx < last; idx++) {
+ block_t blkaddr = NULL_ADDR;
+ bool node_changed = false;
+
+ err = __reserve_data_block(inode, idx, &blkaddr,
+ &node_changed);
+ if (err)
+ return err;
+ if (f2fs_balance_fs_folio_locked(folio, folio->mapping,
+ node_changed))
+ return -EAGAIN;
+ }
+ }
+
+ ffs = f2fs_ffs_find_or_alloc(folio);
+ if (!ffs)
+ return -ENOMEM;
+
+ /* Skip read if the folio is already fully uptodate or the write
+ * covers the entire folio.
+ */
+ if (folio_test_uptodate(folio) || len == folio_size(folio))
+ return 0;
+
+ if (!f2fs_verity_in_progress(inode) &&
+ !(pos & (PAGE_SIZE - 1)) && (pos + len) >= i_size_read(inode)) {
+ size_t zoff = ori_off + len;
+
+ if (zoff < folio_size(folio))
+ folio_zero_segment(folio, zoff, folio_size(folio));
+ return 0;
+ }
+
+ /* Inline data must have been converted before reaching here. */
+ f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
+
+ while (find_next_valid_block(folio, ori_off,
+ &need_off, len)) {
+ struct dnode_of_data dn;
+ pgoff_t index = folio->index + (need_off >> PAGE_SHIFT);
+ block_t blkaddr;
+
+ if (!f2fs_lookup_read_extent_cache_block(inode, index,
+ &blkaddr)) {
+ if (IS_DEVICE_ALIASING(inode))
+ return -ENODATA;
+
+ set_new_dnode(&dn, inode, NULL, NULL, 0);
+ err = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE);
+ if (err)
+ return err;
+ blkaddr = dn.data_blkaddr;
+ f2fs_put_dnode(&dn);
+
+ if (blkaddr == NEW_ADDR) {
+ size_t off = offset_in_folio(folio,
+ (loff_t)index << PAGE_SHIFT);
+
+ folio_zero_segment(folio, off, off + PAGE_SIZE);
+ f2fs_ffs_mark_subrange_uptodate(folio, off,
+ PAGE_SIZE);
+ continue;
+ }
+
+ if (!f2fs_is_valid_blkaddr(sbi, blkaddr,
+ DATA_GENERIC_ENHANCE_READ))
+ return -EFSCORRUPTED;
+ }
+
+ err = f2fs_submit_page_read_sync(inode, folio, index, 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,
@@ -4156,6 +4473,8 @@ static int f2fs_write_begin(const struct kiocb *iocb,
pgoff_t index = pos >> PAGE_SHIFT;
bool need_balance = false;
block_t blkaddr = NULL_ADDR;
+ fgf_t fgp = FGP_LOCK | FGP_WRITE | FGP_CREAT;
+ unsigned int blen;
int err = 0;
trace_f2fs_write_begin(inode, pos, len);
@@ -4203,9 +4522,15 @@ static int f2fs_write_begin(const struct kiocb *iocb,
* Do not use FGP_STABLE to avoid deadlock.
* Will wait that below with our IO control.
*/
- folio = f2fs_filemap_get_folio(mapping, index,
- FGP_LOCK | FGP_WRITE | FGP_CREAT,
- mapping_gfp_mask(mapping));
+ /*
+ * Inline data is carried in the first subpage. Keep the index #0
+ * folio order-0 so that the existing inline read/convert paths
+ * (prepare_write_begin()) still apply; large folios are used from
+ * the second folio on.
+ */
+ fgp |= fgf_set_order(f2fs_has_inline_data(inode) ? PAGE_SIZE : len);
+ folio = f2fs_filemap_get_folio(mapping, index, fgp,
+ mapping_gfp_mask(mapping));
if (IS_ERR(folio)) {
err = PTR_ERR(folio);
goto fail;
@@ -4215,11 +4540,15 @@ static int f2fs_write_begin(const struct kiocb *iocb,
*foliop = folio;
+ /* Clamp the write length to the folio size. */
+ blen = min_t(unsigned int, len,
+ folio_size(folio) - offset_in_folio(folio, pos));
+
if (f2fs_is_atomic_file(inode))
err = prepare_atomic_write_begin(sbi, folio, pos, len,
&blkaddr, &need_balance);
- else
- err = prepare_write_begin(sbi, folio, pos, len,
+ else if (!folio_test_large(folio))
+ err = prepare_write_begin(sbi, folio, pos, blen,
&blkaddr, &need_balance);
if (err)
goto put_folio;
@@ -4239,7 +4568,19 @@ static int f2fs_write_begin(const struct kiocb *iocb,
f2fs_folio_wait_writeback(folio, false, true);
- if (len == folio_size(folio) || folio_test_uptodate(folio))
+ if (folio_test_large(folio)) {
+ err = prepare_large_folio_write_begin(inode,
+ folio, pos, blen);
+ if (!err)
+ return 0;
+ if (err == -EAGAIN) {
+ f2fs_folio_put(folio, true);
+ goto repeat;
+ }
+ goto put_folio;
+ }
+
+ if (blen == folio_size(folio) || folio_test_uptodate(folio))
return 0;
if (!(pos & (PAGE_SIZE - 1)) && (pos + len) >= i_size_read(inode) &&
@@ -4267,7 +4608,7 @@ static int f2fs_write_begin(const struct kiocb *iocb,
*/
f2fs_submit_page_read(inode,
NULL, /* can't write to fsverity files */
- folio, blkaddr, 0, true);
+ folio, index, blkaddr, 0, true);
folio_lock(folio);
if (unlikely(folio->mapping != mapping)) {
@@ -4299,15 +4640,20 @@ static int f2fs_write_end(const struct kiocb *iocb,
trace_f2fs_write_end(inode, pos, len, copied);
/*
- * This should be come from len == PAGE_SIZE, and we expect copied
- * should be PAGE_SIZE. Otherwise, we treat it with zero copied and
- * let generic_perform_write() try to copy data again through copied=0.
+ * If a short copy happens on a folio that isn't uptodate, we treat
+ * it with zero copied and let generic_perform_write() try to copy
+ * data again through copied=0.
*/
if (!folio_test_uptodate(folio)) {
- if (unlikely(copied != len))
+ if (unlikely(copied != len)) {
copied = 0;
- else
+ } else if (folio_test_large(folio)) {
+ f2fs_ffs_mark_subrange_uptodate(folio,
+ offset_in_folio(folio, pos), len);
+ } else {
+ /* This should be come from len == PAGE_SIZE */
folio_mark_uptodate(folio);
+ }
}
#ifdef CONFIG_F2FS_FS_COMPRESSION
@@ -4326,6 +4672,9 @@ static int f2fs_write_end(const struct kiocb *iocb,
if (!copied)
goto unlock_out;
+ if (folio_test_large(folio))
+ f2fs_ffs_mark_subrange_dirty(folio, offset_in_folio(folio, pos),
+ copied);
folio_mark_dirty(folio);
if (f2fs_is_atomic_file(inode))
@@ -4382,8 +4731,22 @@ static bool f2fs_dirty_data_folio(struct address_space *mapping,
trace_f2fs_set_page_dirty(folio, DATA);
- if (!folio_test_uptodate(folio))
- folio_mark_uptodate(folio);
+ if (!folio_test_uptodate(folio)) {
+ bool uptodate = true;
+
+ if (f2fs_folio_has_ffs(folio)) {
+ struct f2fs_folio_state *ffs =
+ (struct f2fs_folio_state *)folio->private;
+ unsigned long flags;
+
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ uptodate = bitmap_full(ffs->state, folio_nr_pages(folio)) &&
+ !ffs->read_pages_pending;
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+ }
+ if (uptodate)
+ folio_mark_uptodate(folio);
+ }
BUG_ON(folio_test_swapcache(folio));
if (filemap_dirty_folio(mapping, folio)) {
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 963cd2cdf7ba..6db23a3c25a9 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4454,6 +4454,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
struct writeback_control *wbc,
enum iostat_type io_type,
int compr_blocks, bool allow_balance);
+bool f2fs_ffs_test_blk_uptodate(const struct folio *folio, pgoff_t index);
void f2fs_write_failed(struct inode *inode, loff_t to);
void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length);
bool f2fs_release_folio(struct folio *folio, gfp_t wait);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 1ff505e4ba11..e53cdb4467b4 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -5424,9 +5424,20 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,
return ret;
}
- /* Do not preallocate blocks that will be written partially in 4KB. */
- map.m_lblk = F2FS_BLK_ALIGN(sbi, pos);
- map.m_len = F2FS_BYTES_TO_BLK(sbi, pos + count);
+ if (!dio && mapping_large_folio_support(inode->i_mapping)) {
+ /*
+ * Preallocate all blocks touched by a large-folio buffered write so
+ * the regular write_begin path does not need to unlock the folio for
+ * f2fs_balance_fs(). Rechecking large-folio state after unlock is
+ * unreliable since partial truncation can split the folio.
+ */
+ map.m_lblk = F2FS_BYTES_TO_BLK(sbi, pos);
+ map.m_len = F2FS_BLK_ALIGN(sbi, pos + count);
+ } else {
+ /* Do not preallocate blocks that will be written partially in 4KB. */
+ map.m_lblk = F2FS_BLK_ALIGN(sbi, pos);
+ map.m_len = F2FS_BYTES_TO_BLK(sbi, pos + count);
+ }
if (map.m_len > map.m_lblk)
map.m_len -= map.m_lblk;
else
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 03/16] f2fs: support regular file buffered writes on large folios
2026-10-14 6:44 ` Nanzhe Zhao
(?)
@ 2026-10-14 16:18 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 16:18 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu; +Cc: Daeho Jeong
Sashiko says:
> Kernel panic (NULL pointer dereference). In prepare_large_folio_atomic_write_begin(),
> f2fs_ffs_find_or_alloc() allocates folio->private. Then it enters a subpage loop. Inside
> the loop, it calls f2fs_balance_fs_folio_locked(), which temporarily drops the folio lock.
> If memory pressure triggers reclaim during this unlocked window, shrink_folio_list() can
> lock the folio, call filemap_release_folio() -> f2fs_release_folio() -> ffs_detach_free(),
> and free folio->private. Because the caller still holds a reference to the folio, the
> folio is not evicted and folio->mapping remains valid. f2fs_balance_fs_folio_locked()
> reacquires the lock, sees the mapping is valid, and returns false. The loop then continues
> to the next index without re-allocating or checking folio->private. When
> f2fs_submit_page_read_sync() is called, it blindly dereferences folio->private (which is
> now NULL), causing a crash.
Changes:
@@ -4306,11 +4334,13 @@ static bool f2fs_balance_fs_folio_locked(struct folio *folio,
struct inode *inode = folio->mapping->host;
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
unsigned int orig_order;
+ bool had_ffs;
if (!node_changed || IS_NOQUOTA(inode) ||
!has_not_enough_free_secs(sbi, 0, 0))
return false;
+ had_ffs = f2fs_folio_has_ffs(folio);
orig_order = folio_order(folio);
folio_unlock(folio);
f2fs_balance_fs(sbi, true);
@@ -4328,6 +4358,10 @@ static bool f2fs_balance_fs_folio_locked(struct folio *folio,
if (folio_order(folio) != orig_order)
return true;
+ /* large folio was released */
+ if (had_ffs && !f2fs_folio_has_ffs(folio))
+ return true;
+
return false;
}
v4 only revalidated mapping and order after unlocking. v5 samples `had_ffs` before
unlocking and returns true if the ffs was lost, so the caller retries and re-allocates it.
`had_ffs` is needed because the non-atomic caller allocates the ffs after its balance loop,
so a plain `if(folio_test_large(folio) && !f2fs_folio_has_ffs(folio)` check would loop on -EAGAIN.
Sashiko: https://sashiko.dev/#/patchset/20261013115621.968742-1-nzzhao.sigma%40gmail.com
Thanks,
Nanzhe Zhao
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 04/16] f2fs: support atomic file large folios buffered write
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
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 | 111 ++++++++++++++++++++++++++++++++++++-------------
1 file changed, 81 insertions(+), 30 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index a1d2f3b7d9df..c9a213a5e6a2 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -4273,18 +4273,16 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
}
static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
- struct folio *folio, loff_t pos, unsigned int len,
+ struct inode *inode, pgoff_t index,
block_t *blk_addr, bool *node_changed)
{
- struct inode *inode = folio->mapping->host;
struct inode *cow_inode = F2FS_I(inode)->cow_inode;
- pgoff_t index = folio->index;
int err = 0;
block_t ori_blk_addr = NULL_ADDR;
bool cow_has_reserved_block = false;
- /* If pos is beyond the end of file, reserve a new block in COW inode */
- if ((pos & PAGE_MASK) >= i_size_read(inode))
+ /* If index is beyond the end of file, reserve a new block in COW inode */
+ if (((loff_t)index << PAGE_SHIFT) >= i_size_read(inode))
goto reserve_block;
/* Look for the block in COW inode first */
@@ -4462,6 +4460,61 @@ 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);
+ size_t ori_off = offset_in_folio(folio, pos);
+ pgoff_t start, end, index;
+ int err = 0;
+
+ len = min_t(unsigned int, len, folio_size(folio) - ori_off);
+
+ if (!f2fs_ffs_find_or_alloc(folio))
+ return -ENOMEM;
+
+ /* Inline data must have been converted before reaching here. */
+ f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
+
+ start = folio->index + (ori_off >> PAGE_SHIFT);
+ end = folio->index + ((ori_off + len - 1) >> PAGE_SHIFT);
+
+ for (index = start; index <= end; index++) {
+ block_t blkaddr = NULL_ADDR;
+ bool node_changed = false;
+ size_t off = (index - folio->index) << PAGE_SHIFT;
+
+ err = prepare_atomic_write_begin(sbi, inode, index,
+ &blkaddr, &node_changed);
+ if (err)
+ return err;
+
+ if (f2fs_ffs_test_blk_uptodate(folio, index))
+ goto balance;
+
+ if (blkaddr == NEW_ADDR) {
+ folio_zero_segment(folio, off, off + PAGE_SIZE);
+ f2fs_ffs_mark_subrange_uptodate(folio, off, PAGE_SIZE);
+ goto balance;
+ }
+
+ if (!f2fs_is_valid_blkaddr(sbi, blkaddr,
+ DATA_GENERIC_ENHANCE_READ))
+ return -EFSCORRUPTED;
+
+ err = f2fs_submit_page_read_sync(inode, folio, index,
+ blkaddr);
+ if (err)
+ return err;
+balance:
+ if (f2fs_balance_fs_folio_locked(folio, mapping, node_changed))
+ return -EAGAIN;
+ }
+
+ return 0;
+}
+
static int f2fs_write_begin(const struct kiocb *iocb,
struct address_space *mapping,
loff_t pos, unsigned len, struct folio **foliop,
@@ -4544,35 +4597,25 @@ static int f2fs_write_begin(const struct kiocb *iocb,
blen = min_t(unsigned int, len,
folio_size(folio) - offset_in_folio(folio, pos));
- if (f2fs_is_atomic_file(inode))
- err = prepare_atomic_write_begin(sbi, folio, pos, len,
+ /*
+ * Flush the cached IO of this folio and make sure it is stable
+ * before touching it, especially for the large folio prepare
+ * below which reads and updates subpage states.
+ */
+ f2fs_folio_wait_writeback(folio, false, true);
+
+ if (f2fs_is_atomic_file(inode) && !folio_test_large(folio))
+ err = prepare_atomic_write_begin(sbi, inode, folio->index,
&blkaddr, &need_balance);
else if (!folio_test_large(folio))
err = prepare_write_begin(sbi, folio, pos, blen,
&blkaddr, &need_balance);
- if (err)
- goto put_folio;
-
- if (need_balance && !IS_NOQUOTA(inode) &&
- has_not_enough_free_secs(sbi, 0, 0)) {
- folio_unlock(folio);
- f2fs_balance_fs(sbi, true);
- folio_lock(folio);
- if (folio->mapping != mapping) {
- /* The folio got truncated from under us */
- folio_unlock(folio);
- folio_put(folio);
- goto repeat;
- }
- }
-
- f2fs_folio_wait_writeback(folio, false, true);
-
- if (folio_test_large(folio)) {
- err = prepare_large_folio_write_begin(inode,
- folio, pos, blen);
- if (!err)
- return 0;
+ else 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, blen);
+ if (err) {
if (err == -EAGAIN) {
f2fs_folio_put(folio, true);
goto repeat;
@@ -4580,6 +4623,14 @@ static int f2fs_write_begin(const struct kiocb *iocb,
goto put_folio;
}
+ if (f2fs_balance_fs_folio_locked(folio, mapping, need_balance)) {
+ f2fs_folio_put(folio, true);
+ goto repeat;
+ }
+
+ if (folio_test_large(folio))
+ return 0;
+
if (blen == folio_size(folio) || folio_test_uptodate(folio))
return 0;
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 04/16] f2fs: support atomic file large folios buffered write
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
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 | 111 ++++++++++++++++++++++++++++++++++++-------------
1 file changed, 81 insertions(+), 30 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index a1d2f3b7d9df..c9a213a5e6a2 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -4273,18 +4273,16 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
}
static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
- struct folio *folio, loff_t pos, unsigned int len,
+ struct inode *inode, pgoff_t index,
block_t *blk_addr, bool *node_changed)
{
- struct inode *inode = folio->mapping->host;
struct inode *cow_inode = F2FS_I(inode)->cow_inode;
- pgoff_t index = folio->index;
int err = 0;
block_t ori_blk_addr = NULL_ADDR;
bool cow_has_reserved_block = false;
- /* If pos is beyond the end of file, reserve a new block in COW inode */
- if ((pos & PAGE_MASK) >= i_size_read(inode))
+ /* If index is beyond the end of file, reserve a new block in COW inode */
+ if (((loff_t)index << PAGE_SHIFT) >= i_size_read(inode))
goto reserve_block;
/* Look for the block in COW inode first */
@@ -4462,6 +4460,61 @@ 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);
+ size_t ori_off = offset_in_folio(folio, pos);
+ pgoff_t start, end, index;
+ int err = 0;
+
+ len = min_t(unsigned int, len, folio_size(folio) - ori_off);
+
+ if (!f2fs_ffs_find_or_alloc(folio))
+ return -ENOMEM;
+
+ /* Inline data must have been converted before reaching here. */
+ f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
+
+ start = folio->index + (ori_off >> PAGE_SHIFT);
+ end = folio->index + ((ori_off + len - 1) >> PAGE_SHIFT);
+
+ for (index = start; index <= end; index++) {
+ block_t blkaddr = NULL_ADDR;
+ bool node_changed = false;
+ size_t off = (index - folio->index) << PAGE_SHIFT;
+
+ err = prepare_atomic_write_begin(sbi, inode, index,
+ &blkaddr, &node_changed);
+ if (err)
+ return err;
+
+ if (f2fs_ffs_test_blk_uptodate(folio, index))
+ goto balance;
+
+ if (blkaddr == NEW_ADDR) {
+ folio_zero_segment(folio, off, off + PAGE_SIZE);
+ f2fs_ffs_mark_subrange_uptodate(folio, off, PAGE_SIZE);
+ goto balance;
+ }
+
+ if (!f2fs_is_valid_blkaddr(sbi, blkaddr,
+ DATA_GENERIC_ENHANCE_READ))
+ return -EFSCORRUPTED;
+
+ err = f2fs_submit_page_read_sync(inode, folio, index,
+ blkaddr);
+ if (err)
+ return err;
+balance:
+ if (f2fs_balance_fs_folio_locked(folio, mapping, node_changed))
+ return -EAGAIN;
+ }
+
+ return 0;
+}
+
static int f2fs_write_begin(const struct kiocb *iocb,
struct address_space *mapping,
loff_t pos, unsigned len, struct folio **foliop,
@@ -4544,35 +4597,25 @@ static int f2fs_write_begin(const struct kiocb *iocb,
blen = min_t(unsigned int, len,
folio_size(folio) - offset_in_folio(folio, pos));
- if (f2fs_is_atomic_file(inode))
- err = prepare_atomic_write_begin(sbi, folio, pos, len,
+ /*
+ * Flush the cached IO of this folio and make sure it is stable
+ * before touching it, especially for the large folio prepare
+ * below which reads and updates subpage states.
+ */
+ f2fs_folio_wait_writeback(folio, false, true);
+
+ if (f2fs_is_atomic_file(inode) && !folio_test_large(folio))
+ err = prepare_atomic_write_begin(sbi, inode, folio->index,
&blkaddr, &need_balance);
else if (!folio_test_large(folio))
err = prepare_write_begin(sbi, folio, pos, blen,
&blkaddr, &need_balance);
- if (err)
- goto put_folio;
-
- if (need_balance && !IS_NOQUOTA(inode) &&
- has_not_enough_free_secs(sbi, 0, 0)) {
- folio_unlock(folio);
- f2fs_balance_fs(sbi, true);
- folio_lock(folio);
- if (folio->mapping != mapping) {
- /* The folio got truncated from under us */
- folio_unlock(folio);
- folio_put(folio);
- goto repeat;
- }
- }
-
- f2fs_folio_wait_writeback(folio, false, true);
-
- if (folio_test_large(folio)) {
- err = prepare_large_folio_write_begin(inode,
- folio, pos, blen);
- if (!err)
- return 0;
+ else 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, blen);
+ if (err) {
if (err == -EAGAIN) {
f2fs_folio_put(folio, true);
goto repeat;
@@ -4580,6 +4623,14 @@ static int f2fs_write_begin(const struct kiocb *iocb,
goto put_folio;
}
+ if (f2fs_balance_fs_folio_locked(folio, mapping, need_balance)) {
+ f2fs_folio_put(folio, true);
+ goto repeat;
+ }
+
+ if (folio_test_large(folio))
+ return 0;
+
if (blen == folio_size(folio) || folio_test_uptodate(folio))
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 05/16] f2fs: support large folio writeback
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
Large folio can contain multiple dirty ranges.
Add a folio-based writeback path for large-folio mapping files
and keep the legacy f2fs_write_cache_pages() path unchanged for
non large-folio mapping files.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 475 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 470 insertions(+), 5 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index c9a213a5e6a2..9701d2d2da89 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -373,7 +373,9 @@ static void f2fs_write_end_bio(struct bio *bio)
bio_for_each_folio_all(fi, bio) {
struct folio *folio = fi.folio;
+ unsigned int nr_pages = fi.length >> PAGE_SHIFT;
enum count_type type;
+ bool finished = true;
#ifdef CONFIG_F2FS_FS_COMPRESSION
if (f2fs_is_compressed_page(folio)) {
@@ -392,7 +394,16 @@ static void f2fs_write_end_bio(struct bio *bio)
}
}
- dec_cache_count(sbi, type);
+ if (f2fs_folio_has_ffs(folio)) {
+ struct f2fs_folio_state *ffs =
+ (struct f2fs_folio_state *)folio->private;
+
+ finished = atomic_sub_and_test(nr_pages,
+ &ffs->write_pages_pending);
+ }
+
+ while (nr_pages--)
+ dec_cache_count(sbi, type);
/*
* we should access sbi before folio_end_writeback() to
@@ -402,8 +413,10 @@ static void f2fs_write_end_bio(struct bio *bio)
wq_has_sleeper(&sbi->cp_wait))
wake_up(&sbi->cp_wait);
- folio_clear_f2fs_gcing(folio);
- folio_end_writeback(folio);
+ if (finished) {
+ folio_clear_f2fs_gcing(folio);
+ folio_end_writeback(folio);
+ }
}
bio_put(bio);
@@ -2908,7 +2921,7 @@ static unsigned int __ffs_mark_subrange_dirty(struct folio *folio,
return bitmap_weight(ffs->state, 2 * nr_subpages) - before;
}
-static void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
+void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
size_t offset, size_t len)
{
struct f2fs_folio_state *ffs;
@@ -2926,6 +2939,99 @@ static void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
spin_unlock_irqrestore(&ffs->state_lock, flags);
}
+static bool __ffs_clear_subrange_dirty(struct folio *folio,
+ struct f2fs_folio_state *ffs, size_t offset, size_t len)
+{
+ unsigned int nr_subpages = folio_nr_pages(folio);
+ unsigned int start, end;
+
+ start = offset >> PAGE_SHIFT;
+ end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ end = min(end, nr_subpages);
+
+ bitmap_clear(ffs->state, nr_subpages + start, end - start);
+ return find_next_bit(ffs->state, 2 * nr_subpages, nr_subpages) <
+ 2 * nr_subpages;
+}
+
+/**
+ * f2fs_ffs_clear_subrange_dirty_and_test - clear dirty bits and test remaining
+ * @folio: the large folio
+ * @offset: start byte offset within the folio
+ * @len: byte length of the subrange
+ *
+ * Clear the dirty bits of the 4K subpages covered by [offset, offset + len),
+ * and return whether the folio still has any dirty subpage left.
+ */
+bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
+ size_t len)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned long flags;
+ bool dirty;
+
+ if (!f2fs_folio_has_ffs(folio))
+ return false;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ dirty = __ffs_clear_subrange_dirty(folio, ffs, offset, len);
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+
+ return dirty;
+}
+
+static unsigned int ffs_next_dirty_subpage(struct f2fs_folio_state *ffs,
+ const struct folio *folio, unsigned int start,
+ unsigned int end)
+{
+ unsigned int nr_subpages = folio_nr_pages(folio);
+
+ return find_next_bit(ffs->state, nr_subpages + end + 1,
+ nr_subpages + start) - nr_subpages;
+}
+
+static unsigned int ffs_next_clean_subpage(struct f2fs_folio_state *ffs,
+ const struct folio *folio, unsigned int start,
+ unsigned int end)
+{
+ unsigned int nr_subpages = folio_nr_pages(folio);
+
+ return find_next_zero_bit(ffs->state, nr_subpages + end + 1,
+ nr_subpages + start) - nr_subpages;
+}
+
+static unsigned int ffs_find_dirty_range(struct folio *folio,
+ u64 *range_start, u64 range_end)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned int start, end, nr_pages;
+
+ if (*range_start >= range_end)
+ return 0;
+
+ if (!f2fs_folio_has_ffs(folio))
+ return range_end - *range_start;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ start = offset_in_folio(folio, *range_start) >> PAGE_SHIFT;
+ end = DIV_ROUND_UP(min_not_zero(offset_in_folio(folio, range_end),
+ folio_size(folio)), PAGE_SIZE) - 1;
+
+ start = ffs_next_dirty_subpage(ffs, folio, start, end);
+ if (start > end)
+ return 0;
+
+ if (start == end)
+ nr_pages = 1;
+ else
+ nr_pages = ffs_next_clean_subpage(ffs, folio,
+ start + 1, end) - start;
+
+ *range_start = folio_pos(folio) + ((u64)start << PAGE_SHIFT);
+ return (u64)nr_pages << PAGE_SHIFT;
+}
+
static bool find_next_valid_block(const struct folio *folio,
size_t orig_off, size_t *need_off,
size_t len)
@@ -3509,6 +3615,144 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
return err;
}
+static int f2fs_write_folio_dirty_range(struct folio *folio, int *submitted,
+ struct writeback_control *wbc,
+ enum iostat_type io_type,
+ u64 *pos, u64 len)
+{
+ struct inode *inode = folio->mapping->host;
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ bool atomic_commit = f2fs_is_atomic_file(inode) &&
+ folio_test_f2fs_atomic(folio);
+ struct inode *dn_inode = atomic_commit ?
+ F2FS_I(inode)->cow_inode : inode;
+ struct f2fs_folio_state *ffs = NULL;
+ u64 folio_start = folio_pos(folio);
+ pgoff_t start_idx = (*pos - folio_start) >> PAGE_SHIFT;
+ pgoff_t end_idx = (*pos - folio_start + len - 1) >> PAGE_SHIFT;
+ int err = 0;
+
+ for (pgoff_t i = start_idx; i <= end_idx && !err; i++) {
+ struct dnode_of_data dn;
+ struct node_info ni;
+ pgoff_t data_idx = folio->index + i;
+ bool ipu_force = false;
+ bool dn_held = false;
+ bool submitted_blk = false;
+ struct f2fs_io_info fio = {
+ .sbi = sbi,
+ .ino = inode->i_ino,
+ .type = DATA,
+ .op = REQ_OP_WRITE,
+ .op_flags = wbc_to_write_flags(wbc),
+ .old_blkaddr = NULL_ADDR,
+ .folio = folio,
+ .folio_offset = i,
+ .folio_blkcnt = 1,
+ .encrypted_page = NULL,
+ .submitted = 0,
+ .need_lock = LOCK_DONE,
+ .meta_gc = f2fs_meta_inode_gc_required(inode) ? 1 : 0,
+ .io_type = io_type,
+ .io_wbc = wbc,
+ };
+
+ if (f2fs_folio_has_ffs(folio)) {
+ ffs = (struct f2fs_folio_state *)folio->private;
+ atomic_inc(&ffs->write_pages_pending);
+ }
+
+ set_new_dnode(&dn, dn_inode, NULL, NULL, 0);
+
+ if (need_inplace_update(&fio) &&
+ f2fs_lookup_read_extent_cache_block(inode, data_idx,
+ &fio.old_blkaddr)) {
+ if (!f2fs_is_valid_blkaddr(sbi, fio.old_blkaddr,
+ DATA_GENERIC_ENHANCE)) {
+ err = -EFSCORRUPTED;
+ goto block_done;
+ }
+ ipu_force = true;
+ goto got_it;
+ }
+
+ err = f2fs_get_dnode_of_data(&dn, data_idx, LOOKUP_NODE);
+ if (err)
+ goto block_done;
+ dn_held = true;
+
+ fio.old_blkaddr = dn.data_blkaddr;
+
+got_it:
+ if (__is_valid_data_blkaddr(fio.old_blkaddr) &&
+ !f2fs_is_valid_blkaddr(sbi, fio.old_blkaddr,
+ DATA_GENERIC_ENHANCE)) {
+ err = -EFSCORRUPTED;
+ goto block_done;
+ }
+
+ if (fio.meta_gc)
+ f2fs_wait_on_block_writeback(inode, fio.old_blkaddr);
+
+ if (ipu_force ||
+ (__is_valid_data_blkaddr(fio.old_blkaddr) &&
+ need_inplace_update(&fio))) {
+ f2fs_put_dnode(&dn);
+ dn_held = false;
+ err = f2fs_inplace_write_data(&fio);
+ trace_f2fs_do_write_data_page(folio, IPU);
+ if (err)
+ goto block_done;
+
+ if (submitted)
+ (*submitted)++;
+ submitted_blk = true;
+ set_inode_flag(inode, FI_UPDATE_WRITE);
+ goto block_done;
+ }
+
+ err = f2fs_get_node_info(sbi, dn.nid, &ni, false);
+ if (err)
+ goto block_done;
+
+ fio.version = ni.version;
+
+ f2fs_outplace_write_data(&dn, &fio);
+ /*
+ * The outplace write path failed to submit this block.
+ */
+ if (!fio.submitted) {
+ err = -EIO;
+ goto block_done;
+ }
+ if (submitted)
+ (*submitted)++;
+ submitted_blk = true;
+ set_inode_flag(inode, FI_APPEND_WRITE);
+ trace_f2fs_do_write_data_page(folio, OPU);
+block_done:
+ if (dn_held)
+ f2fs_put_dnode(&dn);
+ /*
+ * If this block was not submitted, roll back its
+ * write pages pending.
+ */
+ if (!submitted_blk && ffs)
+ atomic_dec(&ffs->write_pages_pending);
+ if (!err) {
+ *pos = ((loff_t)data_idx + 1) << PAGE_SHIFT;
+ spin_lock(&F2FS_I(inode)->i_size_lock);
+ if (F2FS_I(inode)->last_disk_size < *pos)
+ F2FS_I(inode)->last_disk_size = *pos;
+ spin_unlock(&F2FS_I(inode)->i_size_lock);
+ } else {
+ file_set_keep_isize(inode);
+ }
+ }
+
+ return err;
+}
+
int f2fs_write_single_data_page(struct folio *folio, int *submitted,
struct bio **bio,
sector_t *last_block,
@@ -3958,6 +4202,223 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
return ret;
}
+static int f2fs_write_cache_folios(struct address_space *mapping,
+ struct writeback_control *wbc,
+ enum iostat_type io_type)
+{
+ struct folio *folio = NULL;
+ struct inode *inode = mapping->host;
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ struct f2fs_lock_context lc;
+ u64 pos = 0;
+ u64 end_pos = 0;
+ u32 r_len = 0;
+ int err = 0;
+ int submitted = 0;
+ int nwritten = 0;
+ bool op_locked = false;
+ bool retry = false;
+
+ if (get_dirty_pages(inode) <= SM_I(sbi)->min_hot_blocks)
+ set_inode_flag(inode, FI_HOT_DATA);
+ else
+ clear_inode_flag(inode, FI_HOT_DATA);
+
+ while ((folio = writeback_iter(mapping, wbc, folio, &err))) {
+ struct f2fs_folio_state *ffs = NULL;
+ u64 isize;
+ size_t poff;
+ pgoff_t end_index;
+ bool verity_in_progress;
+ int folio_submitted = 0;
+ bool bias_added = false;
+
+ submitted = 0;
+ retry = false;
+
+ if (err) {
+ folio_redirty_for_writepage(wbc, folio);
+ goto retry_out;
+ }
+
+ if (atomic_read(&sbi->wb_sync_req[DATA]) &&
+ wbc->sync_mode == WB_SYNC_NONE) {
+ folio_redirty_for_writepage(wbc, folio);
+ /*
+ * A WB_SYNC_ALL writeback is in progress, so defer
+ * this writeback. Mark the error as -EBUSY to let
+ * writeback_iter() stop iterating.
+ */
+ err = -EBUSY;
+ goto retry_out;
+ }
+
+ /*
+ * If cp_error is set, all subpages of this folio are not written
+ * back unless the filesystem is mounted with errors=remount-ro.
+ */
+ if (unlikely(f2fs_cp_error(sbi))) {
+ mapping_set_error(folio->mapping, -EIO);
+ if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY)
+ folio_redirty_for_writepage(wbc, folio);
+ else
+ f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
+ folio_size(folio));
+ goto retry_out;
+ }
+
+ /*
+ * Writing back one large folio performs multiple block allocations, so
+ * best-effort balance the filesystem before writing it back.
+ */
+ if (!F2FS_I(inode)->wb_task && has_not_enough_free_secs(sbi, 0, 0)) {
+ folio_redirty_for_writepage(wbc, folio);
+ retry = true;
+ folio_unlock(folio);
+ f2fs_balance_fs(sbi, true);
+ folio_lock(folio);
+ goto retry;
+ }
+retry:
+ pos = folio_pos(folio);
+ end_pos = pos + folio_size(folio);
+ isize = i_size_read(inode);
+ verity_in_progress = f2fs_verity_in_progress(inode);
+ poff = 0;
+ end_index = 0;
+
+ if (retry) {
+
+ if (unlikely(folio->mapping != mapping))
+ goto retry_out;
+
+ if (!folio_test_dirty(folio))
+ goto retry_out;
+
+ if (folio_test_writeback(folio)) {
+ if (wbc->sync_mode == WB_SYNC_NONE)
+ goto retry_out;
+ f2fs_folio_wait_writeback(folio, true, true);
+ }
+
+ if (!folio_clear_dirty_for_io(folio))
+ goto retry_out;
+ }
+
+ /* To avoid dealing with the complexity for one subrange is in bio
+ * while we trylock_op failed before writing another subrange.
+ * Try to lock_op before any subrange write for the folio.
+ */
+ if (!op_locked) {
+ if (!f2fs_trylock_op(sbi, &lc)) {
+ folio_redirty_for_writepage(wbc, folio);
+ err = 0;
+ if (wbc->sync_mode != WB_SYNC_ALL)
+ goto retry_out;
+
+ retry = true;
+ folio_unlock(folio);
+ f2fs_io_schedule_timeout(DEFAULT_SCHEDULE_TIMEOUT);
+ folio_lock(folio);
+ goto retry;
+ }
+ op_locked = true;
+ }
+
+ if (!verity_in_progress) {
+ poff = offset_in_folio(folio, isize);
+ end_index = isize >> PAGE_SHIFT;
+
+ if (folio->index > end_index ||
+ (folio->index == end_index && poff == 0))
+ goto out;
+
+ if (end_pos > isize) {
+ folio_zero_segment(folio, poff, folio_size(folio));
+ end_pos = isize;
+ }
+ }
+
+ folio_start_writeback(folio);
+
+ /*
+ * Large folios can be submitted as multiple bios, which may
+ * complete while we are still submitting the remaining dirty
+ * ranges. Hold a bias on write_pages_pending to prevent
+ * folio_end_writeback() from being called early.
+ */
+ if (!bias_added && f2fs_folio_has_ffs(folio)) {
+ ffs = (struct f2fs_folio_state *)folio->private;
+ WARN_ON_ONCE(atomic_read(&ffs->write_pages_pending) != 0);
+ atomic_inc(&ffs->write_pages_pending);
+ bias_added = true;
+ }
+
+ while ((r_len = ffs_find_dirty_range(folio, &pos, end_pos))) {
+ err = f2fs_write_folio_dirty_range(folio, &submitted,
+ wbc, io_type, &pos, r_len);
+ folio_submitted += submitted;
+ nwritten += submitted;
+ if (err)
+ goto out;
+ }
+
+ /* If none of the subpages of a folio is submitted, keep the atomic flag */
+ if (folio_submitted &&
+ f2fs_is_atomic_file(inode) &&
+ folio_test_f2fs_atomic(folio))
+ folio_clear_f2fs_atomic(folio);
+
+out:
+ /*
+ * Clear the dirty state of the subranges that were written back.
+ * If some subranges are still dirty (e.g. the folio was only
+ * partially written back), the folio must stay dirty so that
+ * the remaining subranges are written back later.
+ */
+ if (f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
+ (err ? pos : end_pos) - folio_pos(folio)))
+ folio_redirty_for_writepage(wbc, folio);
+ else
+ inode_dec_dirty_pages(inode);
+
+ /*
+ * Release the bias taken above and we end writeback here if
+ * no write bio is in flight.
+ */
+ if (bias_added &&
+ atomic_dec_and_test(&ffs->write_pages_pending)) {
+ folio_end_writeback(folio);
+ } else if (!folio_submitted && folio_test_writeback(folio)) {
+ /*
+ * Order-0 folios take no bias, so end the writeback
+ * if nothing was submitted.
+ */
+ folio_end_writeback(folio);
+ }
+
+retry_out:
+ if (op_locked) {
+ f2fs_unlock_op(sbi, &lc);
+ op_locked = false;
+ }
+
+ folio_unlock(folio);
+ }
+
+ if (nwritten)
+ f2fs_submit_merged_write_cond(F2FS_M_SB(mapping), mapping->host,
+ NULL);
+
+ /*
+ * Prevent the -EBUSY error that stopped writeback_iter() from
+ * propagating to the user.
+ */
+ if (err == -EBUSY)
+ err = 0;
+ return err;
+}
+
static inline bool __should_serialize_io(struct inode *inode,
struct writeback_control *wbc)
{
@@ -4052,7 +4513,11 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
account_writeback(inode, true);
blk_start_plug(&plug);
- ret = f2fs_write_cache_pages(mapping, wbc, io_type);
+ if (mapping_large_folio_support(inode->i_mapping) &&
+ !f2fs_has_inline_data(inode))
+ ret = f2fs_write_cache_folios(mapping, wbc, io_type);
+ else
+ ret = f2fs_write_cache_pages(mapping, wbc, io_type);
blk_finish_plug(&plug);
account_writeback(inode, false);
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 05/16] f2fs: support large folio writeback
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
Large folio can contain multiple dirty ranges.
Add a folio-based writeback path for large-folio mapping files
and keep the legacy f2fs_write_cache_pages() path unchanged for
non large-folio mapping files.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 475 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 470 insertions(+), 5 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index c9a213a5e6a2..9701d2d2da89 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -373,7 +373,9 @@ static void f2fs_write_end_bio(struct bio *bio)
bio_for_each_folio_all(fi, bio) {
struct folio *folio = fi.folio;
+ unsigned int nr_pages = fi.length >> PAGE_SHIFT;
enum count_type type;
+ bool finished = true;
#ifdef CONFIG_F2FS_FS_COMPRESSION
if (f2fs_is_compressed_page(folio)) {
@@ -392,7 +394,16 @@ static void f2fs_write_end_bio(struct bio *bio)
}
}
- dec_cache_count(sbi, type);
+ if (f2fs_folio_has_ffs(folio)) {
+ struct f2fs_folio_state *ffs =
+ (struct f2fs_folio_state *)folio->private;
+
+ finished = atomic_sub_and_test(nr_pages,
+ &ffs->write_pages_pending);
+ }
+
+ while (nr_pages--)
+ dec_cache_count(sbi, type);
/*
* we should access sbi before folio_end_writeback() to
@@ -402,8 +413,10 @@ static void f2fs_write_end_bio(struct bio *bio)
wq_has_sleeper(&sbi->cp_wait))
wake_up(&sbi->cp_wait);
- folio_clear_f2fs_gcing(folio);
- folio_end_writeback(folio);
+ if (finished) {
+ folio_clear_f2fs_gcing(folio);
+ folio_end_writeback(folio);
+ }
}
bio_put(bio);
@@ -2908,7 +2921,7 @@ static unsigned int __ffs_mark_subrange_dirty(struct folio *folio,
return bitmap_weight(ffs->state, 2 * nr_subpages) - before;
}
-static void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
+void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
size_t offset, size_t len)
{
struct f2fs_folio_state *ffs;
@@ -2926,6 +2939,99 @@ static void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
spin_unlock_irqrestore(&ffs->state_lock, flags);
}
+static bool __ffs_clear_subrange_dirty(struct folio *folio,
+ struct f2fs_folio_state *ffs, size_t offset, size_t len)
+{
+ unsigned int nr_subpages = folio_nr_pages(folio);
+ unsigned int start, end;
+
+ start = offset >> PAGE_SHIFT;
+ end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ end = min(end, nr_subpages);
+
+ bitmap_clear(ffs->state, nr_subpages + start, end - start);
+ return find_next_bit(ffs->state, 2 * nr_subpages, nr_subpages) <
+ 2 * nr_subpages;
+}
+
+/**
+ * f2fs_ffs_clear_subrange_dirty_and_test - clear dirty bits and test remaining
+ * @folio: the large folio
+ * @offset: start byte offset within the folio
+ * @len: byte length of the subrange
+ *
+ * Clear the dirty bits of the 4K subpages covered by [offset, offset + len),
+ * and return whether the folio still has any dirty subpage left.
+ */
+bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
+ size_t len)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned long flags;
+ bool dirty;
+
+ if (!f2fs_folio_has_ffs(folio))
+ return false;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ dirty = __ffs_clear_subrange_dirty(folio, ffs, offset, len);
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+
+ return dirty;
+}
+
+static unsigned int ffs_next_dirty_subpage(struct f2fs_folio_state *ffs,
+ const struct folio *folio, unsigned int start,
+ unsigned int end)
+{
+ unsigned int nr_subpages = folio_nr_pages(folio);
+
+ return find_next_bit(ffs->state, nr_subpages + end + 1,
+ nr_subpages + start) - nr_subpages;
+}
+
+static unsigned int ffs_next_clean_subpage(struct f2fs_folio_state *ffs,
+ const struct folio *folio, unsigned int start,
+ unsigned int end)
+{
+ unsigned int nr_subpages = folio_nr_pages(folio);
+
+ return find_next_zero_bit(ffs->state, nr_subpages + end + 1,
+ nr_subpages + start) - nr_subpages;
+}
+
+static unsigned int ffs_find_dirty_range(struct folio *folio,
+ u64 *range_start, u64 range_end)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned int start, end, nr_pages;
+
+ if (*range_start >= range_end)
+ return 0;
+
+ if (!f2fs_folio_has_ffs(folio))
+ return range_end - *range_start;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ start = offset_in_folio(folio, *range_start) >> PAGE_SHIFT;
+ end = DIV_ROUND_UP(min_not_zero(offset_in_folio(folio, range_end),
+ folio_size(folio)), PAGE_SIZE) - 1;
+
+ start = ffs_next_dirty_subpage(ffs, folio, start, end);
+ if (start > end)
+ return 0;
+
+ if (start == end)
+ nr_pages = 1;
+ else
+ nr_pages = ffs_next_clean_subpage(ffs, folio,
+ start + 1, end) - start;
+
+ *range_start = folio_pos(folio) + ((u64)start << PAGE_SHIFT);
+ return (u64)nr_pages << PAGE_SHIFT;
+}
+
static bool find_next_valid_block(const struct folio *folio,
size_t orig_off, size_t *need_off,
size_t len)
@@ -3509,6 +3615,144 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
return err;
}
+static int f2fs_write_folio_dirty_range(struct folio *folio, int *submitted,
+ struct writeback_control *wbc,
+ enum iostat_type io_type,
+ u64 *pos, u64 len)
+{
+ struct inode *inode = folio->mapping->host;
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ bool atomic_commit = f2fs_is_atomic_file(inode) &&
+ folio_test_f2fs_atomic(folio);
+ struct inode *dn_inode = atomic_commit ?
+ F2FS_I(inode)->cow_inode : inode;
+ struct f2fs_folio_state *ffs = NULL;
+ u64 folio_start = folio_pos(folio);
+ pgoff_t start_idx = (*pos - folio_start) >> PAGE_SHIFT;
+ pgoff_t end_idx = (*pos - folio_start + len - 1) >> PAGE_SHIFT;
+ int err = 0;
+
+ for (pgoff_t i = start_idx; i <= end_idx && !err; i++) {
+ struct dnode_of_data dn;
+ struct node_info ni;
+ pgoff_t data_idx = folio->index + i;
+ bool ipu_force = false;
+ bool dn_held = false;
+ bool submitted_blk = false;
+ struct f2fs_io_info fio = {
+ .sbi = sbi,
+ .ino = inode->i_ino,
+ .type = DATA,
+ .op = REQ_OP_WRITE,
+ .op_flags = wbc_to_write_flags(wbc),
+ .old_blkaddr = NULL_ADDR,
+ .folio = folio,
+ .folio_offset = i,
+ .folio_blkcnt = 1,
+ .encrypted_page = NULL,
+ .submitted = 0,
+ .need_lock = LOCK_DONE,
+ .meta_gc = f2fs_meta_inode_gc_required(inode) ? 1 : 0,
+ .io_type = io_type,
+ .io_wbc = wbc,
+ };
+
+ if (f2fs_folio_has_ffs(folio)) {
+ ffs = (struct f2fs_folio_state *)folio->private;
+ atomic_inc(&ffs->write_pages_pending);
+ }
+
+ set_new_dnode(&dn, dn_inode, NULL, NULL, 0);
+
+ if (need_inplace_update(&fio) &&
+ f2fs_lookup_read_extent_cache_block(inode, data_idx,
+ &fio.old_blkaddr)) {
+ if (!f2fs_is_valid_blkaddr(sbi, fio.old_blkaddr,
+ DATA_GENERIC_ENHANCE)) {
+ err = -EFSCORRUPTED;
+ goto block_done;
+ }
+ ipu_force = true;
+ goto got_it;
+ }
+
+ err = f2fs_get_dnode_of_data(&dn, data_idx, LOOKUP_NODE);
+ if (err)
+ goto block_done;
+ dn_held = true;
+
+ fio.old_blkaddr = dn.data_blkaddr;
+
+got_it:
+ if (__is_valid_data_blkaddr(fio.old_blkaddr) &&
+ !f2fs_is_valid_blkaddr(sbi, fio.old_blkaddr,
+ DATA_GENERIC_ENHANCE)) {
+ err = -EFSCORRUPTED;
+ goto block_done;
+ }
+
+ if (fio.meta_gc)
+ f2fs_wait_on_block_writeback(inode, fio.old_blkaddr);
+
+ if (ipu_force ||
+ (__is_valid_data_blkaddr(fio.old_blkaddr) &&
+ need_inplace_update(&fio))) {
+ f2fs_put_dnode(&dn);
+ dn_held = false;
+ err = f2fs_inplace_write_data(&fio);
+ trace_f2fs_do_write_data_page(folio, IPU);
+ if (err)
+ goto block_done;
+
+ if (submitted)
+ (*submitted)++;
+ submitted_blk = true;
+ set_inode_flag(inode, FI_UPDATE_WRITE);
+ goto block_done;
+ }
+
+ err = f2fs_get_node_info(sbi, dn.nid, &ni, false);
+ if (err)
+ goto block_done;
+
+ fio.version = ni.version;
+
+ f2fs_outplace_write_data(&dn, &fio);
+ /*
+ * The outplace write path failed to submit this block.
+ */
+ if (!fio.submitted) {
+ err = -EIO;
+ goto block_done;
+ }
+ if (submitted)
+ (*submitted)++;
+ submitted_blk = true;
+ set_inode_flag(inode, FI_APPEND_WRITE);
+ trace_f2fs_do_write_data_page(folio, OPU);
+block_done:
+ if (dn_held)
+ f2fs_put_dnode(&dn);
+ /*
+ * If this block was not submitted, roll back its
+ * write pages pending.
+ */
+ if (!submitted_blk && ffs)
+ atomic_dec(&ffs->write_pages_pending);
+ if (!err) {
+ *pos = ((loff_t)data_idx + 1) << PAGE_SHIFT;
+ spin_lock(&F2FS_I(inode)->i_size_lock);
+ if (F2FS_I(inode)->last_disk_size < *pos)
+ F2FS_I(inode)->last_disk_size = *pos;
+ spin_unlock(&F2FS_I(inode)->i_size_lock);
+ } else {
+ file_set_keep_isize(inode);
+ }
+ }
+
+ return err;
+}
+
int f2fs_write_single_data_page(struct folio *folio, int *submitted,
struct bio **bio,
sector_t *last_block,
@@ -3958,6 +4202,223 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
return ret;
}
+static int f2fs_write_cache_folios(struct address_space *mapping,
+ struct writeback_control *wbc,
+ enum iostat_type io_type)
+{
+ struct folio *folio = NULL;
+ struct inode *inode = mapping->host;
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ struct f2fs_lock_context lc;
+ u64 pos = 0;
+ u64 end_pos = 0;
+ u32 r_len = 0;
+ int err = 0;
+ int submitted = 0;
+ int nwritten = 0;
+ bool op_locked = false;
+ bool retry = false;
+
+ if (get_dirty_pages(inode) <= SM_I(sbi)->min_hot_blocks)
+ set_inode_flag(inode, FI_HOT_DATA);
+ else
+ clear_inode_flag(inode, FI_HOT_DATA);
+
+ while ((folio = writeback_iter(mapping, wbc, folio, &err))) {
+ struct f2fs_folio_state *ffs = NULL;
+ u64 isize;
+ size_t poff;
+ pgoff_t end_index;
+ bool verity_in_progress;
+ int folio_submitted = 0;
+ bool bias_added = false;
+
+ submitted = 0;
+ retry = false;
+
+ if (err) {
+ folio_redirty_for_writepage(wbc, folio);
+ goto retry_out;
+ }
+
+ if (atomic_read(&sbi->wb_sync_req[DATA]) &&
+ wbc->sync_mode == WB_SYNC_NONE) {
+ folio_redirty_for_writepage(wbc, folio);
+ /*
+ * A WB_SYNC_ALL writeback is in progress, so defer
+ * this writeback. Mark the error as -EBUSY to let
+ * writeback_iter() stop iterating.
+ */
+ err = -EBUSY;
+ goto retry_out;
+ }
+
+ /*
+ * If cp_error is set, all subpages of this folio are not written
+ * back unless the filesystem is mounted with errors=remount-ro.
+ */
+ if (unlikely(f2fs_cp_error(sbi))) {
+ mapping_set_error(folio->mapping, -EIO);
+ if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY)
+ folio_redirty_for_writepage(wbc, folio);
+ else
+ f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
+ folio_size(folio));
+ goto retry_out;
+ }
+
+ /*
+ * Writing back one large folio performs multiple block allocations, so
+ * best-effort balance the filesystem before writing it back.
+ */
+ if (!F2FS_I(inode)->wb_task && has_not_enough_free_secs(sbi, 0, 0)) {
+ folio_redirty_for_writepage(wbc, folio);
+ retry = true;
+ folio_unlock(folio);
+ f2fs_balance_fs(sbi, true);
+ folio_lock(folio);
+ goto retry;
+ }
+retry:
+ pos = folio_pos(folio);
+ end_pos = pos + folio_size(folio);
+ isize = i_size_read(inode);
+ verity_in_progress = f2fs_verity_in_progress(inode);
+ poff = 0;
+ end_index = 0;
+
+ if (retry) {
+
+ if (unlikely(folio->mapping != mapping))
+ goto retry_out;
+
+ if (!folio_test_dirty(folio))
+ goto retry_out;
+
+ if (folio_test_writeback(folio)) {
+ if (wbc->sync_mode == WB_SYNC_NONE)
+ goto retry_out;
+ f2fs_folio_wait_writeback(folio, true, true);
+ }
+
+ if (!folio_clear_dirty_for_io(folio))
+ goto retry_out;
+ }
+
+ /* To avoid dealing with the complexity for one subrange is in bio
+ * while we trylock_op failed before writing another subrange.
+ * Try to lock_op before any subrange write for the folio.
+ */
+ if (!op_locked) {
+ if (!f2fs_trylock_op(sbi, &lc)) {
+ folio_redirty_for_writepage(wbc, folio);
+ err = 0;
+ if (wbc->sync_mode != WB_SYNC_ALL)
+ goto retry_out;
+
+ retry = true;
+ folio_unlock(folio);
+ f2fs_io_schedule_timeout(DEFAULT_SCHEDULE_TIMEOUT);
+ folio_lock(folio);
+ goto retry;
+ }
+ op_locked = true;
+ }
+
+ if (!verity_in_progress) {
+ poff = offset_in_folio(folio, isize);
+ end_index = isize >> PAGE_SHIFT;
+
+ if (folio->index > end_index ||
+ (folio->index == end_index && poff == 0))
+ goto out;
+
+ if (end_pos > isize) {
+ folio_zero_segment(folio, poff, folio_size(folio));
+ end_pos = isize;
+ }
+ }
+
+ folio_start_writeback(folio);
+
+ /*
+ * Large folios can be submitted as multiple bios, which may
+ * complete while we are still submitting the remaining dirty
+ * ranges. Hold a bias on write_pages_pending to prevent
+ * folio_end_writeback() from being called early.
+ */
+ if (!bias_added && f2fs_folio_has_ffs(folio)) {
+ ffs = (struct f2fs_folio_state *)folio->private;
+ WARN_ON_ONCE(atomic_read(&ffs->write_pages_pending) != 0);
+ atomic_inc(&ffs->write_pages_pending);
+ bias_added = true;
+ }
+
+ while ((r_len = ffs_find_dirty_range(folio, &pos, end_pos))) {
+ err = f2fs_write_folio_dirty_range(folio, &submitted,
+ wbc, io_type, &pos, r_len);
+ folio_submitted += submitted;
+ nwritten += submitted;
+ if (err)
+ goto out;
+ }
+
+ /* If none of the subpages of a folio is submitted, keep the atomic flag */
+ if (folio_submitted &&
+ f2fs_is_atomic_file(inode) &&
+ folio_test_f2fs_atomic(folio))
+ folio_clear_f2fs_atomic(folio);
+
+out:
+ /*
+ * Clear the dirty state of the subranges that were written back.
+ * If some subranges are still dirty (e.g. the folio was only
+ * partially written back), the folio must stay dirty so that
+ * the remaining subranges are written back later.
+ */
+ if (f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
+ (err ? pos : end_pos) - folio_pos(folio)))
+ folio_redirty_for_writepage(wbc, folio);
+ else
+ inode_dec_dirty_pages(inode);
+
+ /*
+ * Release the bias taken above and we end writeback here if
+ * no write bio is in flight.
+ */
+ if (bias_added &&
+ atomic_dec_and_test(&ffs->write_pages_pending)) {
+ folio_end_writeback(folio);
+ } else if (!folio_submitted && folio_test_writeback(folio)) {
+ /*
+ * Order-0 folios take no bias, so end the writeback
+ * if nothing was submitted.
+ */
+ folio_end_writeback(folio);
+ }
+
+retry_out:
+ if (op_locked) {
+ f2fs_unlock_op(sbi, &lc);
+ op_locked = false;
+ }
+
+ folio_unlock(folio);
+ }
+
+ if (nwritten)
+ f2fs_submit_merged_write_cond(F2FS_M_SB(mapping), mapping->host,
+ NULL);
+
+ /*
+ * Prevent the -EBUSY error that stopped writeback_iter() from
+ * propagating to the user.
+ */
+ if (err == -EBUSY)
+ err = 0;
+ return err;
+}
+
static inline bool __should_serialize_io(struct inode *inode,
struct writeback_control *wbc)
{
@@ -4052,7 +4513,11 @@ static int __f2fs_write_data_pages(struct address_space *mapping,
account_writeback(inode, true);
blk_start_plug(&plug);
- ret = f2fs_write_cache_pages(mapping, wbc, io_type);
+ if (mapping_large_folio_support(inode->i_mapping) &&
+ !f2fs_has_inline_data(inode))
+ ret = f2fs_write_cache_folios(mapping, wbc, io_type);
+ else
+ ret = f2fs_write_cache_pages(mapping, wbc, io_type);
blk_finish_plug(&plug);
account_writeback(inode, false);
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 05/16] f2fs: support large folio writeback
2026-10-14 6:44 ` Nanzhe Zhao
(?)
@ 2026-10-14 16:19 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 16:19 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu; +Cc: Daeho Jeong
Sashiko says:
> Does this mask checkpoint faults? If a checkpoint error occurs (or via fault
> injection), the outplace write path fails to submit but is treated as success, so dirty
> data is silently dropped. The VFS writeback loop omits the f2fs_cp_error() abort gate.
Changes:
@@ -4226,6 +4252,33 @@ static int f2fs_write_cache_folios(struct address_space *mapping,
err = -EBUSY;
goto retry_out;
}
+
+ /*
+ * If cp_error is set, all subpages of this folio are not written
+ * back unless the filesystem is mounted with errors=remount-ro.
+ */
+ if (unlikely(f2fs_cp_error(sbi))) {
+ mapping_set_error(folio->mapping, -EIO);
+ if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY)
+ folio_redirty_for_writepage(wbc, folio);
+ else
+ f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
+ folio_size(folio));
+ goto retry_out;
+ }
+
+ /*
+ * Writing back one large folio performs multiple block allocations, so
+ * best-effort balance the filesystem before writing it back.
+ */
+ if (!F2FS_I(inode)->wb_task && has_not_enough_free_secs(sbi, 0, 0)) {
+ folio_redirty_for_writepage(wbc, folio);
+ retry = true;
+ folio_unlock(folio);
+ f2fs_balance_fs(sbi, true);
+ folio_lock(folio);
+ goto retry;
+ }
retry:
pos = folio_pos(folio);
end_pos = pos + folio_size(folio);
v4's large-folio writeback path lacked the `cp_error` gate present in `f2fs_write_single_data_page()`.
v5 adds this gate to report `-EIO`, keeping dirty subranges under `errors=remount-ro` or
dropping all of the folio's subpage dirty state otherwise ,keeping consistent to f2fs_write_single_data_page
v4 omitted `f2fs_balance_fs()` during multi-block large-folio writebacks.
v5 adds a best-effort `f2fs_balance_fs()` before each folio, dropping the lock only when free sections are short
just like `f2fs_balance_fs_folio_locked()` does.
Sashiko says:
> Does this error handling catch all failure cases? When f2fs_do_write_data_page()
> delegates to f2fs_outplace_write_data(), that function has a void return type and handles
> allocation failures internally without propagating an error code.
Changes:
@@ -3697,8 +3721,10 @@ static int f2fs_write_folio_dirty_range(struct folio *folio, int *submitted,
/*
* The outplace write path failed to submit this block.
*/
- if (!fio.submitted)
+ if (!fio.submitted) {
+ err = -EIO;
goto block_done;
+ }
if (submitted)
(*submitted)++;
submitted_blk = true;
v4 treated failed `f2fs_outplace_write_data()` submissions (`fio.submitted == 0`) as success
and cleared dirty state.
v5 converts this to `-EIO` during writeback to re-dirty the folio.
Sashiko: https://sashiko.dev/#/patchset/20261013115621.968742-1-nzzhao.sigma%40gmail.com
Thanks,
Nanzhe Zhao
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 06/16] f2fs: account large folio dirty data at block granularity
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
Originally inode->dirty_pages was accounted once per folio, but f2fs
needs the counter to be accounted in blocks.
This introduces batch dirty page add/sub accounting; for a large folio
the changed dirty page count is computed from the dirty bitmap bit
changes.
Found by f2fs/006 (lfs + checkpoint=disable) and generic/363.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/checkpoint.c | 38 ++++++++++++++++++++++----
fs/f2fs/compress.c | 4 +--
fs/f2fs/data.c | 44 +++++++++++++++++++++++-------
fs/f2fs/dir.c | 2 +-
fs/f2fs/f2fs.h | 65 ++++++++++++++++++++++++++++++++++----------
fs/f2fs/gc.c | 2 +-
fs/f2fs/inline.c | 2 +-
fs/f2fs/node.c | 2 +-
8 files changed, 123 insertions(+), 36 deletions(-)
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 3ad709f69893..1ed38c668fc5 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1324,20 +1324,46 @@ static void __remove_dirty_inode(struct inode *inode, enum inode_type type)
stat_dec_dirty_inode(F2FS_I_SB(inode), type);
}
-void f2fs_update_dirty_folio(struct inode *inode, struct folio *folio)
+/*
+ * Account @nr dirty pages (negative when dirtiness is cleared) for @inode.
+ */
+void f2fs_account_dirty_blocks(struct inode *inode, int nr)
{
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE;
- if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
- !S_ISLNK(inode->i_mode))
+ if (!nr)
return;
spin_lock(&sbi->inode_lock[type]);
- if (type != FILE_INODE || test_opt(sbi, DATA_FLUSH))
- __add_dirty_inode(inode, type);
- inode_inc_dirty_pages(inode);
+ if (nr > 0) {
+ if (type != FILE_INODE || test_opt(sbi, DATA_FLUSH))
+ __add_dirty_inode(inode, type);
+ inode_add_dirty_blocks(inode, nr);
+ } else {
+ inode_sub_dirty_blocks(inode, -nr);
+ __remove_dirty_inode(inode, type);
+ }
spin_unlock(&sbi->inode_lock[type]);
+}
+
+void f2fs_update_dirty_folio(struct inode *inode, struct folio *folio)
+{
+ if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
+ !S_ISLNK(inode->i_mode))
+ return;
+
+ /*
+ * Large folios have a subpage dirty bitmap, so defer their dirty accounting
+ * to the f2fs_ffs_*subrange_dirty*() helpers. This avoids nesting
+ * ffs->state_lock with the inode dirty list lock.
+ */
+ if (f2fs_folio_has_ffs(folio)) {
+ folio_set_f2fs_reference(folio);
+ return;
+ }
+
+ f2fs_account_dirty_blocks(inode, 1);
folio_set_f2fs_reference(folio);
}
diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index c0e39f580993..162bd8ef822a 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -1065,7 +1065,7 @@ static void cancel_cluster_writeback(struct compress_ctx *cc,
/* Cancel writeback and stay locked. */
for (i = 0; i < cc->cluster_size; i++) {
if (i < submitted) {
- inode_inc_dirty_pages(cc->inode);
+ inode_inc_dirty_block(cc->inode);
lock_page(cc->rpages[i]);
}
clear_page_private_gcing(cc->rpages[i]);
@@ -1409,7 +1409,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
}
(*submitted)++;
unlock_continue:
- inode_dec_dirty_pages(cc->inode);
+ inode_dec_dirty_block(cc->inode);
folio_unlock(fio.folio);
}
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 9701d2d2da89..b5c048134e00 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2921,10 +2921,18 @@ static unsigned int __ffs_mark_subrange_dirty(struct folio *folio,
return bitmap_weight(ffs->state, 2 * nr_subpages) - before;
}
+/*
+ * Mark the given range dirty for writeback.
+ *
+ * Callers must guarantee that the corresponding subpages are already
+ * uptodate: a dirty subpage always holds the latest data, whose
+ * on-disk copy may be stale.
+ */
void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
size_t offset, size_t len)
{
struct f2fs_folio_state *ffs;
+ unsigned int set;
unsigned long flags;
f2fs_bug_on(F2FS_F_SB(folio), offset + len > folio_size(folio));
@@ -2935,21 +2943,27 @@ void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
ffs = (struct f2fs_folio_state *)folio->private;
spin_lock_irqsave(&ffs->state_lock, flags);
- __ffs_mark_subrange_dirty(folio, ffs, offset, len);
+ set = __ffs_mark_subrange_dirty(folio, ffs, offset, len);
spin_unlock_irqrestore(&ffs->state_lock, flags);
+
+ if (set)
+ f2fs_account_dirty_blocks(folio->mapping->host, set);
}
static bool __ffs_clear_subrange_dirty(struct folio *folio,
- struct f2fs_folio_state *ffs, size_t offset, size_t len)
+ struct f2fs_folio_state *ffs, size_t offset, size_t len,
+ unsigned int *cleared)
{
unsigned int nr_subpages = folio_nr_pages(folio);
- unsigned int start, end;
+ unsigned int start, end, before;
start = offset >> PAGE_SHIFT;
end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
end = min(end, nr_subpages);
+ before = bitmap_weight(ffs->state, 2 * nr_subpages);
bitmap_clear(ffs->state, nr_subpages + start, end - start);
+ *cleared = before - bitmap_weight(ffs->state, 2 * nr_subpages);
return find_next_bit(ffs->state, 2 * nr_subpages, nr_subpages) <
2 * nr_subpages;
}
@@ -2961,13 +2975,15 @@ static bool __ffs_clear_subrange_dirty(struct folio *folio,
* @len: byte length of the subrange
*
* Clear the dirty bits of the 4K subpages covered by [offset, offset + len),
- * and return whether the folio still has any dirty subpage left.
+ * account the cleared subpages against the inode dirty counters, and return
+ * whether the folio still has any dirty subpage left.
*/
bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
size_t len)
{
struct f2fs_folio_state *ffs;
unsigned long flags;
+ unsigned int cleared = 0;
bool dirty;
if (!f2fs_folio_has_ffs(folio))
@@ -2975,9 +2991,12 @@ bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
ffs = (struct f2fs_folio_state *)folio->private;
spin_lock_irqsave(&ffs->state_lock, flags);
- dirty = __ffs_clear_subrange_dirty(folio, ffs, offset, len);
+ dirty = __ffs_clear_subrange_dirty(folio, ffs, offset, len, &cleared);
spin_unlock_irqrestore(&ffs->state_lock, flags);
+ if (cleared)
+ f2fs_account_dirty_blocks(folio->mapping->host, -cleared);
+
return dirty;
}
@@ -3880,7 +3899,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
goto redirty_out;
out:
- inode_dec_dirty_pages(inode);
+ inode_dec_dirty_block(inode);
if (err) {
folio_clear_uptodate(folio);
folio_clear_f2fs_gcing(folio);
@@ -4376,11 +4395,16 @@ static int f2fs_write_cache_folios(struct address_space *mapping,
* partially written back), the folio must stay dirty so that
* the remaining subranges are written back later.
*/
+ /*
+ * Redirty the folio if dirty subranges remain in a large
+ * folio, or if order-0 writeback fails due to an error.
+ */
if (f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
- (err ? pos : end_pos) - folio_pos(folio)))
+ (err ? pos : end_pos) - folio_pos(folio)) ||
+ err)
folio_redirty_for_writepage(wbc, folio);
- else
- inode_dec_dirty_pages(inode);
+ else if (!f2fs_folio_has_ffs(folio))
+ inode_dec_dirty_block(inode);
/*
* Release the bias taken above and we end writeback here if
@@ -5219,7 +5243,7 @@ void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length)
return;
if (folio_test_dirty(folio)) {
- inode_dec_dirty_pages(inode);
+ inode_dec_dirty_block(inode);
f2fs_remove_dirty_inode(inode);
}
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 97f7fef6b068..70847313ca6a 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -937,7 +937,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, void *dentry_block,
folio_clear_uptodate(folio);
folio_detach_private(folio);
- inode_dec_dirty_pages(dir);
+ inode_dec_dirty_block(dir);
f2fs_remove_dirty_inode(dir);
}
f2fs_folio_put(folio, true);
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 6db23a3c25a9..9edff1e79f2c 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2919,9 +2919,10 @@ static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
f2fs_i_blocks_write(inode, count, false, true);
}
-static inline void inc_cache_count(struct f2fs_sb_info *sbi, int count_type)
+static inline void add_cache_counts(struct f2fs_sb_info *sbi,
+ int count_type, int nr)
{
- atomic_inc(&sbi->nr_caches[count_type]);
+ atomic_add(nr, &sbi->nr_caches[count_type]);
if (count_type == F2FS_DIRTY_DENTS ||
count_type == F2FS_DIRTY_NODES ||
@@ -2931,31 +2932,66 @@ static inline void inc_cache_count(struct f2fs_sb_info *sbi, int count_type)
set_sbi_flag(sbi, SBI_IS_DIRTY);
}
-static inline void inode_inc_dirty_pages(struct inode *inode)
+static inline void sub_cache_counts(struct f2fs_sb_info *sbi,
+ int count_type, int nr)
{
- atomic_inc(&F2FS_I(inode)->dirty_pages);
- inc_cache_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
- F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
- if (IS_NOQUOTA(inode))
- inc_cache_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
+ atomic_sub(nr, &sbi->nr_caches[count_type]);
+}
+
+static inline void inc_cache_count(struct f2fs_sb_info *sbi, int count_type)
+{
+ add_cache_counts(sbi, count_type, 1);
}
static inline void dec_cache_count(struct f2fs_sb_info *sbi, int count_type)
{
- atomic_dec(&sbi->nr_caches[count_type]);
+ sub_cache_counts(sbi, count_type, 1);
+}
+
+/*
+ * Account @nr dirty pages for @inode; one page is
+ * (PAGE_SIZE >> log_blocksize) filesystem blocks.
+ */
+static inline void inode_add_dirty_blocks(struct inode *inode, int nr)
+{
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ int blocks = nr * (PAGE_SIZE >> sbi->log_blocksize);
+
+ atomic_add(blocks, &F2FS_I(inode)->dirty_pages);
+ if (S_ISDIR(inode->i_mode))
+ add_cache_counts(sbi, F2FS_DIRTY_DENTS, blocks);
+ else
+ add_cache_counts(sbi, F2FS_DIRTY_DATA, blocks);
+ if (IS_NOQUOTA(inode))
+ add_cache_counts(sbi, F2FS_DIRTY_QDATA, blocks);
}
-static inline void inode_dec_dirty_pages(struct inode *inode)
+static inline void inode_sub_dirty_blocks(struct inode *inode, int nr)
{
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ int blocks = nr * (PAGE_SIZE >> sbi->log_blocksize);
+
if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
!S_ISLNK(inode->i_mode))
return;
- atomic_dec(&F2FS_I(inode)->dirty_pages);
- dec_cache_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
- F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
+ atomic_sub(blocks, &F2FS_I(inode)->dirty_pages);
+ if (S_ISDIR(inode->i_mode))
+ sub_cache_counts(sbi, F2FS_DIRTY_DENTS, blocks);
+ else
+ sub_cache_counts(sbi, F2FS_DIRTY_DATA, blocks);
if (IS_NOQUOTA(inode))
- dec_cache_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
+ sub_cache_counts(sbi, F2FS_DIRTY_QDATA, blocks);
+}
+
+static inline void inode_inc_dirty_block(struct inode *inode)
+{
+ inode_add_dirty_blocks(inode, 1);
+}
+
+static inline void inode_dec_dirty_block(struct inode *inode)
+{
+ inode_sub_dirty_blocks(inode, 1);
}
static inline void inc_atomic_write_cnt(struct inode *inode)
@@ -4384,6 +4420,7 @@ void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino);
int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi);
int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi);
void f2fs_update_dirty_folio(struct inode *inode, struct folio *folio);
+void f2fs_account_dirty_blocks(struct inode *inode, int nr);
void f2fs_remove_dirty_inode(struct inode *inode);
int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type,
bool from_cp);
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 89e50f871b75..d7fae1890835 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1555,7 +1555,7 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
folio_mark_dirty(folio);
if (folio_clear_dirty_for_io(folio)) {
- inode_dec_dirty_pages(inode);
+ inode_dec_dirty_block(inode);
f2fs_remove_dirty_inode(inode);
}
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index ab7537ff7ebd..49905aa08418 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -199,7 +199,7 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
f2fs_outplace_write_data(dn, &fio);
f2fs_folio_wait_writeback(folio, true, true);
if (dirty) {
- inode_dec_dirty_pages(dn->inode);
+ inode_dec_dirty_block(dn->inode);
f2fs_remove_dirty_inode(dn->inode);
}
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index e7522e7eedf8..d96ccf1c90ff 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1699,7 +1699,7 @@ static void flush_inline_data(struct f2fs_sb_info *sbi, nid_t ino)
goto folio_out;
ret = f2fs_write_inline_data(inode, folio);
- inode_dec_dirty_pages(inode);
+ inode_dec_dirty_block(inode);
f2fs_remove_dirty_inode(inode);
if (ret)
folio_mark_dirty(folio);
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 06/16] f2fs: account large folio dirty data at block granularity
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
Originally inode->dirty_pages was accounted once per folio, but f2fs
needs the counter to be accounted in blocks.
This introduces batch dirty page add/sub accounting; for a large folio
the changed dirty page count is computed from the dirty bitmap bit
changes.
Found by f2fs/006 (lfs + checkpoint=disable) and generic/363.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/checkpoint.c | 38 ++++++++++++++++++++++----
fs/f2fs/compress.c | 4 +--
fs/f2fs/data.c | 44 +++++++++++++++++++++++-------
fs/f2fs/dir.c | 2 +-
fs/f2fs/f2fs.h | 65 ++++++++++++++++++++++++++++++++++----------
fs/f2fs/gc.c | 2 +-
fs/f2fs/inline.c | 2 +-
fs/f2fs/node.c | 2 +-
8 files changed, 123 insertions(+), 36 deletions(-)
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 3ad709f69893..1ed38c668fc5 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1324,20 +1324,46 @@ static void __remove_dirty_inode(struct inode *inode, enum inode_type type)
stat_dec_dirty_inode(F2FS_I_SB(inode), type);
}
-void f2fs_update_dirty_folio(struct inode *inode, struct folio *folio)
+/*
+ * Account @nr dirty pages (negative when dirtiness is cleared) for @inode.
+ */
+void f2fs_account_dirty_blocks(struct inode *inode, int nr)
{
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE;
- if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
- !S_ISLNK(inode->i_mode))
+ if (!nr)
return;
spin_lock(&sbi->inode_lock[type]);
- if (type != FILE_INODE || test_opt(sbi, DATA_FLUSH))
- __add_dirty_inode(inode, type);
- inode_inc_dirty_pages(inode);
+ if (nr > 0) {
+ if (type != FILE_INODE || test_opt(sbi, DATA_FLUSH))
+ __add_dirty_inode(inode, type);
+ inode_add_dirty_blocks(inode, nr);
+ } else {
+ inode_sub_dirty_blocks(inode, -nr);
+ __remove_dirty_inode(inode, type);
+ }
spin_unlock(&sbi->inode_lock[type]);
+}
+
+void f2fs_update_dirty_folio(struct inode *inode, struct folio *folio)
+{
+ if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
+ !S_ISLNK(inode->i_mode))
+ return;
+
+ /*
+ * Large folios have a subpage dirty bitmap, so defer their dirty accounting
+ * to the f2fs_ffs_*subrange_dirty*() helpers. This avoids nesting
+ * ffs->state_lock with the inode dirty list lock.
+ */
+ if (f2fs_folio_has_ffs(folio)) {
+ folio_set_f2fs_reference(folio);
+ return;
+ }
+
+ f2fs_account_dirty_blocks(inode, 1);
folio_set_f2fs_reference(folio);
}
diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index c0e39f580993..162bd8ef822a 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -1065,7 +1065,7 @@ static void cancel_cluster_writeback(struct compress_ctx *cc,
/* Cancel writeback and stay locked. */
for (i = 0; i < cc->cluster_size; i++) {
if (i < submitted) {
- inode_inc_dirty_pages(cc->inode);
+ inode_inc_dirty_block(cc->inode);
lock_page(cc->rpages[i]);
}
clear_page_private_gcing(cc->rpages[i]);
@@ -1409,7 +1409,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
}
(*submitted)++;
unlock_continue:
- inode_dec_dirty_pages(cc->inode);
+ inode_dec_dirty_block(cc->inode);
folio_unlock(fio.folio);
}
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 9701d2d2da89..b5c048134e00 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2921,10 +2921,18 @@ static unsigned int __ffs_mark_subrange_dirty(struct folio *folio,
return bitmap_weight(ffs->state, 2 * nr_subpages) - before;
}
+/*
+ * Mark the given range dirty for writeback.
+ *
+ * Callers must guarantee that the corresponding subpages are already
+ * uptodate: a dirty subpage always holds the latest data, whose
+ * on-disk copy may be stale.
+ */
void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
size_t offset, size_t len)
{
struct f2fs_folio_state *ffs;
+ unsigned int set;
unsigned long flags;
f2fs_bug_on(F2FS_F_SB(folio), offset + len > folio_size(folio));
@@ -2935,21 +2943,27 @@ void f2fs_ffs_mark_subrange_dirty(struct folio *folio,
ffs = (struct f2fs_folio_state *)folio->private;
spin_lock_irqsave(&ffs->state_lock, flags);
- __ffs_mark_subrange_dirty(folio, ffs, offset, len);
+ set = __ffs_mark_subrange_dirty(folio, ffs, offset, len);
spin_unlock_irqrestore(&ffs->state_lock, flags);
+
+ if (set)
+ f2fs_account_dirty_blocks(folio->mapping->host, set);
}
static bool __ffs_clear_subrange_dirty(struct folio *folio,
- struct f2fs_folio_state *ffs, size_t offset, size_t len)
+ struct f2fs_folio_state *ffs, size_t offset, size_t len,
+ unsigned int *cleared)
{
unsigned int nr_subpages = folio_nr_pages(folio);
- unsigned int start, end;
+ unsigned int start, end, before;
start = offset >> PAGE_SHIFT;
end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
end = min(end, nr_subpages);
+ before = bitmap_weight(ffs->state, 2 * nr_subpages);
bitmap_clear(ffs->state, nr_subpages + start, end - start);
+ *cleared = before - bitmap_weight(ffs->state, 2 * nr_subpages);
return find_next_bit(ffs->state, 2 * nr_subpages, nr_subpages) <
2 * nr_subpages;
}
@@ -2961,13 +2975,15 @@ static bool __ffs_clear_subrange_dirty(struct folio *folio,
* @len: byte length of the subrange
*
* Clear the dirty bits of the 4K subpages covered by [offset, offset + len),
- * and return whether the folio still has any dirty subpage left.
+ * account the cleared subpages against the inode dirty counters, and return
+ * whether the folio still has any dirty subpage left.
*/
bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
size_t len)
{
struct f2fs_folio_state *ffs;
unsigned long flags;
+ unsigned int cleared = 0;
bool dirty;
if (!f2fs_folio_has_ffs(folio))
@@ -2975,9 +2991,12 @@ bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
ffs = (struct f2fs_folio_state *)folio->private;
spin_lock_irqsave(&ffs->state_lock, flags);
- dirty = __ffs_clear_subrange_dirty(folio, ffs, offset, len);
+ dirty = __ffs_clear_subrange_dirty(folio, ffs, offset, len, &cleared);
spin_unlock_irqrestore(&ffs->state_lock, flags);
+ if (cleared)
+ f2fs_account_dirty_blocks(folio->mapping->host, -cleared);
+
return dirty;
}
@@ -3880,7 +3899,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
goto redirty_out;
out:
- inode_dec_dirty_pages(inode);
+ inode_dec_dirty_block(inode);
if (err) {
folio_clear_uptodate(folio);
folio_clear_f2fs_gcing(folio);
@@ -4376,11 +4395,16 @@ static int f2fs_write_cache_folios(struct address_space *mapping,
* partially written back), the folio must stay dirty so that
* the remaining subranges are written back later.
*/
+ /*
+ * Redirty the folio if dirty subranges remain in a large
+ * folio, or if order-0 writeback fails due to an error.
+ */
if (f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
- (err ? pos : end_pos) - folio_pos(folio)))
+ (err ? pos : end_pos) - folio_pos(folio)) ||
+ err)
folio_redirty_for_writepage(wbc, folio);
- else
- inode_dec_dirty_pages(inode);
+ else if (!f2fs_folio_has_ffs(folio))
+ inode_dec_dirty_block(inode);
/*
* Release the bias taken above and we end writeback here if
@@ -5219,7 +5243,7 @@ void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length)
return;
if (folio_test_dirty(folio)) {
- inode_dec_dirty_pages(inode);
+ inode_dec_dirty_block(inode);
f2fs_remove_dirty_inode(inode);
}
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 97f7fef6b068..70847313ca6a 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -937,7 +937,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, void *dentry_block,
folio_clear_uptodate(folio);
folio_detach_private(folio);
- inode_dec_dirty_pages(dir);
+ inode_dec_dirty_block(dir);
f2fs_remove_dirty_inode(dir);
}
f2fs_folio_put(folio, true);
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 6db23a3c25a9..9edff1e79f2c 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2919,9 +2919,10 @@ static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
f2fs_i_blocks_write(inode, count, false, true);
}
-static inline void inc_cache_count(struct f2fs_sb_info *sbi, int count_type)
+static inline void add_cache_counts(struct f2fs_sb_info *sbi,
+ int count_type, int nr)
{
- atomic_inc(&sbi->nr_caches[count_type]);
+ atomic_add(nr, &sbi->nr_caches[count_type]);
if (count_type == F2FS_DIRTY_DENTS ||
count_type == F2FS_DIRTY_NODES ||
@@ -2931,31 +2932,66 @@ static inline void inc_cache_count(struct f2fs_sb_info *sbi, int count_type)
set_sbi_flag(sbi, SBI_IS_DIRTY);
}
-static inline void inode_inc_dirty_pages(struct inode *inode)
+static inline void sub_cache_counts(struct f2fs_sb_info *sbi,
+ int count_type, int nr)
{
- atomic_inc(&F2FS_I(inode)->dirty_pages);
- inc_cache_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
- F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
- if (IS_NOQUOTA(inode))
- inc_cache_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
+ atomic_sub(nr, &sbi->nr_caches[count_type]);
+}
+
+static inline void inc_cache_count(struct f2fs_sb_info *sbi, int count_type)
+{
+ add_cache_counts(sbi, count_type, 1);
}
static inline void dec_cache_count(struct f2fs_sb_info *sbi, int count_type)
{
- atomic_dec(&sbi->nr_caches[count_type]);
+ sub_cache_counts(sbi, count_type, 1);
+}
+
+/*
+ * Account @nr dirty pages for @inode; one page is
+ * (PAGE_SIZE >> log_blocksize) filesystem blocks.
+ */
+static inline void inode_add_dirty_blocks(struct inode *inode, int nr)
+{
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ int blocks = nr * (PAGE_SIZE >> sbi->log_blocksize);
+
+ atomic_add(blocks, &F2FS_I(inode)->dirty_pages);
+ if (S_ISDIR(inode->i_mode))
+ add_cache_counts(sbi, F2FS_DIRTY_DENTS, blocks);
+ else
+ add_cache_counts(sbi, F2FS_DIRTY_DATA, blocks);
+ if (IS_NOQUOTA(inode))
+ add_cache_counts(sbi, F2FS_DIRTY_QDATA, blocks);
}
-static inline void inode_dec_dirty_pages(struct inode *inode)
+static inline void inode_sub_dirty_blocks(struct inode *inode, int nr)
{
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ int blocks = nr * (PAGE_SIZE >> sbi->log_blocksize);
+
if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
!S_ISLNK(inode->i_mode))
return;
- atomic_dec(&F2FS_I(inode)->dirty_pages);
- dec_cache_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
- F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
+ atomic_sub(blocks, &F2FS_I(inode)->dirty_pages);
+ if (S_ISDIR(inode->i_mode))
+ sub_cache_counts(sbi, F2FS_DIRTY_DENTS, blocks);
+ else
+ sub_cache_counts(sbi, F2FS_DIRTY_DATA, blocks);
if (IS_NOQUOTA(inode))
- dec_cache_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
+ sub_cache_counts(sbi, F2FS_DIRTY_QDATA, blocks);
+}
+
+static inline void inode_inc_dirty_block(struct inode *inode)
+{
+ inode_add_dirty_blocks(inode, 1);
+}
+
+static inline void inode_dec_dirty_block(struct inode *inode)
+{
+ inode_sub_dirty_blocks(inode, 1);
}
static inline void inc_atomic_write_cnt(struct inode *inode)
@@ -4384,6 +4420,7 @@ void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino);
int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi);
int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi);
void f2fs_update_dirty_folio(struct inode *inode, struct folio *folio);
+void f2fs_account_dirty_blocks(struct inode *inode, int nr);
void f2fs_remove_dirty_inode(struct inode *inode);
int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type,
bool from_cp);
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 89e50f871b75..d7fae1890835 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1555,7 +1555,7 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
folio_mark_dirty(folio);
if (folio_clear_dirty_for_io(folio)) {
- inode_dec_dirty_pages(inode);
+ inode_dec_dirty_block(inode);
f2fs_remove_dirty_inode(inode);
}
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index ab7537ff7ebd..49905aa08418 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -199,7 +199,7 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
f2fs_outplace_write_data(dn, &fio);
f2fs_folio_wait_writeback(folio, true, true);
if (dirty) {
- inode_dec_dirty_pages(dn->inode);
+ inode_dec_dirty_block(dn->inode);
f2fs_remove_dirty_inode(dn->inode);
}
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index e7522e7eedf8..d96ccf1c90ff 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1699,7 +1699,7 @@ static void flush_inline_data(struct f2fs_sb_info *sbi, nid_t ino)
goto folio_out;
ret = f2fs_write_inline_data(inode, folio);
- inode_dec_dirty_pages(inode);
+ inode_dec_dirty_block(inode);
f2fs_remove_dirty_inode(inode);
if (ret)
folio_mark_dirty(folio);
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 07/16] f2fs: prepare mmap write faults for large folios
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
Now write protect `mmap` also need to support large folio,
Change `f2fs_vm_page_mkwrite` to achieve that.
Note it currently marks the whole large folio dirty
to avoid data loss which causes write amplification.
Further optimization is welcome.
The folio_zero_segment() in mkwrite is extended to zero the
post-EOF part of the faulted folio for both order-0 and large
folios, so the f2fs_zero_post_eof_page() call that was added
to cover the removed shortcut is no longer needed.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/f2fs.h | 4 +++
fs/f2fs/file.c | 96 ++++++++++++++++++++++++++++++++------------------
2 files changed, 65 insertions(+), 35 deletions(-)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 9edff1e79f2c..d976e6ad058b 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4492,6 +4492,10 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
enum iostat_type io_type,
int compr_blocks, bool allow_balance);
bool f2fs_ffs_test_blk_uptodate(const struct folio *folio, pgoff_t index);
+struct f2fs_folio_state *f2fs_ffs_find_or_alloc(struct folio *folio);
+void f2fs_ffs_mark_subrange_dirty(struct folio *folio, size_t offset, size_t len);
+bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
+ size_t len);
void f2fs_write_failed(struct inode *inode, loff_t to);
void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length);
bool f2fs_release_folio(struct folio *folio, gfp_t wait);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index e53cdb4467b4..30f1484d2f48 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -118,14 +118,48 @@ static vm_fault_t f2fs_filemap_fault(struct vm_fault *vmf)
return ret;
}
+static int f2fs_get_block_mkwrite(struct inode *inode, struct folio *folio,
+ pgoff_t index, bool need_alloc)
+{
+ struct dnode_of_data dn;
+ int err;
+
+ set_new_dnode(&dn, inode, NULL, NULL, 0);
+ if (need_alloc) {
+ err = f2fs_get_block_locked(&dn, index);
+ } else {
+ err = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE);
+ f2fs_put_dnode(&dn);
+ if (f2fs_is_pinned_file(inode) &&
+ !__is_valid_data_blkaddr(dn.data_blkaddr))
+ err = -EIO;
+ }
+
+ if (err)
+ return err;
+
+ f2fs_folio_wait_writeback(folio, false, true);
+
+ /* wait for GCed page writeback via META_MAPPING */
+ f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
+
+ return 0;
+}
+
static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
{
struct folio *folio = page_folio(vmf->page);
struct inode *inode = file_inode(vmf->vma->vm_file);
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
- struct dnode_of_data dn;
bool need_alloc = !f2fs_is_pinned_file(inode);
+ pgoff_t pidx = folio->index + folio_page_idx(folio, vmf->page);
+ loff_t pos = (loff_t)pidx << PAGE_SHIFT;
loff_t isize;
+ loff_t folio_start;
+ loff_t valid_end;
+ size_t dirty_len;
+ size_t subpage_off;
+ pgoff_t i, nr;
int err = 0;
vm_fault_t ret;
@@ -166,7 +200,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
#ifdef CONFIG_F2FS_FS_COMPRESSION
if (f2fs_compressed_file(inode)) {
- int ret = f2fs_is_compressed_cluster(inode, folio->index);
+ int ret = f2fs_is_compressed_cluster(inode, pidx);
if (ret < 0) {
err = ret;
@@ -184,11 +218,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
- err = f2fs_zero_post_eof_page(inode,
- (folio->index + 1) << PAGE_SHIFT, true, false);
- if (err)
- goto out_pagefault;
-
file_update_time(vmf->vma->vm_file);
filemap_invalidate_lock_shared(inode->i_mapping);
@@ -204,62 +233,59 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
}
folio_lock(folio);
- /*
- * A concurrent buffered write can extend isize, so we store isize in a
- * local variable to let the zeroing offset match the EOF check below.
- */
isize = i_size_read(inode);
+ folio_start = folio_pos(folio);
+ subpage_off = offset_in_folio(folio, pos);
+ valid_end = min_t(loff_t, folio_start + folio_size(folio), isize);
+ dirty_len = valid_end - folio_start;
if (unlikely(folio->mapping != inode->i_mapping ||
- folio_pos(folio) > isize ||
- !folio_test_uptodate(folio))) {
+ pos >= isize ||
+ !f2fs_ffs_test_blk_uptodate(folio,
+ folio->index + (subpage_off >> PAGE_SHIFT)))) {
folio_unlock(folio);
err = -EFAULT;
goto out_sem;
}
- set_new_dnode(&dn, inode, NULL, NULL, 0);
- if (need_alloc) {
- /* block allocation */
- err = f2fs_get_block_locked(&dn, folio->index);
- } else {
- err = f2fs_get_dnode_of_data(&dn, folio->index, LOOKUP_NODE);
- f2fs_put_dnode(&dn);
- if (f2fs_is_pinned_file(inode) &&
- !__is_valid_data_blkaddr(dn.data_blkaddr))
- err = -EIO;
- }
-
- if (err) {
+ if (folio_test_large(folio) && !f2fs_ffs_find_or_alloc(folio)) {
folio_unlock(folio);
+ err = -ENOMEM;
goto out_sem;
}
- f2fs_folio_wait_writeback(folio, false, true);
+ nr = DIV_ROUND_UP(dirty_len, PAGE_SIZE);
- /* wait for GCed page writeback via generic cache */
- f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
+ for (i = 0; i < nr; i++) {
+ err = f2fs_get_block_mkwrite(inode, folio, folio->index + i,
+ need_alloc);
+ if (err) {
+ folio_unlock(folio);
+ goto out_sem;
+ }
+ }
/* page is wholly or partially inside EOF */
- if (((loff_t)(folio->index + 1) << PAGE_SHIFT) > isize) {
- loff_t offset;
+ if (folio_start + folio_size(folio) > isize) {
+ size_t offset = offset_in_folio(folio, isize);
- offset = isize & ~PAGE_MASK;
folio_zero_segment(folio, offset, folio_size(folio));
}
+
+ if (folio_test_large(folio))
+ f2fs_ffs_mark_subrange_dirty(folio, 0, dirty_len);
folio_mark_dirty(folio);
- f2fs_update_iostat(sbi, inode, APP_MAPPED_IO, F2FS_BLKSIZE(sbi));
+ f2fs_update_iostat(sbi, inode, APP_MAPPED_IO, dirty_len);
f2fs_update_time(sbi, REQ_TIME);
out_sem:
filemap_invalidate_unlock_shared(inode->i_mapping);
-out_pagefault:
sb_end_pagefault(inode->i_sb);
out:
ret = vmf_fs_error(err);
- trace_f2fs_vm_page_mkwrite(inode, folio->index, vmf->vma->vm_flags, ret);
+ trace_f2fs_vm_page_mkwrite(inode, pidx, vmf->vma->vm_flags, ret);
return ret;
}
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 07/16] f2fs: prepare mmap write faults for large folios
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
Now write protect `mmap` also need to support large folio,
Change `f2fs_vm_page_mkwrite` to achieve that.
Note it currently marks the whole large folio dirty
to avoid data loss which causes write amplification.
Further optimization is welcome.
The folio_zero_segment() in mkwrite is extended to zero the
post-EOF part of the faulted folio for both order-0 and large
folios, so the f2fs_zero_post_eof_page() call that was added
to cover the removed shortcut is no longer needed.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/f2fs.h | 4 +++
fs/f2fs/file.c | 96 ++++++++++++++++++++++++++++++++------------------
2 files changed, 65 insertions(+), 35 deletions(-)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 9edff1e79f2c..d976e6ad058b 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4492,6 +4492,10 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
enum iostat_type io_type,
int compr_blocks, bool allow_balance);
bool f2fs_ffs_test_blk_uptodate(const struct folio *folio, pgoff_t index);
+struct f2fs_folio_state *f2fs_ffs_find_or_alloc(struct folio *folio);
+void f2fs_ffs_mark_subrange_dirty(struct folio *folio, size_t offset, size_t len);
+bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
+ size_t len);
void f2fs_write_failed(struct inode *inode, loff_t to);
void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length);
bool f2fs_release_folio(struct folio *folio, gfp_t wait);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index e53cdb4467b4..30f1484d2f48 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -118,14 +118,48 @@ static vm_fault_t f2fs_filemap_fault(struct vm_fault *vmf)
return ret;
}
+static int f2fs_get_block_mkwrite(struct inode *inode, struct folio *folio,
+ pgoff_t index, bool need_alloc)
+{
+ struct dnode_of_data dn;
+ int err;
+
+ set_new_dnode(&dn, inode, NULL, NULL, 0);
+ if (need_alloc) {
+ err = f2fs_get_block_locked(&dn, index);
+ } else {
+ err = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE);
+ f2fs_put_dnode(&dn);
+ if (f2fs_is_pinned_file(inode) &&
+ !__is_valid_data_blkaddr(dn.data_blkaddr))
+ err = -EIO;
+ }
+
+ if (err)
+ return err;
+
+ f2fs_folio_wait_writeback(folio, false, true);
+
+ /* wait for GCed page writeback via META_MAPPING */
+ f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
+
+ return 0;
+}
+
static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
{
struct folio *folio = page_folio(vmf->page);
struct inode *inode = file_inode(vmf->vma->vm_file);
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
- struct dnode_of_data dn;
bool need_alloc = !f2fs_is_pinned_file(inode);
+ pgoff_t pidx = folio->index + folio_page_idx(folio, vmf->page);
+ loff_t pos = (loff_t)pidx << PAGE_SHIFT;
loff_t isize;
+ loff_t folio_start;
+ loff_t valid_end;
+ size_t dirty_len;
+ size_t subpage_off;
+ pgoff_t i, nr;
int err = 0;
vm_fault_t ret;
@@ -166,7 +200,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
#ifdef CONFIG_F2FS_FS_COMPRESSION
if (f2fs_compressed_file(inode)) {
- int ret = f2fs_is_compressed_cluster(inode, folio->index);
+ int ret = f2fs_is_compressed_cluster(inode, pidx);
if (ret < 0) {
err = ret;
@@ -184,11 +218,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
f2fs_bug_on(sbi, f2fs_has_inline_data(inode));
- err = f2fs_zero_post_eof_page(inode,
- (folio->index + 1) << PAGE_SHIFT, true, false);
- if (err)
- goto out_pagefault;
-
file_update_time(vmf->vma->vm_file);
filemap_invalidate_lock_shared(inode->i_mapping);
@@ -204,62 +233,59 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
}
folio_lock(folio);
- /*
- * A concurrent buffered write can extend isize, so we store isize in a
- * local variable to let the zeroing offset match the EOF check below.
- */
isize = i_size_read(inode);
+ folio_start = folio_pos(folio);
+ subpage_off = offset_in_folio(folio, pos);
+ valid_end = min_t(loff_t, folio_start + folio_size(folio), isize);
+ dirty_len = valid_end - folio_start;
if (unlikely(folio->mapping != inode->i_mapping ||
- folio_pos(folio) > isize ||
- !folio_test_uptodate(folio))) {
+ pos >= isize ||
+ !f2fs_ffs_test_blk_uptodate(folio,
+ folio->index + (subpage_off >> PAGE_SHIFT)))) {
folio_unlock(folio);
err = -EFAULT;
goto out_sem;
}
- set_new_dnode(&dn, inode, NULL, NULL, 0);
- if (need_alloc) {
- /* block allocation */
- err = f2fs_get_block_locked(&dn, folio->index);
- } else {
- err = f2fs_get_dnode_of_data(&dn, folio->index, LOOKUP_NODE);
- f2fs_put_dnode(&dn);
- if (f2fs_is_pinned_file(inode) &&
- !__is_valid_data_blkaddr(dn.data_blkaddr))
- err = -EIO;
- }
-
- if (err) {
+ if (folio_test_large(folio) && !f2fs_ffs_find_or_alloc(folio)) {
folio_unlock(folio);
+ err = -ENOMEM;
goto out_sem;
}
- f2fs_folio_wait_writeback(folio, false, true);
+ nr = DIV_ROUND_UP(dirty_len, PAGE_SIZE);
- /* wait for GCed page writeback via generic cache */
- f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
+ for (i = 0; i < nr; i++) {
+ err = f2fs_get_block_mkwrite(inode, folio, folio->index + i,
+ need_alloc);
+ if (err) {
+ folio_unlock(folio);
+ goto out_sem;
+ }
+ }
/* page is wholly or partially inside EOF */
- if (((loff_t)(folio->index + 1) << PAGE_SHIFT) > isize) {
- loff_t offset;
+ if (folio_start + folio_size(folio) > isize) {
+ size_t offset = offset_in_folio(folio, isize);
- offset = isize & ~PAGE_MASK;
folio_zero_segment(folio, offset, folio_size(folio));
}
+
+ if (folio_test_large(folio))
+ f2fs_ffs_mark_subrange_dirty(folio, 0, dirty_len);
folio_mark_dirty(folio);
- f2fs_update_iostat(sbi, inode, APP_MAPPED_IO, F2FS_BLKSIZE(sbi));
+ f2fs_update_iostat(sbi, inode, APP_MAPPED_IO, dirty_len);
f2fs_update_time(sbi, REQ_TIME);
out_sem:
filemap_invalidate_unlock_shared(inode->i_mapping);
-out_pagefault:
sb_end_pagefault(inode->i_sb);
out:
ret = vmf_fs_error(err);
- trace_f2fs_vm_page_mkwrite(inode, folio->index, vmf->vma->vm_flags, ret);
+ trace_f2fs_vm_page_mkwrite(inode, pidx, vmf->vma->vm_flags, ret);
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 08/16] f2fs: make GC migration large-folio aware
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
GC can operate on a 4K block that is cached inside a large folio.
The data lookup helpers therefore need to test and update uptodate
state for the addressed subpage instead of rejecting large folios or
treating the whole folio as the target block.
Let f2fs_get_read_data_folio() and f2fs_get_lock_data_folio() to use
subpage uptodate state. Submit single-block reads at the requested
folio offset and zero only the addressed 4K range for NEW_ADDR.
Also update `move_data_page` to mark, clear, and restore dirty
state for the target subpage, and submit write I/O with the subpage
offset recorded in f2fs_io_info.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 46 ++++++++++++++++++++++++++++++----------------
fs/f2fs/f2fs.h | 1 +
fs/f2fs/gc.c | 36 ++++++++++++++++++++++++++++++++----
fs/f2fs/segment.c | 2 +-
4 files changed, 64 insertions(+), 21 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index b5c048134e00..710213fea7a6 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1633,20 +1633,16 @@ struct folio *f2fs_get_read_data_folio(struct inode *inode, pgoff_t index,
struct dnode_of_data dn;
struct folio *folio;
int err;
-retry:
+
folio = f2fs_grab_cache_folio(mapping, index, for_write);
if (IS_ERR(folio))
return folio;
if (folio_test_large(folio)) {
- pgoff_t folio_index = mapping_align_index(mapping, index);
- unsigned long nr_pages = folio_nr_pages(folio);
-
- f2fs_folio_put(folio, true);
- invalidate_inode_pages2_range(mapping, folio_index,
- folio_index + nr_pages - 1);
- f2fs_schedule_timeout(DEFAULT_SCHEDULE_TIMEOUT);
- goto retry;
+ if (!f2fs_ffs_find_or_alloc(folio)) {
+ err = -ENOMEM;
+ goto put_err;
+ }
}
if (f2fs_lookup_read_extent_cache_block(inode, index,
@@ -1682,7 +1678,7 @@ struct folio *f2fs_get_read_data_folio(struct inode *inode, pgoff_t index,
goto put_err;
}
got_it:
- if (folio_test_uptodate(folio)) {
+ if (f2fs_ffs_test_blk_uptodate(folio, index)) {
folio_unlock(folio);
return folio;
}
@@ -1695,9 +1691,11 @@ struct folio *f2fs_get_read_data_folio(struct inode *inode, pgoff_t index,
* f2fs_init_inode_metadata.
*/
if (dn.data_blkaddr == NEW_ADDR) {
- folio_zero_segment(folio, 0, folio_size(folio));
- if (!folio_test_uptodate(folio))
- folio_mark_uptodate(folio);
+ size_t offset = offset_in_folio(folio,
+ (loff_t)index << PAGE_SHIFT);
+
+ folio_zero_segment(folio, offset, offset + PAGE_SIZE);
+ f2fs_ffs_mark_subrange_uptodate(folio, offset, PAGE_SIZE);
folio_unlock(folio);
return folio;
}
@@ -1757,7 +1755,8 @@ struct folio *f2fs_get_lock_data_folio(struct inode *inode, pgoff_t index,
/* wait for read completion */
folio_lock(folio);
- if (unlikely(folio->mapping != mapping || !folio_test_uptodate(folio))) {
+ if (unlikely(folio->mapping != mapping ||
+ !f2fs_ffs_test_blk_uptodate(folio, index))) {
f2fs_folio_put(folio, true);
return ERR_PTR(-EIO);
}
@@ -2906,6 +2905,22 @@ static void f2fs_ffs_mark_subrange_uptodate(struct folio *folio, size_t offset,
folio_mark_uptodate(folio);
}
+bool f2fs_ffs_test_blk_dirty(const struct folio *folio, pgoff_t index)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned int idx, nr_subpages;
+
+ f2fs_bug_on(F2FS_F_SB(folio), !folio_contains(folio, index));
+
+ if (!f2fs_folio_has_ffs(folio))
+ return folio_test_dirty(folio);
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ nr_subpages = folio_nr_pages(folio);
+ idx = index - folio->index;
+ return test_bit(nr_subpages + idx, ffs->state);
+}
+
static unsigned int __ffs_mark_subrange_dirty(struct folio *folio,
struct f2fs_folio_state *ffs, size_t offset, size_t len)
{
@@ -2999,7 +3014,6 @@ bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
return dirty;
}
-
static unsigned int ffs_next_dirty_subpage(struct f2fs_folio_state *ffs,
const struct folio *folio, unsigned int start,
unsigned int end)
@@ -3497,7 +3511,7 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)
return true;
if (fio) {
- if (page_private_gcing(fio->page))
+ if (folio_test_f2fs_gcing(fio->folio))
return true;
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED) &&
f2fs_is_checkpointed_data(sbi, fio->old_blkaddr)))
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index d976e6ad058b..36ec8266af69 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4493,6 +4493,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
int compr_blocks, bool allow_balance);
bool f2fs_ffs_test_blk_uptodate(const struct folio *folio, pgoff_t index);
struct f2fs_folio_state *f2fs_ffs_find_or_alloc(struct folio *folio);
+bool f2fs_ffs_test_blk_dirty(const struct folio *folio, pgoff_t index);
void f2fs_ffs_mark_subrange_dirty(struct folio *folio, size_t offset, size_t len);
bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
size_t len);
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index d7fae1890835..5bb117e5e811 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1512,12 +1512,19 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
unsigned int segno, int off)
{
struct folio *folio;
+ size_t foff = 0;
+ bool large = false;
int err = 0;
folio = f2fs_get_lock_data_folio(inode, bidx, true);
if (IS_ERR(folio))
return PTR_ERR(folio);
+ if (f2fs_folio_has_ffs(folio)) {
+ large = true;
+ foff = offset_in_folio(folio, (loff_t)bidx << PAGE_SHIFT);
+ }
+
if (!check_valid_map(F2FS_I_SB(inode), segno, off)) {
err = -ENOENT;
goto out;
@@ -1532,6 +1539,8 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
err = -EAGAIN;
goto out;
}
+ if (large)
+ f2fs_ffs_mark_subrange_dirty(folio, foff, PAGE_SIZE);
folio_mark_dirty(folio);
folio_set_f2fs_gcing(folio);
} else {
@@ -1544,32 +1553,51 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
.op_flags = REQ_SYNC,
.old_blkaddr = NULL_ADDR,
.folio = folio,
+ .folio_offset = bidx - folio->index,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.need_lock = LOCK_REQ,
.io_type = FS_GC_DATA_IO,
};
- bool is_dirty = folio_test_dirty(folio);
+ struct f2fs_folio_state *ffs = NULL;
+ bool is_dirty = f2fs_ffs_test_blk_dirty(folio, bidx);
retry:
f2fs_folio_wait_writeback(folio, true, true);
+ if (large) {
+ ffs = (struct f2fs_folio_state *)folio->private;
+ f2fs_ffs_mark_subrange_dirty(folio, foff, PAGE_SIZE);
+ }
folio_mark_dirty(folio);
if (folio_clear_dirty_for_io(folio)) {
- inode_dec_dirty_block(inode);
- f2fs_remove_dirty_inode(inode);
+ if (!large) {
+ inode_dec_dirty_block(inode);
+ f2fs_remove_dirty_inode(inode);
+ } else if (f2fs_ffs_clear_subrange_dirty_and_test(folio,
+ foff, PAGE_SIZE)) {
+ folio_mark_dirty(folio);
+ }
}
+ if (large)
+ atomic_inc(&ffs->write_pages_pending);
folio_set_f2fs_gcing(folio);
err = f2fs_do_write_data_page(&fio);
if (err) {
folio_clear_f2fs_gcing(folio);
+ if (large)
+ atomic_dec(&ffs->write_pages_pending);
if (err == -ENOMEM) {
memalloc_retry_wait(GFP_NOFS);
goto retry;
}
- if (is_dirty)
+ if (is_dirty) {
+ if (large)
+ f2fs_ffs_mark_subrange_dirty(folio, foff, PAGE_SIZE);
folio_mark_dirty(folio);
+ }
}
}
out:
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 96bfb7d63692..06fb92fc8479 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3863,7 +3863,7 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)
if (is_inode_flag_set(inode, FI_ALIGNED_WRITE))
return CURSEG_COLD_DATA_PINNED;
- if (page_private_gcing(fio->page)) {
+ if (folio_test_f2fs_gcing(fio->folio)) {
if (fio->sbi->am.atgc_enabled &&
(fio->io_type == FS_DATA_IO) &&
(fio->sbi->gc_mode != GC_URGENT_HIGH) &&
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 08/16] f2fs: make GC migration large-folio aware
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
GC can operate on a 4K block that is cached inside a large folio.
The data lookup helpers therefore need to test and update uptodate
state for the addressed subpage instead of rejecting large folios or
treating the whole folio as the target block.
Let f2fs_get_read_data_folio() and f2fs_get_lock_data_folio() to use
subpage uptodate state. Submit single-block reads at the requested
folio offset and zero only the addressed 4K range for NEW_ADDR.
Also update `move_data_page` to mark, clear, and restore dirty
state for the target subpage, and submit write I/O with the subpage
offset recorded in f2fs_io_info.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 46 ++++++++++++++++++++++++++++++----------------
fs/f2fs/f2fs.h | 1 +
fs/f2fs/gc.c | 36 ++++++++++++++++++++++++++++++++----
fs/f2fs/segment.c | 2 +-
4 files changed, 64 insertions(+), 21 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index b5c048134e00..710213fea7a6 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1633,20 +1633,16 @@ struct folio *f2fs_get_read_data_folio(struct inode *inode, pgoff_t index,
struct dnode_of_data dn;
struct folio *folio;
int err;
-retry:
+
folio = f2fs_grab_cache_folio(mapping, index, for_write);
if (IS_ERR(folio))
return folio;
if (folio_test_large(folio)) {
- pgoff_t folio_index = mapping_align_index(mapping, index);
- unsigned long nr_pages = folio_nr_pages(folio);
-
- f2fs_folio_put(folio, true);
- invalidate_inode_pages2_range(mapping, folio_index,
- folio_index + nr_pages - 1);
- f2fs_schedule_timeout(DEFAULT_SCHEDULE_TIMEOUT);
- goto retry;
+ if (!f2fs_ffs_find_or_alloc(folio)) {
+ err = -ENOMEM;
+ goto put_err;
+ }
}
if (f2fs_lookup_read_extent_cache_block(inode, index,
@@ -1682,7 +1678,7 @@ struct folio *f2fs_get_read_data_folio(struct inode *inode, pgoff_t index,
goto put_err;
}
got_it:
- if (folio_test_uptodate(folio)) {
+ if (f2fs_ffs_test_blk_uptodate(folio, index)) {
folio_unlock(folio);
return folio;
}
@@ -1695,9 +1691,11 @@ struct folio *f2fs_get_read_data_folio(struct inode *inode, pgoff_t index,
* f2fs_init_inode_metadata.
*/
if (dn.data_blkaddr == NEW_ADDR) {
- folio_zero_segment(folio, 0, folio_size(folio));
- if (!folio_test_uptodate(folio))
- folio_mark_uptodate(folio);
+ size_t offset = offset_in_folio(folio,
+ (loff_t)index << PAGE_SHIFT);
+
+ folio_zero_segment(folio, offset, offset + PAGE_SIZE);
+ f2fs_ffs_mark_subrange_uptodate(folio, offset, PAGE_SIZE);
folio_unlock(folio);
return folio;
}
@@ -1757,7 +1755,8 @@ struct folio *f2fs_get_lock_data_folio(struct inode *inode, pgoff_t index,
/* wait for read completion */
folio_lock(folio);
- if (unlikely(folio->mapping != mapping || !folio_test_uptodate(folio))) {
+ if (unlikely(folio->mapping != mapping ||
+ !f2fs_ffs_test_blk_uptodate(folio, index))) {
f2fs_folio_put(folio, true);
return ERR_PTR(-EIO);
}
@@ -2906,6 +2905,22 @@ static void f2fs_ffs_mark_subrange_uptodate(struct folio *folio, size_t offset,
folio_mark_uptodate(folio);
}
+bool f2fs_ffs_test_blk_dirty(const struct folio *folio, pgoff_t index)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned int idx, nr_subpages;
+
+ f2fs_bug_on(F2FS_F_SB(folio), !folio_contains(folio, index));
+
+ if (!f2fs_folio_has_ffs(folio))
+ return folio_test_dirty(folio);
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ nr_subpages = folio_nr_pages(folio);
+ idx = index - folio->index;
+ return test_bit(nr_subpages + idx, ffs->state);
+}
+
static unsigned int __ffs_mark_subrange_dirty(struct folio *folio,
struct f2fs_folio_state *ffs, size_t offset, size_t len)
{
@@ -2999,7 +3014,6 @@ bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
return dirty;
}
-
static unsigned int ffs_next_dirty_subpage(struct f2fs_folio_state *ffs,
const struct folio *folio, unsigned int start,
unsigned int end)
@@ -3497,7 +3511,7 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)
return true;
if (fio) {
- if (page_private_gcing(fio->page))
+ if (folio_test_f2fs_gcing(fio->folio))
return true;
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED) &&
f2fs_is_checkpointed_data(sbi, fio->old_blkaddr)))
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index d976e6ad058b..36ec8266af69 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4493,6 +4493,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
int compr_blocks, bool allow_balance);
bool f2fs_ffs_test_blk_uptodate(const struct folio *folio, pgoff_t index);
struct f2fs_folio_state *f2fs_ffs_find_or_alloc(struct folio *folio);
+bool f2fs_ffs_test_blk_dirty(const struct folio *folio, pgoff_t index);
void f2fs_ffs_mark_subrange_dirty(struct folio *folio, size_t offset, size_t len);
bool f2fs_ffs_clear_subrange_dirty_and_test(struct folio *folio, size_t offset,
size_t len);
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index d7fae1890835..5bb117e5e811 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1512,12 +1512,19 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
unsigned int segno, int off)
{
struct folio *folio;
+ size_t foff = 0;
+ bool large = false;
int err = 0;
folio = f2fs_get_lock_data_folio(inode, bidx, true);
if (IS_ERR(folio))
return PTR_ERR(folio);
+ if (f2fs_folio_has_ffs(folio)) {
+ large = true;
+ foff = offset_in_folio(folio, (loff_t)bidx << PAGE_SHIFT);
+ }
+
if (!check_valid_map(F2FS_I_SB(inode), segno, off)) {
err = -ENOENT;
goto out;
@@ -1532,6 +1539,8 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
err = -EAGAIN;
goto out;
}
+ if (large)
+ f2fs_ffs_mark_subrange_dirty(folio, foff, PAGE_SIZE);
folio_mark_dirty(folio);
folio_set_f2fs_gcing(folio);
} else {
@@ -1544,32 +1553,51 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
.op_flags = REQ_SYNC,
.old_blkaddr = NULL_ADDR,
.folio = folio,
+ .folio_offset = bidx - folio->index,
+ .folio_blkcnt = 1,
.encrypted_page = NULL,
.need_lock = LOCK_REQ,
.io_type = FS_GC_DATA_IO,
};
- bool is_dirty = folio_test_dirty(folio);
+ struct f2fs_folio_state *ffs = NULL;
+ bool is_dirty = f2fs_ffs_test_blk_dirty(folio, bidx);
retry:
f2fs_folio_wait_writeback(folio, true, true);
+ if (large) {
+ ffs = (struct f2fs_folio_state *)folio->private;
+ f2fs_ffs_mark_subrange_dirty(folio, foff, PAGE_SIZE);
+ }
folio_mark_dirty(folio);
if (folio_clear_dirty_for_io(folio)) {
- inode_dec_dirty_block(inode);
- f2fs_remove_dirty_inode(inode);
+ if (!large) {
+ inode_dec_dirty_block(inode);
+ f2fs_remove_dirty_inode(inode);
+ } else if (f2fs_ffs_clear_subrange_dirty_and_test(folio,
+ foff, PAGE_SIZE)) {
+ folio_mark_dirty(folio);
+ }
}
+ if (large)
+ atomic_inc(&ffs->write_pages_pending);
folio_set_f2fs_gcing(folio);
err = f2fs_do_write_data_page(&fio);
if (err) {
folio_clear_f2fs_gcing(folio);
+ if (large)
+ atomic_dec(&ffs->write_pages_pending);
if (err == -ENOMEM) {
memalloc_retry_wait(GFP_NOFS);
goto retry;
}
- if (is_dirty)
+ if (is_dirty) {
+ if (large)
+ f2fs_ffs_mark_subrange_dirty(folio, foff, PAGE_SIZE);
folio_mark_dirty(folio);
+ }
}
}
out:
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 96bfb7d63692..06fb92fc8479 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3863,7 +3863,7 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)
if (is_inode_flag_set(inode, FI_ALIGNED_WRITE))
return CURSEG_COLD_DATA_PINNED;
- if (page_private_gcing(fio->page)) {
+ if (folio_test_f2fs_gcing(fio->folio)) {
if (fio->sbi->am.atgc_enabled &&
(fio->io_type == FS_DATA_IO) &&
(fio->sbi->gc_mode != GC_URGENT_HIGH) &&
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 08/16] f2fs: make GC migration large-folio aware
2026-10-14 6:44 ` Nanzhe Zhao
(?)
@ 2026-10-14 16:20 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 16:20 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu; +Cc: Daeho Jeong
Sashiko says:
> UAF on folio->private in f2fs_ffs_test_blk_uptodate due to lockless access.
> f2fs_find_data_folio() retrieves an unlocked folio from the page cache using
> f2fs_filemap_get_folio(..., FGP_ACCESSED, 0) [...] and passes this unlocked folio to
> f2fs_ffs_test_blk_uptodate [...]. Concurrently another thread can call
> f2fs_invalidate_folio() -> ffs_detach_free() [...], resulting in a Use-After-Free.
Changes:
@@ -1701,7 +1718,7 @@ struct folio *f2fs_find_data_folio(struct inode *inode, pgoff_t index,
folio = f2fs_filemap_get_folio(mapping, index, FGP_ACCESSED, 0);
if (IS_ERR(folio))
goto read;
- if (f2fs_ffs_test_blk_uptodate(folio, index))
+ if (folio_test_uptodate(folio))
return folio;
f2fs_folio_put(folio, false);
@@ -1710,11 +1727,11 @@ struct folio *f2fs_find_data_folio(struct inode *inode, pgoff_t index,
if (IS_ERR(folio))
return folio;
- if (f2fs_ffs_test_blk_uptodate(folio, index))
+ if (folio_test_uptodate(folio))
return folio;
folio_wait_locked(folio);
- if (unlikely(!f2fs_ffs_test_blk_uptodate(folio, index))) {
+ if (unlikely(!folio_test_uptodate(folio))) {
f2fs_folio_put(folio, false);
return ERR_PTR(-EIO);
}
v5 restores `folio_test_uptodate()` in `f2fs_find_data_folio()`, leaving the function unchanged.
Because this function is only used in dentry call paths and directories only use order-0 folios.
Sashiko: https://sashiko.dev/#/patchset/20261013115621.968742-1-nzzhao.sigma%40gmail.com
Thanks,
Nanzhe Zhao
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 09/16] f2fs: optimize small block size large folio read
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
The original f2fs_read_data_large_folio() implementation has limited
benefit with a 4KB block size, mainly because updating
read_pages_pending greatly increases the number of spinlock
operations.
Use len_blks to batch read_pages_pending and iostat updates for
contiguous mapped blocks.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 45 ++++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 710213fea7a6..59346b61615b 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -158,7 +158,7 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
continue;
}
- if (folio_test_large(folio)) {
+ if (f2fs_folio_has_ffs(folio)) {
struct f2fs_folio_state *ffs =
(struct f2fs_folio_state *)folio->private;
@@ -3105,7 +3105,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
pgoff_t index, offset, next_pgofs = 0;
unsigned max_nr_pages = rac ? readahead_count(rac) :
folio_nr_pages(folio);
- unsigned nrpages;
+ unsigned nrpages, len_blks;
struct f2fs_folio_state *ffs;
int ret = 0;
bool folio_in_bio = false;
@@ -3129,11 +3129,16 @@ static int f2fs_read_data_large_folio(struct inode *inode,
folio_in_bio = false;
index = folio->index;
offset = 0;
- ffs = NULL;
nrpages = folio_nr_pages(folio);
- for (; nrpages; nrpages--, max_nr_pages--, index++, offset++) {
+ for (; nrpages;
+ nrpages -= len_blks, max_nr_pages -= len_blks,
+ index += len_blks, offset += len_blks) {
sector_t block_nr;
+ unsigned int i;
+
+ len_blks = 1;
+
/*
* Map blocks using the previous result first.
*/
@@ -3162,13 +3167,23 @@ static int f2fs_read_data_large_folio(struct inode *inode,
got_it:
if ((map.m_flags & F2FS_MAP_MAPPED)) {
block_nr = map.m_pblk + index - map.m_lblk;
- if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr,
+
+ len_blks = min_t(unsigned int, nrpages, max_nr_pages);
+ len_blks = min_t(unsigned int, len_blks,
+ (unsigned int)(map.m_lblk + map.m_len - index));
+
+ for (i = 0; i < len_blks; i++) {
+ if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode),
+ block_nr + i,
DATA_GENERIC_ENHANCE_READ)) {
- ret = -EFSCORRUPTED;
- goto err_out;
+ ret = -EFSCORRUPTED;
+ goto err_out;
+ }
}
+
} else {
size_t page_offset = offset << PAGE_SHIFT;
+
folio_zero_range(folio, page_offset, PAGE_SIZE);
if (vi && !fsverity_verify_blocks(vi, folio, PAGE_SIZE, page_offset)) {
ret = -EIO;
@@ -3188,9 +3203,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
}
/* set the bitmap to wait */
- spin_lock_irq(&ffs->state_lock);
- ffs->read_pages_pending++;
- spin_unlock_irq(&ffs->state_lock);
+ f2fs_update_read_folio_pending(folio, len_blks);
}
/*
@@ -3214,17 +3227,19 @@ static int f2fs_read_data_large_folio(struct inode *inode,
* If the page is under writeback, we need to wait for
* its completion to see the correct decrypted data.
*/
- f2fs_wait_on_block_writeback(inode, block_nr);
+ f2fs_wait_on_block_writeback_range(inode, block_nr, len_blks);
- if (!bio_add_folio(bio, folio, F2FS_BLKSIZE(F2FS_I_SB(inode)),
+ if (!bio_add_folio(bio, folio,
+ len_blks * F2FS_BLKSIZE(F2FS_I_SB(inode)),
offset << PAGE_SHIFT))
goto submit_and_realloc;
folio_in_bio = true;
- inc_cache_count(F2FS_I_SB(inode), F2FS_RD_DATA);
+ for (i = 0; i < len_blks; i++)
+ inc_cache_count(F2FS_I_SB(inode), F2FS_RD_DATA);
f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO,
- F2FS_BLKSIZE(F2FS_I_SB(inode)));
- last_block_in_bio = block_nr;
+ len_blks * F2FS_BLKSIZE(F2FS_I_SB(inode)));
+ last_block_in_bio = block_nr + len_blks - 1;
}
trace_f2fs_read_folio(folio, DATA);
err_out:
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 09/16] f2fs: optimize small block size large folio read
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
The original f2fs_read_data_large_folio() implementation has limited
benefit with a 4KB block size, mainly because updating
read_pages_pending greatly increases the number of spinlock
operations.
Use len_blks to batch read_pages_pending and iostat updates for
contiguous mapped blocks.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 45 ++++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 710213fea7a6..59346b61615b 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -158,7 +158,7 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
continue;
}
- if (folio_test_large(folio)) {
+ if (f2fs_folio_has_ffs(folio)) {
struct f2fs_folio_state *ffs =
(struct f2fs_folio_state *)folio->private;
@@ -3105,7 +3105,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
pgoff_t index, offset, next_pgofs = 0;
unsigned max_nr_pages = rac ? readahead_count(rac) :
folio_nr_pages(folio);
- unsigned nrpages;
+ unsigned nrpages, len_blks;
struct f2fs_folio_state *ffs;
int ret = 0;
bool folio_in_bio = false;
@@ -3129,11 +3129,16 @@ static int f2fs_read_data_large_folio(struct inode *inode,
folio_in_bio = false;
index = folio->index;
offset = 0;
- ffs = NULL;
nrpages = folio_nr_pages(folio);
- for (; nrpages; nrpages--, max_nr_pages--, index++, offset++) {
+ for (; nrpages;
+ nrpages -= len_blks, max_nr_pages -= len_blks,
+ index += len_blks, offset += len_blks) {
sector_t block_nr;
+ unsigned int i;
+
+ len_blks = 1;
+
/*
* Map blocks using the previous result first.
*/
@@ -3162,13 +3167,23 @@ static int f2fs_read_data_large_folio(struct inode *inode,
got_it:
if ((map.m_flags & F2FS_MAP_MAPPED)) {
block_nr = map.m_pblk + index - map.m_lblk;
- if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr,
+
+ len_blks = min_t(unsigned int, nrpages, max_nr_pages);
+ len_blks = min_t(unsigned int, len_blks,
+ (unsigned int)(map.m_lblk + map.m_len - index));
+
+ for (i = 0; i < len_blks; i++) {
+ if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode),
+ block_nr + i,
DATA_GENERIC_ENHANCE_READ)) {
- ret = -EFSCORRUPTED;
- goto err_out;
+ ret = -EFSCORRUPTED;
+ goto err_out;
+ }
}
+
} else {
size_t page_offset = offset << PAGE_SHIFT;
+
folio_zero_range(folio, page_offset, PAGE_SIZE);
if (vi && !fsverity_verify_blocks(vi, folio, PAGE_SIZE, page_offset)) {
ret = -EIO;
@@ -3188,9 +3203,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
}
/* set the bitmap to wait */
- spin_lock_irq(&ffs->state_lock);
- ffs->read_pages_pending++;
- spin_unlock_irq(&ffs->state_lock);
+ f2fs_update_read_folio_pending(folio, len_blks);
}
/*
@@ -3214,17 +3227,19 @@ static int f2fs_read_data_large_folio(struct inode *inode,
* If the page is under writeback, we need to wait for
* its completion to see the correct decrypted data.
*/
- f2fs_wait_on_block_writeback(inode, block_nr);
+ f2fs_wait_on_block_writeback_range(inode, block_nr, len_blks);
- if (!bio_add_folio(bio, folio, F2FS_BLKSIZE(F2FS_I_SB(inode)),
+ if (!bio_add_folio(bio, folio,
+ len_blks * F2FS_BLKSIZE(F2FS_I_SB(inode)),
offset << PAGE_SHIFT))
goto submit_and_realloc;
folio_in_bio = true;
- inc_cache_count(F2FS_I_SB(inode), F2FS_RD_DATA);
+ for (i = 0; i < len_blks; i++)
+ inc_cache_count(F2FS_I_SB(inode), F2FS_RD_DATA);
f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO,
- F2FS_BLKSIZE(F2FS_I_SB(inode)));
- last_block_in_bio = block_nr;
+ len_blks * F2FS_BLKSIZE(F2FS_I_SB(inode)));
+ last_block_in_bio = block_nr + len_blks - 1;
}
trace_f2fs_read_folio(folio, DATA);
err_out:
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 10/16] f2fs: support partial uptodate large folio read
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
Buffered write can have write bytes smaller than folio
size for cases when folio minimum order is not zero.
This can left partially uptodate folio in page cache.
So we skip uptodate subpage read in read_data_large_folio.
Also mark hole subpage uptodate in uptodate bitmap.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 87 insertions(+), 1 deletion(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 59346b61615b..b9f2054f514f 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -148,6 +148,7 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
struct folio *folio = fi.folio;
unsigned nr_pages = fi.length >> PAGE_SHIFT;
bool finished = true;
+ bool uptodate = bio->bi_status == BLK_STS_OK;
if (!folio_test_large(folio) &&
f2fs_is_compressed_page(folio)) {
@@ -163,6 +164,9 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
(struct f2fs_folio_state *)folio->private;
spin_lock_irqsave(&ffs->state_lock, flags);
+ if (bio->bi_status == BLK_STS_OK)
+ uptodate = __ffs_mark_subrange_uptodate(folio, ffs,
+ fi.offset, fi.length);
ffs->read_pages_pending -= nr_pages;
finished = !ffs->read_pages_pending;
spin_unlock_irqrestore(&ffs->state_lock, flags);
@@ -172,7 +176,7 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
dec_cache_count(F2FS_F_SB(folio), F2FS_RD_DATA);
if (finished)
- folio_end_read(folio, bio->bi_status == BLK_STS_OK);
+ folio_end_read(folio, uptodate);
}
if (ctx)
@@ -3095,6 +3099,70 @@ static bool find_next_valid_block(const struct folio *folio,
return false;
}
+static unsigned int ffs_next_uptodate_subpage(struct f2fs_folio_state *ffs,
+ unsigned int start, unsigned int end)
+{
+ return find_next_bit(ffs->state, end + 1, start);
+}
+
+static unsigned int ffs_next_nonuptodate_subpage(struct f2fs_folio_state *ffs,
+ unsigned int start, unsigned int end)
+{
+ return find_next_zero_bit(ffs->state, end + 1, start);
+}
+
+static void f2fs_skip_fully_uptodate_front(struct folio *folio,
+ pgoff_t *index, pgoff_t *offset, unsigned int *nrpages,
+ unsigned int *max_nr_pages)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned int next, skipped;
+
+ if (!f2fs_folio_has_ffs(folio) || !*nrpages)
+ return;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ next = ffs_next_nonuptodate_subpage(ffs, *offset,
+ *offset + *nrpages - 1);
+ skipped = next - *offset;
+ if (!skipped)
+ return;
+
+ *index += skipped;
+ *offset += skipped;
+ *nrpages -= skipped;
+ *max_nr_pages -= skipped;
+}
+
+static void f2fs_truncate_read_extent(struct inode *inode, struct folio *folio,
+ pgoff_t offset, block_t block_nr,
+ unsigned int *len_blks)
+{
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ struct f2fs_folio_state *ffs;
+ unsigned int next, end;
+
+ if (!f2fs_folio_has_ffs(folio) || *len_blks <= 1)
+ return;
+
+ if (f2fs_is_multi_device(sbi)) {
+ int bidx = f2fs_target_device_index(sbi, block_nr);
+
+ *len_blks = min_t(unsigned int, *len_blks,
+ FDEV(bidx).end_blk + 1 - block_nr);
+ }
+ *len_blks = min_t(unsigned int, *len_blks,
+ (unsigned int)fscrypt_limit_io_blocks(inode,
+ folio->index + offset,
+ *len_blks));
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ end = offset + *len_blks - 1;
+ next = ffs_next_uptodate_subpage(ffs, offset + 1, end);
+ if (next <= end)
+ *len_blks = next - offset;
+}
+
static int f2fs_read_data_large_folio(struct inode *inode,
struct fsverity_info *vi,
struct readahead_control *rac, struct folio *folio)
@@ -3139,6 +3207,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
len_blks = 1;
+ f2fs_skip_fully_uptodate_front(folio, &index, &offset,
+ &nrpages, &max_nr_pages);
+ if (!nrpages)
+ break;
+
/*
* Map blocks using the previous result first.
*/
@@ -3171,6 +3244,8 @@ static int f2fs_read_data_large_folio(struct inode *inode,
len_blks = min_t(unsigned int, nrpages, max_nr_pages);
len_blks = min_t(unsigned int, len_blks,
(unsigned int)(map.m_lblk + map.m_len - index));
+ f2fs_truncate_read_extent(inode, folio, offset,
+ block_nr, &len_blks);
for (i = 0; i < len_blks; i++) {
if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode),
@@ -3189,6 +3264,17 @@ static int f2fs_read_data_large_folio(struct inode *inode,
ret = -EIO;
goto err_out;
}
+ if (folio_test_large(folio)) {
+ ffs = f2fs_ffs_find_or_alloc(folio);
+ if (!ffs) {
+ ret = -ENOMEM;
+ goto err_out;
+ }
+ spin_lock_irq(&ffs->state_lock);
+ __ffs_mark_subrange_uptodate(folio, ffs,
+ page_offset, PAGE_SIZE);
+ spin_unlock_irq(&ffs->state_lock);
+ }
continue;
}
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 10/16] f2fs: support partial uptodate large folio read
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
Buffered write can have write bytes smaller than folio
size for cases when folio minimum order is not zero.
This can left partially uptodate folio in page cache.
So we skip uptodate subpage read in read_data_large_folio.
Also mark hole subpage uptodate in uptodate bitmap.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 87 insertions(+), 1 deletion(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 59346b61615b..b9f2054f514f 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -148,6 +148,7 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
struct folio *folio = fi.folio;
unsigned nr_pages = fi.length >> PAGE_SHIFT;
bool finished = true;
+ bool uptodate = bio->bi_status == BLK_STS_OK;
if (!folio_test_large(folio) &&
f2fs_is_compressed_page(folio)) {
@@ -163,6 +164,9 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
(struct f2fs_folio_state *)folio->private;
spin_lock_irqsave(&ffs->state_lock, flags);
+ if (bio->bi_status == BLK_STS_OK)
+ uptodate = __ffs_mark_subrange_uptodate(folio, ffs,
+ fi.offset, fi.length);
ffs->read_pages_pending -= nr_pages;
finished = !ffs->read_pages_pending;
spin_unlock_irqrestore(&ffs->state_lock, flags);
@@ -172,7 +176,7 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
dec_cache_count(F2FS_F_SB(folio), F2FS_RD_DATA);
if (finished)
- folio_end_read(folio, bio->bi_status == BLK_STS_OK);
+ folio_end_read(folio, uptodate);
}
if (ctx)
@@ -3095,6 +3099,70 @@ static bool find_next_valid_block(const struct folio *folio,
return false;
}
+static unsigned int ffs_next_uptodate_subpage(struct f2fs_folio_state *ffs,
+ unsigned int start, unsigned int end)
+{
+ return find_next_bit(ffs->state, end + 1, start);
+}
+
+static unsigned int ffs_next_nonuptodate_subpage(struct f2fs_folio_state *ffs,
+ unsigned int start, unsigned int end)
+{
+ return find_next_zero_bit(ffs->state, end + 1, start);
+}
+
+static void f2fs_skip_fully_uptodate_front(struct folio *folio,
+ pgoff_t *index, pgoff_t *offset, unsigned int *nrpages,
+ unsigned int *max_nr_pages)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned int next, skipped;
+
+ if (!f2fs_folio_has_ffs(folio) || !*nrpages)
+ return;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ next = ffs_next_nonuptodate_subpage(ffs, *offset,
+ *offset + *nrpages - 1);
+ skipped = next - *offset;
+ if (!skipped)
+ return;
+
+ *index += skipped;
+ *offset += skipped;
+ *nrpages -= skipped;
+ *max_nr_pages -= skipped;
+}
+
+static void f2fs_truncate_read_extent(struct inode *inode, struct folio *folio,
+ pgoff_t offset, block_t block_nr,
+ unsigned int *len_blks)
+{
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ struct f2fs_folio_state *ffs;
+ unsigned int next, end;
+
+ if (!f2fs_folio_has_ffs(folio) || *len_blks <= 1)
+ return;
+
+ if (f2fs_is_multi_device(sbi)) {
+ int bidx = f2fs_target_device_index(sbi, block_nr);
+
+ *len_blks = min_t(unsigned int, *len_blks,
+ FDEV(bidx).end_blk + 1 - block_nr);
+ }
+ *len_blks = min_t(unsigned int, *len_blks,
+ (unsigned int)fscrypt_limit_io_blocks(inode,
+ folio->index + offset,
+ *len_blks));
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ end = offset + *len_blks - 1;
+ next = ffs_next_uptodate_subpage(ffs, offset + 1, end);
+ if (next <= end)
+ *len_blks = next - offset;
+}
+
static int f2fs_read_data_large_folio(struct inode *inode,
struct fsverity_info *vi,
struct readahead_control *rac, struct folio *folio)
@@ -3139,6 +3207,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
len_blks = 1;
+ f2fs_skip_fully_uptodate_front(folio, &index, &offset,
+ &nrpages, &max_nr_pages);
+ if (!nrpages)
+ break;
+
/*
* Map blocks using the previous result first.
*/
@@ -3171,6 +3244,8 @@ static int f2fs_read_data_large_folio(struct inode *inode,
len_blks = min_t(unsigned int, nrpages, max_nr_pages);
len_blks = min_t(unsigned int, len_blks,
(unsigned int)(map.m_lblk + map.m_len - index));
+ f2fs_truncate_read_extent(inode, folio, offset,
+ block_nr, &len_blks);
for (i = 0; i < len_blks; i++) {
if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode),
@@ -3189,6 +3264,17 @@ static int f2fs_read_data_large_folio(struct inode *inode,
ret = -EIO;
goto err_out;
}
+ if (folio_test_large(folio)) {
+ ffs = f2fs_ffs_find_or_alloc(folio);
+ if (!ffs) {
+ ret = -ENOMEM;
+ goto err_out;
+ }
+ spin_lock_irq(&ffs->state_lock);
+ __ffs_mark_subrange_uptodate(folio, ffs,
+ page_offset, PAGE_SIZE);
+ spin_unlock_irq(&ffs->state_lock);
+ }
continue;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 10/16] f2fs: support partial uptodate large folio read
2026-10-14 6:44 ` Nanzhe Zhao
(?)
@ 2026-10-14 16:20 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 16:20 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu; +Cc: Daeho Jeong
Sashiko says:
> Because the batch size (len_blks) is based on the mapped extent length and is not
> clamped at device boundaries or fscrypt limits, could this cause IO errors or silent data
> corruption?
Changes:
@@ -3117,15 +3134,28 @@ static void f2fs_skip_fully_uptodate_front(struct folio *folio,
*max_nr_pages -= skipped;
}
-static void f2fs_truncate_read_extent(struct folio *folio, pgoff_t offset,
- unsigned int *len_blks)
+static void f2fs_truncate_read_extent(struct inode *inode, struct folio *folio,
+ pgoff_t offset, block_t block_nr,
+ unsigned int *len_blks)
{
+ struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct f2fs_folio_state *ffs;
unsigned int next, end;
if (!f2fs_folio_has_ffs(folio) || *len_blks <= 1)
return;
+ if (f2fs_is_multi_device(sbi)) {
+ int bidx = f2fs_target_device_index(sbi, block_nr);
+
+ *len_blks = min_t(unsigned int, *len_blks,
+ FDEV(bidx).end_blk + 1 - block_nr);
+ }
+ *len_blks = min_t(unsigned int, *len_blks,
+ (unsigned int)fscrypt_limit_io_blocks(inode,
+ folio->index + offset,
+ *len_blks));
+
ffs = (struct f2fs_folio_state *)folio->private;
end = offset + *len_blks - 1;
next = ffs_next_uptodate_subpage(ffs, offset + 1, end);
v5 clamps batch `len_blks` to device boundaries and `fscrypt_limit_io_blocks()` to avoid DUN discontinuities.
Sashiko says:
> f2fs_ffs_find_or_alloc() can return NULL on allocation failure, which is immediately
> dereferenced by spin_lock_irq() because there is no NULL check.
Changes:
@@ -3235,6 +3266,10 @@ static int f2fs_read_data_large_folio(struct inode *inode,
}
if (folio_test_large(folio)) {
ffs = f2fs_ffs_find_or_alloc(folio);
+ if (!ffs) {
+ ret = -ENOMEM;
+ goto err_out;
+ }
spin_lock_irq(&ffs->state_lock);
__ffs_mark_subrange_uptodate(folio, ffs,
page_offset, PAGE_SIZE);
The hole-handling branch missed to handle -ENOMEM for f2fs_ffs_find_or_alloc,
v5 fixes this.
Sashiko: https://sashiko.dev/#/patchset/20261013115621.968742-1-nzzhao.sigma%40gmail.com
Thanks,
Nanzhe Zhao
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 11/16] f2fs: handle partial truncate of large folio dirty subpages
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
A large folio can be partial truncated and stays in folio mapping, we
need to clear the subrange dirty bits and uptodate bits that the partial
truncate covers. If this partial truncate happens to clear the last
subrange dirty bits, then cancel the whole folio dirty state.
Also add a guard in f2fs_write_folio_dirty_range() so a large folio
subpage whose disk block was already truncated (NULL_ADDR) is skipped
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 122 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index b9f2054f514f..4228c26bee0d 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -362,6 +362,27 @@ static void f2fs_cache_write_end_bio(struct bio *bio)
bio_put(bio);
}
+static bool f2fs_ffs_has_dirty_subpage(struct folio *folio)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned long flags;
+ unsigned int nr_subpages;
+ bool dirty;
+
+ if (!f2fs_folio_has_ffs(folio))
+ return false;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ nr_subpages = folio_nr_pages(folio);
+
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ dirty = find_next_bit(ffs->state, 2 * nr_subpages,
+ nr_subpages) < 2 * nr_subpages;
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+
+ return dirty;
+}
+
static void f2fs_write_end_bio(struct bio *bio)
{
struct f2fs_sb_info *sbi = bio->bi_private;
@@ -418,7 +439,8 @@ static void f2fs_write_end_bio(struct bio *bio)
wake_up(&sbi->cp_wait);
if (finished) {
- folio_clear_f2fs_gcing(folio);
+ if (!f2fs_ffs_has_dirty_subpage(folio))
+ folio_clear_f2fs_gcing(folio);
folio_end_writeback(folio);
}
}
@@ -2909,6 +2931,40 @@ static void f2fs_ffs_mark_subrange_uptodate(struct folio *folio, size_t offset,
folio_mark_uptodate(folio);
}
+static void ffs_clear_subrange_uptodate(struct folio *folio,
+ size_t offset, size_t len)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned int nr_subpages, start, end;
+ unsigned long flags;
+
+ f2fs_bug_on(F2FS_F_SB(folio), offset + len > folio_size(folio));
+
+ if (!f2fs_folio_has_ffs(folio))
+ return;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ nr_subpages = folio_nr_pages(folio);
+ start = offset >> PAGE_SHIFT;
+ end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ end = min(end, nr_subpages);
+
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ bitmap_clear(ffs->state, start, end - start);
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+}
+
+static void f2fs_clear_truncated_page_state(struct folio *folio, pgoff_t i)
+{
+ if (f2fs_folio_has_ffs(folio)) {
+ ffs_clear_subrange_uptodate(folio,
+ (loff_t)i << PAGE_SHIFT, PAGE_SIZE);
+ } else {
+ folio_clear_uptodate(folio);
+ folio_clear_f2fs_gcing(folio);
+ }
+}
+
bool f2fs_ffs_test_blk_dirty(const struct folio *folio, pgoff_t index)
{
struct f2fs_folio_state *ffs;
@@ -3811,12 +3867,31 @@ static int f2fs_write_folio_dirty_range(struct folio *folio, int *submitted,
}
err = f2fs_get_dnode_of_data(&dn, data_idx, LOOKUP_NODE);
- if (err)
+ /*
+ * If a subpage of folio for a cow file is dirtied but not
+ * reserve a cow block, fallback to original inode to lookup
+ * block address
+ */
+ if (atomic_commit && (err == -ENOENT ||
+ (!err && dn.data_blkaddr == NULL_ADDR))) {
+ f2fs_put_dnode(&dn);
+ set_new_dnode(&dn, inode, NULL, NULL, 0);
+ err = f2fs_get_dnode_of_data(&dn, data_idx,
+ LOOKUP_NODE);
+ }
+ if (err && err != -ENOENT)
goto block_done;
dn_held = true;
fio.old_blkaddr = dn.data_blkaddr;
+ /* This page is already truncated */
+ if (err == -ENOENT || fio.old_blkaddr == NULL_ADDR) {
+ f2fs_clear_truncated_page_state(folio, i);
+ err = 0;
+ goto block_done;
+ }
+
got_it:
if (__is_valid_data_blkaddr(fio.old_blkaddr) &&
!f2fs_is_valid_blkaddr(sbi, fio.old_blkaddr,
@@ -4366,6 +4441,7 @@ static int f2fs_write_cache_folios(struct address_space *mapping,
bool verity_in_progress;
int folio_submitted = 0;
bool bias_added = false;
+ bool dirty;
submitted = 0;
retry = false;
@@ -4514,9 +4590,9 @@ static int f2fs_write_cache_folios(struct address_space *mapping,
* Redirty the folio if dirty subranges remain in a large
* folio, or if order-0 writeback fails due to an error.
*/
- if (f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
- (err ? pos : end_pos) - folio_pos(folio)) ||
- err)
+ dirty = f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
+ (err ? pos : end_pos) - folio_pos(folio));
+ if (dirty || err)
folio_redirty_for_writepage(wbc, folio);
else if (!f2fs_folio_has_ffs(folio))
inode_dec_dirty_block(inode);
@@ -4527,6 +4603,14 @@ static int f2fs_write_cache_folios(struct address_space *mapping,
*/
if (bias_added &&
atomic_dec_and_test(&ffs->write_pages_pending)) {
+ /*
+ * For a large folio we clear PAGE_PRIVATE_GCING only
+ * when the last dirty bit is cleared, otherwise the
+ * remaining subpages are no longer written back as
+ * checkpoint-guaranteed data (f2fs_is_cp_guaranteed()).
+ */
+ if (!dirty)
+ folio_clear_f2fs_gcing(folio);
folio_end_writeback(folio);
} else if (!folio_submitted && folio_test_writeback(folio)) {
/*
@@ -5354,10 +5438,41 @@ void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length)
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
if (inode->i_ino >= F2FS_ROOT_INO(sbi) &&
- (offset || length != folio_size(folio)))
+ (offset || length != folio_size(folio))) {
+ size_t clear_start = round_up(offset, PAGE_SIZE);
+ size_t clear_end = round_down(offset + length, PAGE_SIZE);
+ size_t clear_length;
+ bool dirty;
+
+ /*
+ * If the truncated range falls within a single subpage, no
+ * subpage state needs to be cleared.
+ */
+ if (clear_start >= clear_end || !f2fs_folio_has_ffs(folio))
+ return;
+
+ clear_length = clear_end - clear_start;
+ dirty = f2fs_ffs_clear_subrange_dirty_and_test(folio,
+ clear_start, clear_length);
+ ffs_clear_subrange_uptodate(folio, clear_start, clear_length);
+ folio_clear_uptodate(folio);
+
+ /*
+ * If the truncated subrange happens to clear the remaining
+ * dirty bitmap of the whole folio, cancel the folio-level
+ * dirty state.
+ */
+ if (!dirty && folio_test_dirty(folio))
+ folio_cancel_dirty(folio);
+ if (!dirty && !folio_test_writeback(folio))
+ folio_clear_f2fs_gcing(folio);
return;
+ }
- if (folio_test_dirty(folio)) {
+ if (f2fs_folio_has_ffs(folio)) {
+ f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
+ folio_size(folio));
+ } else if (folio_test_dirty(folio)) {
inode_dec_dirty_block(inode);
f2fs_remove_dirty_inode(inode);
}
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 11/16] f2fs: handle partial truncate of large folio dirty subpages
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
A large folio can be partial truncated and stays in folio mapping, we
need to clear the subrange dirty bits and uptodate bits that the partial
truncate covers. If this partial truncate happens to clear the last
subrange dirty bits, then cancel the whole folio dirty state.
Also add a guard in f2fs_write_folio_dirty_range() so a large folio
subpage whose disk block was already truncated (NULL_ADDR) is skipped
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 122 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index b9f2054f514f..4228c26bee0d 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -362,6 +362,27 @@ static void f2fs_cache_write_end_bio(struct bio *bio)
bio_put(bio);
}
+static bool f2fs_ffs_has_dirty_subpage(struct folio *folio)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned long flags;
+ unsigned int nr_subpages;
+ bool dirty;
+
+ if (!f2fs_folio_has_ffs(folio))
+ return false;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ nr_subpages = folio_nr_pages(folio);
+
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ dirty = find_next_bit(ffs->state, 2 * nr_subpages,
+ nr_subpages) < 2 * nr_subpages;
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+
+ return dirty;
+}
+
static void f2fs_write_end_bio(struct bio *bio)
{
struct f2fs_sb_info *sbi = bio->bi_private;
@@ -418,7 +439,8 @@ static void f2fs_write_end_bio(struct bio *bio)
wake_up(&sbi->cp_wait);
if (finished) {
- folio_clear_f2fs_gcing(folio);
+ if (!f2fs_ffs_has_dirty_subpage(folio))
+ folio_clear_f2fs_gcing(folio);
folio_end_writeback(folio);
}
}
@@ -2909,6 +2931,40 @@ static void f2fs_ffs_mark_subrange_uptodate(struct folio *folio, size_t offset,
folio_mark_uptodate(folio);
}
+static void ffs_clear_subrange_uptodate(struct folio *folio,
+ size_t offset, size_t len)
+{
+ struct f2fs_folio_state *ffs;
+ unsigned int nr_subpages, start, end;
+ unsigned long flags;
+
+ f2fs_bug_on(F2FS_F_SB(folio), offset + len > folio_size(folio));
+
+ if (!f2fs_folio_has_ffs(folio))
+ return;
+
+ ffs = (struct f2fs_folio_state *)folio->private;
+ nr_subpages = folio_nr_pages(folio);
+ start = offset >> PAGE_SHIFT;
+ end = (offset + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ end = min(end, nr_subpages);
+
+ spin_lock_irqsave(&ffs->state_lock, flags);
+ bitmap_clear(ffs->state, start, end - start);
+ spin_unlock_irqrestore(&ffs->state_lock, flags);
+}
+
+static void f2fs_clear_truncated_page_state(struct folio *folio, pgoff_t i)
+{
+ if (f2fs_folio_has_ffs(folio)) {
+ ffs_clear_subrange_uptodate(folio,
+ (loff_t)i << PAGE_SHIFT, PAGE_SIZE);
+ } else {
+ folio_clear_uptodate(folio);
+ folio_clear_f2fs_gcing(folio);
+ }
+}
+
bool f2fs_ffs_test_blk_dirty(const struct folio *folio, pgoff_t index)
{
struct f2fs_folio_state *ffs;
@@ -3811,12 +3867,31 @@ static int f2fs_write_folio_dirty_range(struct folio *folio, int *submitted,
}
err = f2fs_get_dnode_of_data(&dn, data_idx, LOOKUP_NODE);
- if (err)
+ /*
+ * If a subpage of folio for a cow file is dirtied but not
+ * reserve a cow block, fallback to original inode to lookup
+ * block address
+ */
+ if (atomic_commit && (err == -ENOENT ||
+ (!err && dn.data_blkaddr == NULL_ADDR))) {
+ f2fs_put_dnode(&dn);
+ set_new_dnode(&dn, inode, NULL, NULL, 0);
+ err = f2fs_get_dnode_of_data(&dn, data_idx,
+ LOOKUP_NODE);
+ }
+ if (err && err != -ENOENT)
goto block_done;
dn_held = true;
fio.old_blkaddr = dn.data_blkaddr;
+ /* This page is already truncated */
+ if (err == -ENOENT || fio.old_blkaddr == NULL_ADDR) {
+ f2fs_clear_truncated_page_state(folio, i);
+ err = 0;
+ goto block_done;
+ }
+
got_it:
if (__is_valid_data_blkaddr(fio.old_blkaddr) &&
!f2fs_is_valid_blkaddr(sbi, fio.old_blkaddr,
@@ -4366,6 +4441,7 @@ static int f2fs_write_cache_folios(struct address_space *mapping,
bool verity_in_progress;
int folio_submitted = 0;
bool bias_added = false;
+ bool dirty;
submitted = 0;
retry = false;
@@ -4514,9 +4590,9 @@ static int f2fs_write_cache_folios(struct address_space *mapping,
* Redirty the folio if dirty subranges remain in a large
* folio, or if order-0 writeback fails due to an error.
*/
- if (f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
- (err ? pos : end_pos) - folio_pos(folio)) ||
- err)
+ dirty = f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
+ (err ? pos : end_pos) - folio_pos(folio));
+ if (dirty || err)
folio_redirty_for_writepage(wbc, folio);
else if (!f2fs_folio_has_ffs(folio))
inode_dec_dirty_block(inode);
@@ -4527,6 +4603,14 @@ static int f2fs_write_cache_folios(struct address_space *mapping,
*/
if (bias_added &&
atomic_dec_and_test(&ffs->write_pages_pending)) {
+ /*
+ * For a large folio we clear PAGE_PRIVATE_GCING only
+ * when the last dirty bit is cleared, otherwise the
+ * remaining subpages are no longer written back as
+ * checkpoint-guaranteed data (f2fs_is_cp_guaranteed()).
+ */
+ if (!dirty)
+ folio_clear_f2fs_gcing(folio);
folio_end_writeback(folio);
} else if (!folio_submitted && folio_test_writeback(folio)) {
/*
@@ -5354,10 +5438,41 @@ void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length)
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
if (inode->i_ino >= F2FS_ROOT_INO(sbi) &&
- (offset || length != folio_size(folio)))
+ (offset || length != folio_size(folio))) {
+ size_t clear_start = round_up(offset, PAGE_SIZE);
+ size_t clear_end = round_down(offset + length, PAGE_SIZE);
+ size_t clear_length;
+ bool dirty;
+
+ /*
+ * If the truncated range falls within a single subpage, no
+ * subpage state needs to be cleared.
+ */
+ if (clear_start >= clear_end || !f2fs_folio_has_ffs(folio))
+ return;
+
+ clear_length = clear_end - clear_start;
+ dirty = f2fs_ffs_clear_subrange_dirty_and_test(folio,
+ clear_start, clear_length);
+ ffs_clear_subrange_uptodate(folio, clear_start, clear_length);
+ folio_clear_uptodate(folio);
+
+ /*
+ * If the truncated subrange happens to clear the remaining
+ * dirty bitmap of the whole folio, cancel the folio-level
+ * dirty state.
+ */
+ if (!dirty && folio_test_dirty(folio))
+ folio_cancel_dirty(folio);
+ if (!dirty && !folio_test_writeback(folio))
+ folio_clear_f2fs_gcing(folio);
return;
+ }
- if (folio_test_dirty(folio)) {
+ if (f2fs_folio_has_ffs(folio)) {
+ f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
+ folio_size(folio));
+ } else if (folio_test_dirty(folio)) {
inode_dec_dirty_block(inode);
f2fs_remove_dirty_inode(inode);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 11/16] f2fs: handle partial truncate of large folio dirty subpages
2026-10-14 6:44 ` Nanzhe Zhao
(?)
@ 2026-10-14 16:20 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 16:20 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu; +Cc: Daeho Jeong
Sashiko says:
> Could this lead to silent data loss for order-0 folios on recoverable errors? If a
> recoverable error like -ENOMEM or -EIO occurs [..] the code clears the dirty tags and
> advances, silently discarding the unwritten blocks.
Changes:
@@ -4531,4 +4593,4 @@ static int f2fs_write_cache_folios(struct address_space *mapping,
dirty = f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
(err ? pos : end_pos) - folio_pos(folio));
- if (dirty)
+ if (dirty || err)
folio_redirty_for_writepage(wbc, folio);
v5 adds `|| err` to re-dirty the folio on writeback failure so it is retried, matching `f2fs_write_single_data_page()`.
Sashiko: https://sashiko.dev/#/patchset/20261013115621.968742-1-nzzhao.sigma%40gmail.com
Thanks,
Nanzhe Zhao
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 12/16] f2fs: wait for folio writeback before ffs_detach_free
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, kernel test robot,
Pengfei Li, Dev Jain, David Hildenbrand, linux-kernel, Bo Zhang,
Kalesh Singh, Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
truncate_inode_pages_range() can invalidate a large folio that is still
under writeback, which can result in the following use-after-free:
CPU0 (writeback) CPU1 (truncate)
---- ----
f2fs_write_cache_folios()
folio_start_writeback(folio)
/* submit bios */
retry_out:
folio_unlock(folio)
/* all bios submitted; folio lock released */
truncate_inode_pages_range()
find_lock_entries() /* locks the folio */
truncate_cleanup_folio(folio)
folio_invalidate(folio, 0, folio_size(folio))
-> f2fs_invalidate_folio(folio, 0,
folio_size(folio))
f2fs_write_end_bio(bio)
ffs = folio->private ffs_detach_free(folio)
folio_detach_private(folio)
kfree(ffs)
atomic_sub_and_test(nr_pages,
&ffs->write_pages_pending) <-- use-after-free
Wait for folio writeback in invalidate_folio, then we can free the
folio state without any other remaining user.
Reported-by: kernel test robot <yi1.lai@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202610081027.b13dcf10-lkp@intel.com
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 4228c26bee0d..9cd1c34fe6c8 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -5470,6 +5470,14 @@ void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length)
}
if (f2fs_folio_has_ffs(folio)) {
+ /*
+ * The folio may still be under writeback with bios in
+ * completion that need to access f2fs_folio_state. Wait
+ * for the writeback to complete before freeing the state,
+ * otherwise it will result in use-after-free.
+ */
+ folio_wait_writeback(folio);
+
f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
folio_size(folio));
} else if (folio_test_dirty(folio)) {
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 12/16] f2fs: wait for folio writeback before ffs_detach_free
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts, kernel test robot
truncate_inode_pages_range() can invalidate a large folio that is still
under writeback, which can result in the following use-after-free:
CPU0 (writeback) CPU1 (truncate)
---- ----
f2fs_write_cache_folios()
folio_start_writeback(folio)
/* submit bios */
retry_out:
folio_unlock(folio)
/* all bios submitted; folio lock released */
truncate_inode_pages_range()
find_lock_entries() /* locks the folio */
truncate_cleanup_folio(folio)
folio_invalidate(folio, 0, folio_size(folio))
-> f2fs_invalidate_folio(folio, 0,
folio_size(folio))
f2fs_write_end_bio(bio)
ffs = folio->private ffs_detach_free(folio)
folio_detach_private(folio)
kfree(ffs)
atomic_sub_and_test(nr_pages,
&ffs->write_pages_pending) <-- use-after-free
Wait for folio writeback in invalidate_folio, then we can free the
folio state without any other remaining user.
Reported-by: kernel test robot <yi1.lai@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202610081027.b13dcf10-lkp@intel.com
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 4228c26bee0d..9cd1c34fe6c8 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -5470,6 +5470,14 @@ void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length)
}
if (f2fs_folio_has_ffs(folio)) {
+ /*
+ * The folio may still be under writeback with bios in
+ * completion that need to access f2fs_folio_state. Wait
+ * for the writeback to complete before freeing the state,
+ * otherwise it will result in use-after-free.
+ */
+ folio_wait_writeback(folio);
+
f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
folio_size(folio));
} else if (folio_test_dirty(folio)) {
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 13/16] f2fs: fix zeroing paths for large folios
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
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 | 18 +++++++++++++-----
fs/f2fs/f2fs.h | 1 +
fs/f2fs/file.c | 29 ++++++++++++++++++++++++-----
3 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 9cd1c34fe6c8..45861c31fe76 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1816,6 +1816,12 @@ struct folio *f2fs_get_new_data_folio(struct inode *inode,
return ERR_PTR(-ENOMEM);
}
+ if (folio_test_large(folio) && !f2fs_ffs_find_or_alloc(folio)) {
+ f2fs_folio_put(folio, true);
+ f2fs_put_cache(ientry, true);
+ return ERR_PTR(-ENOMEM);
+ }
+
set_new_dnode(&dn, inode, ientry, NULL, 0);
err = f2fs_reserve_block(&dn, index);
if (err) {
@@ -1825,13 +1831,15 @@ struct folio *f2fs_get_new_data_folio(struct inode *inode,
if (!ientry)
f2fs_put_dnode(&dn);
- if (folio_test_uptodate(folio))
+ if (f2fs_ffs_test_blk_uptodate(folio, index))
goto got_it;
if (dn.data_blkaddr == NEW_ADDR) {
- folio_zero_segment(folio, 0, folio_size(folio));
- if (!folio_test_uptodate(folio))
- folio_mark_uptodate(folio);
+ size_t off = offset_in_folio(folio,
+ (loff_t)index << PAGE_SHIFT);
+
+ folio_zero_segment(folio, off, off + PAGE_SIZE);
+ f2fs_ffs_mark_subrange_uptodate(folio, off, PAGE_SIZE);
} else {
f2fs_folio_put(folio, true);
@@ -2908,7 +2916,7 @@ bool f2fs_ffs_test_blk_uptodate(const struct folio *folio, pgoff_t index)
return test_bit(idx, ffs->state);
}
-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 36ec8266af69..ddff43bcb800 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4480,6 +4480,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 f2fs_cached_block *ientry, 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 30f1484d2f48..5a8dbe228fb1 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -837,12 +837,13 @@ 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;
+ size_t blk_end;
- if (!offset && !cache_only)
+ if (!(from & (PAGE_SIZE - 1)) && !cache_only)
return 0;
if (cache_only) {
@@ -860,12 +861,22 @@ static int truncate_partial_data_page(struct inode *inode, u64 from,
return PTR_ERR(folio) == -ENOENT ? 0 : PTR_ERR(folio);
truncate_out:
f2fs_folio_wait_writeback(folio, true, true);
- folio_zero_segment(folio, offset, folio_size(folio));
+ folio_off = offset_in_folio(folio, from);
+ blk_end = min_t(size_t, round_up(folio_off, PAGE_SIZE),
+ folio_size(folio));
+ folio_zero_segment(folio, folio_off, blk_end);
/* 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) {
+ /*
+ * The folio was read back above, so the subpage is
+ * already uptodate and dirty data stays valid.
+ */
+ f2fs_ffs_mark_subrange_dirty(folio, folio_off,
+ blk_end - folio_off);
folio_mark_dirty(folio);
+ }
f2fs_folio_put(folio, true);
return 0;
}
@@ -1329,6 +1340,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;
@@ -1343,7 +1355,14 @@ static int fill_zero(struct inode *inode, pgoff_t index,
return PTR_ERR(folio);
f2fs_folio_wait_writeback(folio, 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);
+ /*
+ * This subpage must be uptodate here, which is guaranteed by
+ * f2fs_get_new_data_folio() above.
+ */
+ f2fs_ffs_mark_subrange_dirty(folio, folio_off, len);
folio_mark_dirty(folio);
f2fs_folio_put(folio, true);
return 0;
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 13/16] f2fs: fix zeroing paths for large folios
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
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 | 18 +++++++++++++-----
fs/f2fs/f2fs.h | 1 +
fs/f2fs/file.c | 29 ++++++++++++++++++++++++-----
3 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 9cd1c34fe6c8..45861c31fe76 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1816,6 +1816,12 @@ struct folio *f2fs_get_new_data_folio(struct inode *inode,
return ERR_PTR(-ENOMEM);
}
+ if (folio_test_large(folio) && !f2fs_ffs_find_or_alloc(folio)) {
+ f2fs_folio_put(folio, true);
+ f2fs_put_cache(ientry, true);
+ return ERR_PTR(-ENOMEM);
+ }
+
set_new_dnode(&dn, inode, ientry, NULL, 0);
err = f2fs_reserve_block(&dn, index);
if (err) {
@@ -1825,13 +1831,15 @@ struct folio *f2fs_get_new_data_folio(struct inode *inode,
if (!ientry)
f2fs_put_dnode(&dn);
- if (folio_test_uptodate(folio))
+ if (f2fs_ffs_test_blk_uptodate(folio, index))
goto got_it;
if (dn.data_blkaddr == NEW_ADDR) {
- folio_zero_segment(folio, 0, folio_size(folio));
- if (!folio_test_uptodate(folio))
- folio_mark_uptodate(folio);
+ size_t off = offset_in_folio(folio,
+ (loff_t)index << PAGE_SHIFT);
+
+ folio_zero_segment(folio, off, off + PAGE_SIZE);
+ f2fs_ffs_mark_subrange_uptodate(folio, off, PAGE_SIZE);
} else {
f2fs_folio_put(folio, true);
@@ -2908,7 +2916,7 @@ bool f2fs_ffs_test_blk_uptodate(const struct folio *folio, pgoff_t index)
return test_bit(idx, ffs->state);
}
-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 36ec8266af69..ddff43bcb800 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4480,6 +4480,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 f2fs_cached_block *ientry, 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 30f1484d2f48..5a8dbe228fb1 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -837,12 +837,13 @@ 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;
+ size_t blk_end;
- if (!offset && !cache_only)
+ if (!(from & (PAGE_SIZE - 1)) && !cache_only)
return 0;
if (cache_only) {
@@ -860,12 +861,22 @@ static int truncate_partial_data_page(struct inode *inode, u64 from,
return PTR_ERR(folio) == -ENOENT ? 0 : PTR_ERR(folio);
truncate_out:
f2fs_folio_wait_writeback(folio, true, true);
- folio_zero_segment(folio, offset, folio_size(folio));
+ folio_off = offset_in_folio(folio, from);
+ blk_end = min_t(size_t, round_up(folio_off, PAGE_SIZE),
+ folio_size(folio));
+ folio_zero_segment(folio, folio_off, blk_end);
/* 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) {
+ /*
+ * The folio was read back above, so the subpage is
+ * already uptodate and dirty data stays valid.
+ */
+ f2fs_ffs_mark_subrange_dirty(folio, folio_off,
+ blk_end - folio_off);
folio_mark_dirty(folio);
+ }
f2fs_folio_put(folio, true);
return 0;
}
@@ -1329,6 +1340,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;
@@ -1343,7 +1355,14 @@ static int fill_zero(struct inode *inode, pgoff_t index,
return PTR_ERR(folio);
f2fs_folio_wait_writeback(folio, 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);
+ /*
+ * This subpage must be uptodate here, which is guaranteed by
+ * f2fs_get_new_data_folio() above.
+ */
+ f2fs_ffs_mark_subrange_dirty(folio, folio_off, len);
folio_mark_dirty(folio);
f2fs_folio_put(folio, true);
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 14/16] f2fs: handle block cloning within the same large folio
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
With large folios, the source and destination block in __clone_blkaddrs()
can belong to the same folio during same-inode operations such as
collapse range and insert range.
In that case, locking the source folio and then looking up the
destination folio can try to lock the same folio again. It also copies
from and to offset 0, which is only correct for order-0 folios.
Detect the same-inode, same-folio case before looking up the destination
folio. Then in this case,we reserve the destination block explicitly.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/file.c | 61 +++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 53 insertions(+), 8 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 5a8dbe228fb1..cad5329bbfd6 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1602,25 +1602,70 @@ static int __clone_blkaddrs(struct inode *src_inode, struct inode *dst_inode,
f2fs_put_dnode(&dn);
} else {
struct folio *fsrc, *fdst;
+ size_t src_off, dst_off;
+ bool same_folio;
fsrc = f2fs_get_lock_data_folio(src_inode,
src + i, true);
if (IS_ERR(fsrc))
return PTR_ERR(fsrc);
- fdst = f2fs_get_new_data_folio(dst_inode, NULL, dst + i,
- true);
- if (IS_ERR(fdst)) {
- f2fs_folio_put(fsrc, true);
- return PTR_ERR(fdst);
+
+ src_off = offset_in_folio(fsrc,
+ (loff_t)(src + i) << PAGE_SHIFT);
+
+ /*
+ * For same-inode operations (collapse/insert), src and
+ * dst may fall within the same large folio. Detect this
+ * to avoid self-deadlock on folio lock.
+ */
+ same_folio = src_inode == dst_inode &&
+ folio_contains(fsrc, dst + i);
+ if (same_folio) {
+ struct dnode_of_data dn;
+
+ /* Reserve block for dst before copying */
+ set_new_dnode(&dn, dst_inode, NULL, NULL, 0);
+ ret = f2fs_reserve_block(&dn, dst + i);
+ if (ret) {
+ f2fs_folio_put(fsrc, true);
+ return ret;
+ }
+ fdst = fsrc;
+ } else {
+ fdst = f2fs_get_new_data_folio(dst_inode, NULL,
+ dst + i, true);
+ if (IS_ERR(fdst)) {
+ f2fs_folio_put(fsrc, true);
+ return PTR_ERR(fdst);
+ }
}
+ dst_off = offset_in_folio(fdst,
+ (loff_t)(dst + i) << PAGE_SHIFT);
f2fs_folio_wait_writeback(fdst, true, true);
-
- memcpy_folio(fdst, 0, fsrc, 0, PAGE_SIZE);
+ memcpy_folio(fdst, dst_off, fsrc, src_off,
+ PAGE_SIZE);
+ if (folio_test_large(fdst)) {
+ if (!f2fs_ffs_find_or_alloc(fdst)) {
+ f2fs_folio_put(fdst, true);
+ if (!same_folio)
+ f2fs_folio_put(fsrc, true);
+ return -ENOMEM;
+ }
+ f2fs_ffs_mark_subrange_uptodate(fdst,
+ dst_off, PAGE_SIZE);
+ f2fs_ffs_mark_subrange_dirty(fdst, dst_off,
+ PAGE_SIZE);
+ }
folio_mark_dirty(fdst);
+ if (same_folio && i_size_read(dst_inode) <
+ ((loff_t)(dst + i + 1) << PAGE_SHIFT))
+ f2fs_i_size_write(dst_inode,
+ ((loff_t)(dst + i + 1) << PAGE_SHIFT));
folio_set_f2fs_gcing(fdst);
f2fs_folio_put(fdst, true);
- f2fs_folio_put(fsrc, true);
+ if (!same_folio)
+ f2fs_folio_put(fsrc, true);
ret = f2fs_truncate_hole(src_inode,
src + i, src + i + 1);
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 14/16] f2fs: handle block cloning within the same large folio
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
With large folios, the source and destination block in __clone_blkaddrs()
can belong to the same folio during same-inode operations such as
collapse range and insert range.
In that case, locking the source folio and then looking up the
destination folio can try to lock the same folio again. It also copies
from and to offset 0, which is only correct for order-0 folios.
Detect the same-inode, same-folio case before looking up the destination
folio. Then in this case,we reserve the destination block explicitly.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/file.c | 61 +++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 53 insertions(+), 8 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 5a8dbe228fb1..cad5329bbfd6 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1602,25 +1602,70 @@ static int __clone_blkaddrs(struct inode *src_inode, struct inode *dst_inode,
f2fs_put_dnode(&dn);
} else {
struct folio *fsrc, *fdst;
+ size_t src_off, dst_off;
+ bool same_folio;
fsrc = f2fs_get_lock_data_folio(src_inode,
src + i, true);
if (IS_ERR(fsrc))
return PTR_ERR(fsrc);
- fdst = f2fs_get_new_data_folio(dst_inode, NULL, dst + i,
- true);
- if (IS_ERR(fdst)) {
- f2fs_folio_put(fsrc, true);
- return PTR_ERR(fdst);
+
+ src_off = offset_in_folio(fsrc,
+ (loff_t)(src + i) << PAGE_SHIFT);
+
+ /*
+ * For same-inode operations (collapse/insert), src and
+ * dst may fall within the same large folio. Detect this
+ * to avoid self-deadlock on folio lock.
+ */
+ same_folio = src_inode == dst_inode &&
+ folio_contains(fsrc, dst + i);
+ if (same_folio) {
+ struct dnode_of_data dn;
+
+ /* Reserve block for dst before copying */
+ set_new_dnode(&dn, dst_inode, NULL, NULL, 0);
+ ret = f2fs_reserve_block(&dn, dst + i);
+ if (ret) {
+ f2fs_folio_put(fsrc, true);
+ return ret;
+ }
+ fdst = fsrc;
+ } else {
+ fdst = f2fs_get_new_data_folio(dst_inode, NULL,
+ dst + i, true);
+ if (IS_ERR(fdst)) {
+ f2fs_folio_put(fsrc, true);
+ return PTR_ERR(fdst);
+ }
}
+ dst_off = offset_in_folio(fdst,
+ (loff_t)(dst + i) << PAGE_SHIFT);
f2fs_folio_wait_writeback(fdst, true, true);
-
- memcpy_folio(fdst, 0, fsrc, 0, PAGE_SIZE);
+ memcpy_folio(fdst, dst_off, fsrc, src_off,
+ PAGE_SIZE);
+ if (folio_test_large(fdst)) {
+ if (!f2fs_ffs_find_or_alloc(fdst)) {
+ f2fs_folio_put(fdst, true);
+ if (!same_folio)
+ f2fs_folio_put(fsrc, true);
+ return -ENOMEM;
+ }
+ f2fs_ffs_mark_subrange_uptodate(fdst,
+ dst_off, PAGE_SIZE);
+ f2fs_ffs_mark_subrange_dirty(fdst, dst_off,
+ PAGE_SIZE);
+ }
folio_mark_dirty(fdst);
+ if (same_folio && i_size_read(dst_inode) <
+ ((loff_t)(dst + i + 1) << PAGE_SHIFT))
+ f2fs_i_size_write(dst_inode,
+ ((loff_t)(dst + i + 1) << PAGE_SHIFT));
folio_set_f2fs_gcing(fdst);
f2fs_folio_put(fdst, true);
- f2fs_folio_put(fsrc, true);
+ if (!same_folio)
+ f2fs_folio_put(fsrc, true);
ret = f2fs_truncate_hole(src_inode,
src + i, src + i + 1);
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 15/16] f2fs: allow large folio support to writeable files
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
Now we make all write path support large folios,
so we open permission to let writeable file set
large folio mapping.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 2 +-
fs/f2fs/f2fs.h | 17 +++++++++++++++++
fs/f2fs/file.c | 16 +---------------
fs/f2fs/inline.c | 6 ++++++
fs/f2fs/inode.c | 4 +---
fs/f2fs/namei.c | 1 +
6 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 45861c31fe76..a476464b856c 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3242,7 +3242,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
int ret = 0;
bool folio_in_bio = false;
- if (!IS_IMMUTABLE(inode) || f2fs_compressed_file(inode)) {
+ if (f2fs_compressed_file(inode)) {
if (folio)
folio_unlock(folio);
return -EOPNOTSUPP;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index ddff43bcb800..1f9bd8e3b526 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -5348,6 +5348,23 @@ static inline bool f2fs_quota_file(struct f2fs_sb_info *sbi, nid_t ino)
return false;
}
+static inline void f2fs_mapping_set_large_folio(struct inode *inode)
+{
+ if (!S_ISREG(inode->i_mode) ||
+ f2fs_compressed_file(inode) ||
+ f2fs_quota_file(F2FS_I_SB(inode), inode->i_ino))
+ return;
+
+ /*
+ * Keep the folio order range at 0 as a transitional step; large
+ * folios will be enabled once the whole write path is audited.
+ */
+ if (IS_IMMUTABLE(inode))
+ mapping_set_folio_min_order(inode->i_mapping, 0);
+ else
+ mapping_set_folio_order_range(inode->i_mapping, 0, 0);
+}
+
static inline bool f2fs_block_unit_discard(struct f2fs_sb_info *sbi)
{
return F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK;
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index cad5329bbfd6..803e2b9900d1 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -163,17 +163,8 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
int err = 0;
vm_fault_t ret;
- /*
- * We only support large folio on the read case.
- * Don't make any dirty pages.
- */
- if (unlikely(IS_IMMUTABLE(inode)) ||
- mapping_large_folio_support(inode->i_mapping)) {
- f2fs_err(sbi, "Not expected: immutable: %d large_folio: %d",
- IS_IMMUTABLE(inode),
- mapping_large_folio_support(inode->i_mapping));
+ if (unlikely(IS_IMMUTABLE(inode)))
return VM_FAULT_SIGBUS;
- }
/* mmap stores bypass the COW inode and would break atomicity */
if (f2fs_is_atomic_file(inode))
@@ -724,9 +715,6 @@ static int f2fs_file_open(struct inode *inode, struct file *filp)
if (!f2fs_is_compress_backend_ready(inode))
return -EOPNOTSUPP;
- if (mapping_large_folio_support(inode->i_mapping) &&
- filp->f_mode & FMODE_WRITE)
- return -EOPNOTSUPP;
err = fsverity_file_open(inode, filp);
if (err)
@@ -1198,8 +1186,6 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
return -EPERM;
if ((attr->ia_valid & ATTR_SIZE)) {
- if (mapping_large_folio_support(inode->i_mapping))
- return -EOPNOTSUPP;
if (IS_DEVICE_ALIASING(inode))
return -EPERM;
if (!f2fs_is_compress_backend_ready(inode))
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index 49905aa08418..0dca6c3d58fb 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -239,6 +239,12 @@ int f2fs_convert_inline_inode(struct inode *inode)
if (IS_ERR(folio))
return PTR_ERR(folio);
+ /*
+ * Inline data is only supported in an order-0 index #0 folio; the
+ * inline write and mmap fault paths never request a larger order.
+ */
+ f2fs_bug_on(sbi, folio_test_large(folio));
+
f2fs_lock_op(sbi, &lc);
ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 9164a2b5d9f0..f5a4dac98ef2 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -599,9 +599,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
inode->i_op = &f2fs_file_inode_operations;
inode->i_fop = &f2fs_file_operations;
inode->i_mapping->a_ops = &f2fs_dblock_aops;
- if (IS_IMMUTABLE(inode) && !f2fs_compressed_file(inode) &&
- !f2fs_quota_file(sbi, inode->i_ino))
- mapping_set_folio_min_order(inode->i_mapping, 0);
+ f2fs_mapping_set_large_folio(inode);
} else if (S_ISDIR(inode->i_mode)) {
inode->i_op = &f2fs_dir_inode_operations;
inode->i_fop = &f2fs_dir_operations;
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 38fcea8b72bf..6a1ff631393c 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -341,6 +341,7 @@ static struct inode *f2fs_new_inode(struct mnt_idmap *idmap,
f2fs_set_inode_flags(inode);
f2fs_init_extent_tree(inode);
+ f2fs_mapping_set_large_folio(inode);
trace_f2fs_new_inode(inode, 0);
return inode;
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 15/16] f2fs: allow large folio support to writeable files
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
Now we make all write path support large folios,
so we open permission to let writeable file set
large folio mapping.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
fs/f2fs/data.c | 2 +-
fs/f2fs/f2fs.h | 17 +++++++++++++++++
fs/f2fs/file.c | 16 +---------------
fs/f2fs/inline.c | 6 ++++++
fs/f2fs/inode.c | 4 +---
fs/f2fs/namei.c | 1 +
6 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 45861c31fe76..a476464b856c 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3242,7 +3242,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
int ret = 0;
bool folio_in_bio = false;
- if (!IS_IMMUTABLE(inode) || f2fs_compressed_file(inode)) {
+ if (f2fs_compressed_file(inode)) {
if (folio)
folio_unlock(folio);
return -EOPNOTSUPP;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index ddff43bcb800..1f9bd8e3b526 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -5348,6 +5348,23 @@ static inline bool f2fs_quota_file(struct f2fs_sb_info *sbi, nid_t ino)
return false;
}
+static inline void f2fs_mapping_set_large_folio(struct inode *inode)
+{
+ if (!S_ISREG(inode->i_mode) ||
+ f2fs_compressed_file(inode) ||
+ f2fs_quota_file(F2FS_I_SB(inode), inode->i_ino))
+ return;
+
+ /*
+ * Keep the folio order range at 0 as a transitional step; large
+ * folios will be enabled once the whole write path is audited.
+ */
+ if (IS_IMMUTABLE(inode))
+ mapping_set_folio_min_order(inode->i_mapping, 0);
+ else
+ mapping_set_folio_order_range(inode->i_mapping, 0, 0);
+}
+
static inline bool f2fs_block_unit_discard(struct f2fs_sb_info *sbi)
{
return F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK;
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index cad5329bbfd6..803e2b9900d1 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -163,17 +163,8 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
int err = 0;
vm_fault_t ret;
- /*
- * We only support large folio on the read case.
- * Don't make any dirty pages.
- */
- if (unlikely(IS_IMMUTABLE(inode)) ||
- mapping_large_folio_support(inode->i_mapping)) {
- f2fs_err(sbi, "Not expected: immutable: %d large_folio: %d",
- IS_IMMUTABLE(inode),
- mapping_large_folio_support(inode->i_mapping));
+ if (unlikely(IS_IMMUTABLE(inode)))
return VM_FAULT_SIGBUS;
- }
/* mmap stores bypass the COW inode and would break atomicity */
if (f2fs_is_atomic_file(inode))
@@ -724,9 +715,6 @@ static int f2fs_file_open(struct inode *inode, struct file *filp)
if (!f2fs_is_compress_backend_ready(inode))
return -EOPNOTSUPP;
- if (mapping_large_folio_support(inode->i_mapping) &&
- filp->f_mode & FMODE_WRITE)
- return -EOPNOTSUPP;
err = fsverity_file_open(inode, filp);
if (err)
@@ -1198,8 +1186,6 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
return -EPERM;
if ((attr->ia_valid & ATTR_SIZE)) {
- if (mapping_large_folio_support(inode->i_mapping))
- return -EOPNOTSUPP;
if (IS_DEVICE_ALIASING(inode))
return -EPERM;
if (!f2fs_is_compress_backend_ready(inode))
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index 49905aa08418..0dca6c3d58fb 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -239,6 +239,12 @@ int f2fs_convert_inline_inode(struct inode *inode)
if (IS_ERR(folio))
return PTR_ERR(folio);
+ /*
+ * Inline data is only supported in an order-0 index #0 folio; the
+ * inline write and mmap fault paths never request a larger order.
+ */
+ f2fs_bug_on(sbi, folio_test_large(folio));
+
f2fs_lock_op(sbi, &lc);
ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 9164a2b5d9f0..f5a4dac98ef2 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -599,9 +599,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
inode->i_op = &f2fs_file_inode_operations;
inode->i_fop = &f2fs_file_operations;
inode->i_mapping->a_ops = &f2fs_dblock_aops;
- if (IS_IMMUTABLE(inode) && !f2fs_compressed_file(inode) &&
- !f2fs_quota_file(sbi, inode->i_ino))
- mapping_set_folio_min_order(inode->i_mapping, 0);
+ f2fs_mapping_set_large_folio(inode);
} else if (S_ISDIR(inode->i_mode)) {
inode->i_op = &f2fs_dir_inode_operations;
inode->i_fop = &f2fs_dir_operations;
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 38fcea8b72bf..6a1ff631393c 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -341,6 +341,7 @@ static struct inode *f2fs_new_inode(struct mnt_idmap *idmap,
f2fs_set_inode_flags(inode);
f2fs_init_extent_tree(inode);
+ f2fs_mapping_set_large_folio(inode);
trace_f2fs_new_inode(inode, 0);
return inode;
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread
* [f2fs-dev] [PATCH v5 16/16] f2fs: make compressed files compatible with large folio
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 6:44 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Juan Yescas, Daeho Jeong, Pengfei Li, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
The compression flag is the hint indicates that the inode can be
compressed, when the inode is using large folio, we expected it keeps
using the large folio read/write paths and its data stays uncompressed
on disk until the inode is evicted and re-read
Let f2fs_write_begin() skip the compression overwrite preparation for
such inodes and remove the compressed-file gate in
f2fs_read_data_large_folio() so the data is simply read/written as
regular blocks.
For the same reason, reject F2FS_IOC_COMPRESS_FILE with -EOPNOTSUPP
once the inode mapping is switched to large folios.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
Documentation/filesystems/f2fs.rst | 10 ++++++++++
fs/f2fs/compress.c | 2 ++
fs/f2fs/data.c | 9 ++-------
fs/f2fs/file.c | 7 +++++++
4 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst
index 771216f45207..b4f436ffd9ac 100644
--- a/Documentation/filesystems/f2fs.rst
+++ b/Documentation/filesystems/f2fs.rst
@@ -941,6 +941,16 @@ Compression implementation
reserved via ioctl(F2FS_IOC_RESERVE_COMPRESS_BLOCKS) or the file size is
truncated to zero.
+- Compression and large folios are not effective at the same time on a file:
+ a compressed inode does not use large folios, while an inode which is
+ using large folios keeps its data uncompressed on disk. If the compression
+ flag is set on an inode that is already using large folios, the flag works
+ as a hint until the inode is evicted: the inode keeps using the large folio
+ read/write paths, f2fs_write_begin() skips the compression overwrite
+ preparation, and ioctl(F2FS_IOC_COMPRESS_FILE) fails with -EOPNOTSUPP.
+ Once the inode is evicted and read back, it uses order-0 folios again and
+ compression is applied as usual.
+
Compress metadata layout::
[Dnode Structure]
diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 162bd8ef822a..721b01dd0d24 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -78,6 +78,8 @@ bool f2fs_is_compressed_page(struct folio *folio)
return false;
if (folio_test_f2fs_nonpointer(folio))
return false;
+ if (f2fs_folio_has_ffs(folio))
+ return false;
f2fs_bug_on(F2FS_F_SB(folio),
*((u32 *)folio->private) != F2FS_COMPRESSED_PAGE_MAGIC);
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index a476464b856c..f6be297f9f59 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3242,12 +3242,6 @@ static int f2fs_read_data_large_folio(struct inode *inode,
int ret = 0;
bool folio_in_bio = false;
- if (f2fs_compressed_file(inode)) {
- if (folio)
- folio_unlock(folio);
- return -EOPNOTSUPP;
- }
-
map.m_seg_type = NO_CHECK_TYPE;
if (rac)
@@ -5245,7 +5239,8 @@ static int f2fs_write_begin(const struct kiocb *iocb,
}
#ifdef CONFIG_F2FS_FS_COMPRESSION
- if (f2fs_compressed_file(inode)) {
+ if (f2fs_compressed_file(inode) &&
+ !mapping_large_folio_support(inode->i_mapping)) {
int ret;
struct page *page;
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 803e2b9900d1..9282b16fc222 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -5025,6 +5025,13 @@ static int f2fs_ioc_compress_file(struct file *filp)
if (!(filp->f_mode & FMODE_WRITE))
return -EBADF;
+ /*
+ * The mapping is already using large folios, where the data is kept
+ * uncompressed, so refuse to start compressing the file.
+ */
+ if (mapping_large_folio_support(inode->i_mapping))
+ return -EOPNOTSUPP;
+
f2fs_balance_fs(sbi, true);
ret = mnt_want_write_file(filp);
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 52+ messages in thread* [PATCH v5 16/16] f2fs: make compressed files compatible with large folio
@ 2026-10-14 6:44 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-14 6:44 UTC (permalink / raw)
To: linux-f2fs-devel, Jaegeuk Kim, Chao Yu
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, Dev Jain,
David Hildenbrand, linux-kernel, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, Pengfei Li, Ryan Roberts
The compression flag is the hint indicates that the inode can be
compressed, when the inode is using large folio, we expected it keeps
using the large folio read/write paths and its data stays uncompressed
on disk until the inode is evicted and re-read
Let f2fs_write_begin() skip the compression overwrite preparation for
such inodes and remove the compressed-file gate in
f2fs_read_data_large_folio() so the data is simply read/written as
regular blocks.
For the same reason, reject F2FS_IOC_COMPRESS_FILE with -EOPNOTSUPP
once the inode mapping is switched to large folios.
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xiaomi.com>
---
Documentation/filesystems/f2fs.rst | 10 ++++++++++
fs/f2fs/compress.c | 2 ++
fs/f2fs/data.c | 9 ++-------
fs/f2fs/file.c | 7 +++++++
4 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst
index 771216f45207..b4f436ffd9ac 100644
--- a/Documentation/filesystems/f2fs.rst
+++ b/Documentation/filesystems/f2fs.rst
@@ -941,6 +941,16 @@ Compression implementation
reserved via ioctl(F2FS_IOC_RESERVE_COMPRESS_BLOCKS) or the file size is
truncated to zero.
+- Compression and large folios are not effective at the same time on a file:
+ a compressed inode does not use large folios, while an inode which is
+ using large folios keeps its data uncompressed on disk. If the compression
+ flag is set on an inode that is already using large folios, the flag works
+ as a hint until the inode is evicted: the inode keeps using the large folio
+ read/write paths, f2fs_write_begin() skips the compression overwrite
+ preparation, and ioctl(F2FS_IOC_COMPRESS_FILE) fails with -EOPNOTSUPP.
+ Once the inode is evicted and read back, it uses order-0 folios again and
+ compression is applied as usual.
+
Compress metadata layout::
[Dnode Structure]
diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 162bd8ef822a..721b01dd0d24 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -78,6 +78,8 @@ bool f2fs_is_compressed_page(struct folio *folio)
return false;
if (folio_test_f2fs_nonpointer(folio))
return false;
+ if (f2fs_folio_has_ffs(folio))
+ return false;
f2fs_bug_on(F2FS_F_SB(folio),
*((u32 *)folio->private) != F2FS_COMPRESSED_PAGE_MAGIC);
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index a476464b856c..f6be297f9f59 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3242,12 +3242,6 @@ static int f2fs_read_data_large_folio(struct inode *inode,
int ret = 0;
bool folio_in_bio = false;
- if (f2fs_compressed_file(inode)) {
- if (folio)
- folio_unlock(folio);
- return -EOPNOTSUPP;
- }
-
map.m_seg_type = NO_CHECK_TYPE;
if (rac)
@@ -5245,7 +5239,8 @@ static int f2fs_write_begin(const struct kiocb *iocb,
}
#ifdef CONFIG_F2FS_FS_COMPRESSION
- if (f2fs_compressed_file(inode)) {
+ if (f2fs_compressed_file(inode) &&
+ !mapping_large_folio_support(inode->i_mapping)) {
int ret;
struct page *page;
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 803e2b9900d1..9282b16fc222 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -5025,6 +5025,13 @@ static int f2fs_ioc_compress_file(struct file *filp)
if (!(filp->f_mode & FMODE_WRITE))
return -EBADF;
+ /*
+ * The mapping is already using large folios, where the data is kept
+ * uncompressed, so refuse to start compressing the file.
+ */
+ if (mapping_large_folio_support(inode->i_mapping))
+ return -EOPNOTSUPP;
+
f2fs_balance_fs(sbi, true);
ret = mnt_want_write_file(filp);
--
2.43.0
^ permalink raw reply related [flat|nested] 52+ messages in thread
* Re: [f2fs-dev] [PATCH v5 00/16] f2fs: support & optimize large folios for writable files
2026-10-14 6:44 ` [f2fs-dev] " Nanzhe Zhao
@ 2026-10-14 23:23 ` Jaegeuk Kim
-1 siblings, 0 replies; 52+ messages in thread
From: Jaegeuk Kim via Linux-f2fs-devel @ 2026-10-14 23:23 UTC (permalink / raw)
To: Nanzhe Zhao
Cc: Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong, linux-kernel,
Dev Jain, David Hildenbrand, Pengfei Li, Bo Zhang, Kalesh Singh,
Nanzhe Zhao, linux-f2fs-devel, Ryan Roberts
Hi Nanzhe,
Could you please check IO submission path for Zoned block device?
I hit this.
[ 93.100225] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.100420] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.100551] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.100948] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.101432] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.101762] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.101907] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.102564] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.103054] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.103447] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.103667] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.104294] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.104373] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.104449] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105220] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105253] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105532] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105575] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105606] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105985] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.106192] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.106692] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.106799] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107015] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107090] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107113] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.107268] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107288] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.107499] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107511] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.107707] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107724] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.107770] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.107929] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107941] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.108040] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.108050] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.108166] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.108179] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.108322] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.108341] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.108582] sd 0:0:0:4: [sde] tag#31 UNKNOWN(0x2003) Result: hostbyte=0x00 driverbyte=DRIVER_OK cmd_age=0s
[ 93.108588] sd 0:0:0:4: [sde] tag#31 Sense Key : 0x5 [current]
[ 93.108595] sd 0:0:0:4: [sde] tag#31 ASC=0x21 ASCQ=0x4
[ 93.108605] sd 0:0:0:4: [sde] tag#31 CDB: opcode=0x8a 8a 00 00 00 00 00 01 ee d9 4e 00 00 00 01 03 00
[ 93.108607] critical target error, dev sde, sector 259443312 op 0x1:(WRITE) flags 0x800 phys_seg 1 prio class 0
[ 93.108612] sde: zone 2639: Aborting plugged BIOs
[ 93.108626] CPU: 1 UID: 1000 PID: 1831 Comm: CachedAppOptimi Tainted: G W O 6.12.81-android16-6-maybe-dirty-4k #1 de5ea2c0fc3867082493fabcae9896176e2e435e
[ 93.108630] Tainted: [W]=WARN, [O]=OOT_MODULE
[ 93.108631] Hardware name: KODIAK DVT 1.0 based on MALIBU (DT)
[ 93.108632] Call trace:
[ 93.108633] dump_backtrace+0xec/0x128
[ 93.108641] show_stack+0x18/0x28
[ 93.108645] dump_stack_lvl+0x40/0xb8
[ 93.108649] dump_stack+0x18/0x28
[ 93.108652] f2fs_stop_checkpoint+0x1f0/0x2d8
[ 93.108654] f2fs_write_end_bio+0x50/0x694
[ 93.108657] f2fs_write_end_io+0x80/0x94
[ 93.108660] bio_endio+0x114/0x224
[ 93.108662] __dm_io_complete+0xf4/0x278
[ 93.108665] clone_endio+0xc0/0x26c
[ 93.108669] bio_endio+0x114/0x224
[ 93.108671] blk_zone_write_plug_bio_endio+0x104/0x334
[ 93.108674] bio_endio+0x160/0x224
[ 93.108676] blk_update_request+0x17c/0x218
On 10/14, Nanzhe Zhao wrote:
> This series supports large folios for most readable/writable files
> in buffered I/O paths, including normal files, block-layer encrypted
> files, and atomic files except for inline-data files, compressed files,
> and quota files.
>
> It also extends f2fs_folio_state to coexist with f2fs page-private
> flags and to handle large folio write path and partial truncate of
> large folios correctly. A valid large folio always carries a
> f2fs_folio_state at its folio->private in the current implementation.
>
> Benchmark details can be found in the RFC v2 cover letter [1].
>
> Changes in v5:
> - Rebased onto the f2fs dev-test branch (d1685c24b6c3).
> - Dropped the two prerequisite bug fixes, which are now merged:
> c04f209773ec ("f2fs: read i_size once in f2fs_vm_page_mkwrite")
> b3c984358925 ("f2fs: remove mappedtodisk flag usage in mmap write path")
> - Link to v4: [2]
>
> Many thanks to Chao and Daeho for your extensive reviews and valuable
> suggestions!
>
> [1] https://lore.kernel.org/r/20260622160830.324455-1-zhaonanzhe@xiaomi.com
> [2] https://lore.kernel.org/linux-f2fs-devel/20261013115621.968742-1-nzzhao.sigma@gmail.com/
>
> Nanzhe Zhao (16):
> f2fs: extend folio state for large folio write path
> f2fs: carry subpage offset and count in write IO
> f2fs: support regular file buffered writes on large folios
> f2fs: support atomic file large folios buffered write
> f2fs: support large folio writeback
> f2fs: account large folio dirty data at block granularity
> f2fs: prepare mmap write faults for large folios
> f2fs: make GC migration large-folio aware
> f2fs: optimize small block size large folio read
> f2fs: support partial uptodate large folio read
> f2fs: handle partial truncate of large folio dirty subpages
> f2fs: wait for folio writeback before ffs_detach_free
> f2fs: fix zeroing paths for large folios
> f2fs: handle block cloning within the same large folio
> f2fs: allow large folio support to writeable files
> f2fs: make compressed files compatible with large folio
>
> Documentation/filesystems/f2fs.rst | 10 +
> fs/f2fs/checkpoint.c | 40 +-
> fs/f2fs/compress.c | 7 +-
> fs/f2fs/data.c | 1467 +++++++++++++++++++++++++---
> fs/f2fs/dir.c | 2 +-
> fs/f2fs/f2fs.h | 170 +++-
> fs/f2fs/file.c | 226 +++--
> fs/f2fs/gc.c | 38 +-
> fs/f2fs/inline.c | 9 +-
> fs/f2fs/inode.c | 4 +-
> fs/f2fs/namei.c | 1 +
> fs/f2fs/node.c | 2 +-
> fs/f2fs/segment.c | 5 +-
> 13 files changed, 1716 insertions(+), 265 deletions(-)
>
> --
> 2.43.0
>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 00/16] f2fs: support & optimize large folios for writable files
@ 2026-10-14 23:23 ` Jaegeuk Kim
0 siblings, 0 replies; 52+ messages in thread
From: Jaegeuk Kim @ 2026-10-14 23:23 UTC (permalink / raw)
To: Nanzhe Zhao
Cc: linux-f2fs-devel, Chao Yu, Barry Song, Juan Yescas, Daeho Jeong,
Pengfei Li, Dev Jain, David Hildenbrand, linux-kernel, Bo Zhang,
Kalesh Singh, Nanzhe Zhao, Nanzhe Zhao, Ryan Roberts
Hi Nanzhe,
Could you please check IO submission path for Zoned block device?
I hit this.
[ 93.100225] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.100420] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.100551] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.100948] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.101432] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.101762] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.101907] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.102564] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.103054] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.103447] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.103667] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.104294] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.104373] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.104449] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105220] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105253] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105532] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105575] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105606] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.105985] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.106192] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.106692] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.106799] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107015] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107090] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107113] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.107268] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107288] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.107499] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107511] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.107707] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107724] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.107770] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.107929] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.107941] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.108040] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.108050] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.108166] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.108179] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.108322] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
[ 93.108341] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
[ 93.108582] sd 0:0:0:4: [sde] tag#31 UNKNOWN(0x2003) Result: hostbyte=0x00 driverbyte=DRIVER_OK cmd_age=0s
[ 93.108588] sd 0:0:0:4: [sde] tag#31 Sense Key : 0x5 [current]
[ 93.108595] sd 0:0:0:4: [sde] tag#31 ASC=0x21 ASCQ=0x4
[ 93.108605] sd 0:0:0:4: [sde] tag#31 CDB: opcode=0x8a 8a 00 00 00 00 00 01 ee d9 4e 00 00 00 01 03 00
[ 93.108607] critical target error, dev sde, sector 259443312 op 0x1:(WRITE) flags 0x800 phys_seg 1 prio class 0
[ 93.108612] sde: zone 2639: Aborting plugged BIOs
[ 93.108626] CPU: 1 UID: 1000 PID: 1831 Comm: CachedAppOptimi Tainted: G W O 6.12.81-android16-6-maybe-dirty-4k #1 de5ea2c0fc3867082493fabcae9896176e2e435e
[ 93.108630] Tainted: [W]=WARN, [O]=OOT_MODULE
[ 93.108631] Hardware name: KODIAK DVT 1.0 based on MALIBU (DT)
[ 93.108632] Call trace:
[ 93.108633] dump_backtrace+0xec/0x128
[ 93.108641] show_stack+0x18/0x28
[ 93.108645] dump_stack_lvl+0x40/0xb8
[ 93.108649] dump_stack+0x18/0x28
[ 93.108652] f2fs_stop_checkpoint+0x1f0/0x2d8
[ 93.108654] f2fs_write_end_bio+0x50/0x694
[ 93.108657] f2fs_write_end_io+0x80/0x94
[ 93.108660] bio_endio+0x114/0x224
[ 93.108662] __dm_io_complete+0xf4/0x278
[ 93.108665] clone_endio+0xc0/0x26c
[ 93.108669] bio_endio+0x114/0x224
[ 93.108671] blk_zone_write_plug_bio_endio+0x104/0x334
[ 93.108674] bio_endio+0x160/0x224
[ 93.108676] blk_update_request+0x17c/0x218
On 10/14, Nanzhe Zhao wrote:
> This series supports large folios for most readable/writable files
> in buffered I/O paths, including normal files, block-layer encrypted
> files, and atomic files except for inline-data files, compressed files,
> and quota files.
>
> It also extends f2fs_folio_state to coexist with f2fs page-private
> flags and to handle large folio write path and partial truncate of
> large folios correctly. A valid large folio always carries a
> f2fs_folio_state at its folio->private in the current implementation.
>
> Benchmark details can be found in the RFC v2 cover letter [1].
>
> Changes in v5:
> - Rebased onto the f2fs dev-test branch (d1685c24b6c3).
> - Dropped the two prerequisite bug fixes, which are now merged:
> c04f209773ec ("f2fs: read i_size once in f2fs_vm_page_mkwrite")
> b3c984358925 ("f2fs: remove mappedtodisk flag usage in mmap write path")
> - Link to v4: [2]
>
> Many thanks to Chao and Daeho for your extensive reviews and valuable
> suggestions!
>
> [1] https://lore.kernel.org/r/20260622160830.324455-1-zhaonanzhe@xiaomi.com
> [2] https://lore.kernel.org/linux-f2fs-devel/20261013115621.968742-1-nzzhao.sigma@gmail.com/
>
> Nanzhe Zhao (16):
> f2fs: extend folio state for large folio write path
> f2fs: carry subpage offset and count in write IO
> f2fs: support regular file buffered writes on large folios
> f2fs: support atomic file large folios buffered write
> f2fs: support large folio writeback
> f2fs: account large folio dirty data at block granularity
> f2fs: prepare mmap write faults for large folios
> f2fs: make GC migration large-folio aware
> f2fs: optimize small block size large folio read
> f2fs: support partial uptodate large folio read
> f2fs: handle partial truncate of large folio dirty subpages
> f2fs: wait for folio writeback before ffs_detach_free
> f2fs: fix zeroing paths for large folios
> f2fs: handle block cloning within the same large folio
> f2fs: allow large folio support to writeable files
> f2fs: make compressed files compatible with large folio
>
> Documentation/filesystems/f2fs.rst | 10 +
> fs/f2fs/checkpoint.c | 40 +-
> fs/f2fs/compress.c | 7 +-
> fs/f2fs/data.c | 1467 +++++++++++++++++++++++++---
> fs/f2fs/dir.c | 2 +-
> fs/f2fs/f2fs.h | 170 +++-
> fs/f2fs/file.c | 226 +++--
> fs/f2fs/gc.c | 38 +-
> fs/f2fs/inline.c | 9 +-
> fs/f2fs/inode.c | 4 +-
> fs/f2fs/namei.c | 1 +
> fs/f2fs/node.c | 2 +-
> fs/f2fs/segment.c | 5 +-
> 13 files changed, 1716 insertions(+), 265 deletions(-)
>
> --
> 2.43.0
>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 00/16] f2fs: support & optimize large folios for writable files
2026-10-14 23:23 ` Jaegeuk Kim
@ 2026-10-15 2:13 ` Jaegeuk Kim via Linux-f2fs-devel
-1 siblings, 0 replies; 52+ messages in thread
From: Jaegeuk Kim @ 2026-10-15 2:13 UTC (permalink / raw)
To: Nanzhe Zhao, Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong,
linux-kernel, Dev Jain, David Hildenbrand, Pengfei Li, Bo Zhang,
Kalesh Singh, Nanzhe Zhao, linux-f2fs-devel, Ryan Roberts
Ok, this comes when applying "f2fs: carry subpage offset and count in write IO".
On 10/14, Jaegeuk Kim via Linux-f2fs-devel wrote:
> Hi Nanzhe,
>
> Could you please check IO submission path for Zoned block device?
> I hit this.
>
> [ 93.100225] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.100420] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.100551] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.100948] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.101432] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.101762] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.101907] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.102564] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.103054] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.103447] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.103667] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.104294] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.104373] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.104449] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105220] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105253] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105532] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105575] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105606] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105985] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.106192] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.106692] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.106799] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107015] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107090] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107113] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.107268] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107288] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.107499] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107511] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.107707] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107724] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.107770] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.107929] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107941] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.108040] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.108050] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.108166] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.108179] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.108322] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.108341] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.108582] sd 0:0:0:4: [sde] tag#31 UNKNOWN(0x2003) Result: hostbyte=0x00 driverbyte=DRIVER_OK cmd_age=0s
> [ 93.108588] sd 0:0:0:4: [sde] tag#31 Sense Key : 0x5 [current]
> [ 93.108595] sd 0:0:0:4: [sde] tag#31 ASC=0x21 ASCQ=0x4
> [ 93.108605] sd 0:0:0:4: [sde] tag#31 CDB: opcode=0x8a 8a 00 00 00 00 00 01 ee d9 4e 00 00 00 01 03 00
> [ 93.108607] critical target error, dev sde, sector 259443312 op 0x1:(WRITE) flags 0x800 phys_seg 1 prio class 0
> [ 93.108612] sde: zone 2639: Aborting plugged BIOs
> [ 93.108626] CPU: 1 UID: 1000 PID: 1831 Comm: CachedAppOptimi Tainted: G W O 6.12.81-android16-6-maybe-dirty-4k #1 de5ea2c0fc3867082493fabcae9896176e2e435e
> [ 93.108630] Tainted: [W]=WARN, [O]=OOT_MODULE
> [ 93.108631] Hardware name: KODIAK DVT 1.0 based on MALIBU (DT)
> [ 93.108632] Call trace:
> [ 93.108633] dump_backtrace+0xec/0x128
> [ 93.108641] show_stack+0x18/0x28
> [ 93.108645] dump_stack_lvl+0x40/0xb8
> [ 93.108649] dump_stack+0x18/0x28
> [ 93.108652] f2fs_stop_checkpoint+0x1f0/0x2d8
> [ 93.108654] f2fs_write_end_bio+0x50/0x694
> [ 93.108657] f2fs_write_end_io+0x80/0x94
> [ 93.108660] bio_endio+0x114/0x224
> [ 93.108662] __dm_io_complete+0xf4/0x278
> [ 93.108665] clone_endio+0xc0/0x26c
> [ 93.108669] bio_endio+0x114/0x224
> [ 93.108671] blk_zone_write_plug_bio_endio+0x104/0x334
> [ 93.108674] bio_endio+0x160/0x224
> [ 93.108676] blk_update_request+0x17c/0x218
>
> On 10/14, Nanzhe Zhao wrote:
> > This series supports large folios for most readable/writable files
> > in buffered I/O paths, including normal files, block-layer encrypted
> > files, and atomic files except for inline-data files, compressed files,
> > and quota files.
> >
> > It also extends f2fs_folio_state to coexist with f2fs page-private
> > flags and to handle large folio write path and partial truncate of
> > large folios correctly. A valid large folio always carries a
> > f2fs_folio_state at its folio->private in the current implementation.
> >
> > Benchmark details can be found in the RFC v2 cover letter [1].
> >
> > Changes in v5:
> > - Rebased onto the f2fs dev-test branch (d1685c24b6c3).
> > - Dropped the two prerequisite bug fixes, which are now merged:
> > c04f209773ec ("f2fs: read i_size once in f2fs_vm_page_mkwrite")
> > b3c984358925 ("f2fs: remove mappedtodisk flag usage in mmap write path")
> > - Link to v4: [2]
> >
> > Many thanks to Chao and Daeho for your extensive reviews and valuable
> > suggestions!
> >
> > [1] https://lore.kernel.org/r/20260622160830.324455-1-zhaonanzhe@xiaomi.com
> > [2] https://lore.kernel.org/linux-f2fs-devel/20261013115621.968742-1-nzzhao.sigma@gmail.com/
> >
> > Nanzhe Zhao (16):
> > f2fs: extend folio state for large folio write path
> > f2fs: carry subpage offset and count in write IO
> > f2fs: support regular file buffered writes on large folios
> > f2fs: support atomic file large folios buffered write
> > f2fs: support large folio writeback
> > f2fs: account large folio dirty data at block granularity
> > f2fs: prepare mmap write faults for large folios
> > f2fs: make GC migration large-folio aware
> > f2fs: optimize small block size large folio read
> > f2fs: support partial uptodate large folio read
> > f2fs: handle partial truncate of large folio dirty subpages
> > f2fs: wait for folio writeback before ffs_detach_free
> > f2fs: fix zeroing paths for large folios
> > f2fs: handle block cloning within the same large folio
> > f2fs: allow large folio support to writeable files
> > f2fs: make compressed files compatible with large folio
> >
> > Documentation/filesystems/f2fs.rst | 10 +
> > fs/f2fs/checkpoint.c | 40 +-
> > fs/f2fs/compress.c | 7 +-
> > fs/f2fs/data.c | 1467 +++++++++++++++++++++++++---
> > fs/f2fs/dir.c | 2 +-
> > fs/f2fs/f2fs.h | 170 +++-
> > fs/f2fs/file.c | 226 +++--
> > fs/f2fs/gc.c | 38 +-
> > fs/f2fs/inline.c | 9 +-
> > fs/f2fs/inode.c | 4 +-
> > fs/f2fs/namei.c | 1 +
> > fs/f2fs/node.c | 2 +-
> > fs/f2fs/segment.c | 5 +-
> > 13 files changed, 1716 insertions(+), 265 deletions(-)
> >
> > --
> > 2.43.0
> >
> >
> >
> > _______________________________________________
> > Linux-f2fs-devel mailing list
> > Linux-f2fs-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 00/16] f2fs: support & optimize large folios for writable files
@ 2026-10-15 2:13 ` Jaegeuk Kim via Linux-f2fs-devel
0 siblings, 0 replies; 52+ messages in thread
From: Jaegeuk Kim via Linux-f2fs-devel @ 2026-10-15 2:13 UTC (permalink / raw)
To: Nanzhe Zhao, Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong,
linux-kernel, Dev Jain, David Hildenbrand, Pengfei Li, Bo Zhang,
Kalesh Singh, Nanzhe Zhao, linux-f2fs-devel, Ryan Roberts
Ok, this comes when applying "f2fs: carry subpage offset and count in write IO".
On 10/14, Jaegeuk Kim via Linux-f2fs-devel wrote:
> Hi Nanzhe,
>
> Could you please check IO submission path for Zoned block device?
> I hit this.
>
> [ 93.100225] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.100420] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.100551] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.100948] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.101432] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.101762] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.101907] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.102564] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.103054] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.103447] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.103667] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.104294] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.104373] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.104449] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105220] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105253] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105532] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105575] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105606] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.105985] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.106192] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.106692] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.106799] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107015] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107090] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107113] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.107268] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107288] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.107499] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107511] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.107707] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107724] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.107770] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.107929] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.107941] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.108040] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.108050] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.108166] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.108179] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.108322] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
> [ 93.108341] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
> [ 93.108582] sd 0:0:0:4: [sde] tag#31 UNKNOWN(0x2003) Result: hostbyte=0x00 driverbyte=DRIVER_OK cmd_age=0s
> [ 93.108588] sd 0:0:0:4: [sde] tag#31 Sense Key : 0x5 [current]
> [ 93.108595] sd 0:0:0:4: [sde] tag#31 ASC=0x21 ASCQ=0x4
> [ 93.108605] sd 0:0:0:4: [sde] tag#31 CDB: opcode=0x8a 8a 00 00 00 00 00 01 ee d9 4e 00 00 00 01 03 00
> [ 93.108607] critical target error, dev sde, sector 259443312 op 0x1:(WRITE) flags 0x800 phys_seg 1 prio class 0
> [ 93.108612] sde: zone 2639: Aborting plugged BIOs
> [ 93.108626] CPU: 1 UID: 1000 PID: 1831 Comm: CachedAppOptimi Tainted: G W O 6.12.81-android16-6-maybe-dirty-4k #1 de5ea2c0fc3867082493fabcae9896176e2e435e
> [ 93.108630] Tainted: [W]=WARN, [O]=OOT_MODULE
> [ 93.108631] Hardware name: KODIAK DVT 1.0 based on MALIBU (DT)
> [ 93.108632] Call trace:
> [ 93.108633] dump_backtrace+0xec/0x128
> [ 93.108641] show_stack+0x18/0x28
> [ 93.108645] dump_stack_lvl+0x40/0xb8
> [ 93.108649] dump_stack+0x18/0x28
> [ 93.108652] f2fs_stop_checkpoint+0x1f0/0x2d8
> [ 93.108654] f2fs_write_end_bio+0x50/0x694
> [ 93.108657] f2fs_write_end_io+0x80/0x94
> [ 93.108660] bio_endio+0x114/0x224
> [ 93.108662] __dm_io_complete+0xf4/0x278
> [ 93.108665] clone_endio+0xc0/0x26c
> [ 93.108669] bio_endio+0x114/0x224
> [ 93.108671] blk_zone_write_plug_bio_endio+0x104/0x334
> [ 93.108674] bio_endio+0x160/0x224
> [ 93.108676] blk_update_request+0x17c/0x218
>
> On 10/14, Nanzhe Zhao wrote:
> > This series supports large folios for most readable/writable files
> > in buffered I/O paths, including normal files, block-layer encrypted
> > files, and atomic files except for inline-data files, compressed files,
> > and quota files.
> >
> > It also extends f2fs_folio_state to coexist with f2fs page-private
> > flags and to handle large folio write path and partial truncate of
> > large folios correctly. A valid large folio always carries a
> > f2fs_folio_state at its folio->private in the current implementation.
> >
> > Benchmark details can be found in the RFC v2 cover letter [1].
> >
> > Changes in v5:
> > - Rebased onto the f2fs dev-test branch (d1685c24b6c3).
> > - Dropped the two prerequisite bug fixes, which are now merged:
> > c04f209773ec ("f2fs: read i_size once in f2fs_vm_page_mkwrite")
> > b3c984358925 ("f2fs: remove mappedtodisk flag usage in mmap write path")
> > - Link to v4: [2]
> >
> > Many thanks to Chao and Daeho for your extensive reviews and valuable
> > suggestions!
> >
> > [1] https://lore.kernel.org/r/20260622160830.324455-1-zhaonanzhe@xiaomi.com
> > [2] https://lore.kernel.org/linux-f2fs-devel/20261013115621.968742-1-nzzhao.sigma@gmail.com/
> >
> > Nanzhe Zhao (16):
> > f2fs: extend folio state for large folio write path
> > f2fs: carry subpage offset and count in write IO
> > f2fs: support regular file buffered writes on large folios
> > f2fs: support atomic file large folios buffered write
> > f2fs: support large folio writeback
> > f2fs: account large folio dirty data at block granularity
> > f2fs: prepare mmap write faults for large folios
> > f2fs: make GC migration large-folio aware
> > f2fs: optimize small block size large folio read
> > f2fs: support partial uptodate large folio read
> > f2fs: handle partial truncate of large folio dirty subpages
> > f2fs: wait for folio writeback before ffs_detach_free
> > f2fs: fix zeroing paths for large folios
> > f2fs: handle block cloning within the same large folio
> > f2fs: allow large folio support to writeable files
> > f2fs: make compressed files compatible with large folio
> >
> > Documentation/filesystems/f2fs.rst | 10 +
> > fs/f2fs/checkpoint.c | 40 +-
> > fs/f2fs/compress.c | 7 +-
> > fs/f2fs/data.c | 1467 +++++++++++++++++++++++++---
> > fs/f2fs/dir.c | 2 +-
> > fs/f2fs/f2fs.h | 170 +++-
> > fs/f2fs/file.c | 226 +++--
> > fs/f2fs/gc.c | 38 +-
> > fs/f2fs/inline.c | 9 +-
> > fs/f2fs/inode.c | 4 +-
> > fs/f2fs/namei.c | 1 +
> > fs/f2fs/node.c | 2 +-
> > fs/f2fs/segment.c | 5 +-
> > 13 files changed, 1716 insertions(+), 265 deletions(-)
> >
> > --
> > 2.43.0
> >
> >
> >
> > _______________________________________________
> > Linux-f2fs-devel mailing list
> > Linux-f2fs-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 00/16] f2fs: support & optimize large folios for writable files
2026-10-15 2:13 ` Jaegeuk Kim via Linux-f2fs-devel
@ 2026-10-15 2:36 ` Chao Yu via Linux-f2fs-devel
-1 siblings, 0 replies; 52+ messages in thread
From: Chao Yu @ 2026-10-15 2:36 UTC (permalink / raw)
To: Jaegeuk Kim, Nanzhe Zhao, Barry Song, Nanzhe Zhao, Juan Yescas,
Daeho Jeong, linux-kernel, Dev Jain, David Hildenbrand,
Pengfei Li, Bo Zhang, Kalesh Singh, Nanzhe Zhao, linux-f2fs-devel,
Ryan Roberts
Cc: chao
Nanzhe,
It needs to set .folio_blkcnt = 1 in move_data_page()
in "f2fs: carry subpage offset and count in write IO" rather than
in "f2fs: make GC migration large-folio aware"
On 10/15/26 10:13, Jaegeuk Kim via Linux-f2fs-devel wrote:
> Ok, this comes when applying "f2fs: carry subpage offset and count in write IO".
>
> On 10/14, Jaegeuk Kim via Linux-f2fs-devel wrote:
>> Hi Nanzhe,
>>
>> Could you please check IO submission path for Zoned block device?
>> I hit this.
>>
>> [ 93.100225] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100420] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100551] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100948] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101432] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101762] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101907] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.102564] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103054] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103447] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103667] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104294] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104373] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104449] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105220] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105253] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105532] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105575] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105606] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105985] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.106192] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.106692] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.106799] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107015] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107090] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107113] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.107268] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107288] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.107499] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107511] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.107707] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107724] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.107770] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.107929] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107941] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.108040] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.108050] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.108166] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.108179] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.108322] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.108341] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.108582] sd 0:0:0:4: [sde] tag#31 UNKNOWN(0x2003) Result: hostbyte=0x00 driverbyte=DRIVER_OK cmd_age=0s
>> [ 93.108588] sd 0:0:0:4: [sde] tag#31 Sense Key : 0x5 [current]
>> [ 93.108595] sd 0:0:0:4: [sde] tag#31 ASC=0x21 ASCQ=0x4
>> [ 93.108605] sd 0:0:0:4: [sde] tag#31 CDB: opcode=0x8a 8a 00 00 00 00 00 01 ee d9 4e 00 00 00 01 03 00
>> [ 93.108607] critical target error, dev sde, sector 259443312 op 0x1:(WRITE) flags 0x800 phys_seg 1 prio class 0
>> [ 93.108612] sde: zone 2639: Aborting plugged BIOs
>> [ 93.108626] CPU: 1 UID: 1000 PID: 1831 Comm: CachedAppOptimi Tainted: G W O 6.12.81-android16-6-maybe-dirty-4k #1 de5ea2c0fc3867082493fabcae9896176e2e435e
>> [ 93.108630] Tainted: [W]=WARN, [O]=OOT_MODULE
>> [ 93.108631] Hardware name: KODIAK DVT 1.0 based on MALIBU (DT)
>> [ 93.108632] Call trace:
>> [ 93.108633] dump_backtrace+0xec/0x128
>> [ 93.108641] show_stack+0x18/0x28
>> [ 93.108645] dump_stack_lvl+0x40/0xb8
>> [ 93.108649] dump_stack+0x18/0x28
>> [ 93.108652] f2fs_stop_checkpoint+0x1f0/0x2d8
>> [ 93.108654] f2fs_write_end_bio+0x50/0x694
>> [ 93.108657] f2fs_write_end_io+0x80/0x94
>> [ 93.108660] bio_endio+0x114/0x224
>> [ 93.108662] __dm_io_complete+0xf4/0x278
>> [ 93.108665] clone_endio+0xc0/0x26c
>> [ 93.108669] bio_endio+0x114/0x224
>> [ 93.108671] blk_zone_write_plug_bio_endio+0x104/0x334
>> [ 93.108674] bio_endio+0x160/0x224
>> [ 93.108676] blk_update_request+0x17c/0x218
>>
>> On 10/14, Nanzhe Zhao wrote:
>>> This series supports large folios for most readable/writable files
>>> in buffered I/O paths, including normal files, block-layer encrypted
>>> files, and atomic files except for inline-data files, compressed files,
>>> and quota files.
>>>
>>> It also extends f2fs_folio_state to coexist with f2fs page-private
>>> flags and to handle large folio write path and partial truncate of
>>> large folios correctly. A valid large folio always carries a
>>> f2fs_folio_state at its folio->private in the current implementation.
>>>
>>> Benchmark details can be found in the RFC v2 cover letter [1].
>>>
>>> Changes in v5:
>>> - Rebased onto the f2fs dev-test branch (d1685c24b6c3).
>>> - Dropped the two prerequisite bug fixes, which are now merged:
>>> c04f209773ec ("f2fs: read i_size once in f2fs_vm_page_mkwrite")
>>> b3c984358925 ("f2fs: remove mappedtodisk flag usage in mmap write path")
>>> - Link to v4: [2]
>>>
>>> Many thanks to Chao and Daeho for your extensive reviews and valuable
>>> suggestions!
>>>
>>> [1] https://lore.kernel.org/r/20260622160830.324455-1-zhaonanzhe@xiaomi.com
>>> [2] https://lore.kernel.org/linux-f2fs-devel/20261013115621.968742-1-nzzhao.sigma@gmail.com/
>>>
>>> Nanzhe Zhao (16):
>>> f2fs: extend folio state for large folio write path
>>> f2fs: carry subpage offset and count in write IO
>>> f2fs: support regular file buffered writes on large folios
>>> f2fs: support atomic file large folios buffered write
>>> f2fs: support large folio writeback
>>> f2fs: account large folio dirty data at block granularity
>>> f2fs: prepare mmap write faults for large folios
>>> f2fs: make GC migration large-folio aware
>>> f2fs: optimize small block size large folio read
>>> f2fs: support partial uptodate large folio read
>>> f2fs: handle partial truncate of large folio dirty subpages
>>> f2fs: wait for folio writeback before ffs_detach_free
>>> f2fs: fix zeroing paths for large folios
>>> f2fs: handle block cloning within the same large folio
>>> f2fs: allow large folio support to writeable files
>>> f2fs: make compressed files compatible with large folio
>>>
>>> Documentation/filesystems/f2fs.rst | 10 +
>>> fs/f2fs/checkpoint.c | 40 +-
>>> fs/f2fs/compress.c | 7 +-
>>> fs/f2fs/data.c | 1467 +++++++++++++++++++++++++---
>>> fs/f2fs/dir.c | 2 +-
>>> fs/f2fs/f2fs.h | 170 +++-
>>> fs/f2fs/file.c | 226 +++--
>>> fs/f2fs/gc.c | 38 +-
>>> fs/f2fs/inline.c | 9 +-
>>> fs/f2fs/inode.c | 4 +-
>>> fs/f2fs/namei.c | 1 +
>>> fs/f2fs/node.c | 2 +-
>>> fs/f2fs/segment.c | 5 +-
>>> 13 files changed, 1716 insertions(+), 265 deletions(-)
>>>
>>> --
>>> 2.43.0
>>>
>>>
>>>
>>> _______________________________________________
>>> Linux-f2fs-devel mailing list
>>> Linux-f2fs-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>>
>>
>> _______________________________________________
>> Linux-f2fs-devel mailing list
>> Linux-f2fs-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 00/16] f2fs: support & optimize large folios for writable files
@ 2026-10-15 2:36 ` Chao Yu via Linux-f2fs-devel
0 siblings, 0 replies; 52+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2026-10-15 2:36 UTC (permalink / raw)
To: Jaegeuk Kim, Nanzhe Zhao, Barry Song, Nanzhe Zhao, Juan Yescas,
Daeho Jeong, linux-kernel, Dev Jain, David Hildenbrand,
Pengfei Li, Bo Zhang, Kalesh Singh, Nanzhe Zhao, linux-f2fs-devel,
Ryan Roberts
Nanzhe,
It needs to set .folio_blkcnt = 1 in move_data_page()
in "f2fs: carry subpage offset and count in write IO" rather than
in "f2fs: make GC migration large-folio aware"
On 10/15/26 10:13, Jaegeuk Kim via Linux-f2fs-devel wrote:
> Ok, this comes when applying "f2fs: carry subpage offset and count in write IO".
>
> On 10/14, Jaegeuk Kim via Linux-f2fs-devel wrote:
>> Hi Nanzhe,
>>
>> Could you please check IO submission path for Zoned block device?
>> I hit this.
>>
>> [ 93.100225] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100420] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100551] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100948] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101432] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101762] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101907] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.102564] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103054] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103447] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103667] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104294] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104373] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104449] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105220] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105253] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105532] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105575] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105606] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105985] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.106192] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.106692] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.106799] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107015] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107090] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107113] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.107268] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107288] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.107499] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107511] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.107707] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107724] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.107770] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107781] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.107929] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.107941] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.108040] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.108050] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.108166] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.108179] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.108322] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.108341] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443320; zone offset 19064; I/O scheduler (none); rq 00000000ea98b61b {.op=WRI
>> [ 93.108582] sd 0:0:0:4: [sde] tag#31 UNKNOWN(0x2003) Result: hostbyte=0x00 driverbyte=DRIVER_OK cmd_age=0s
>> [ 93.108588] sd 0:0:0:4: [sde] tag#31 Sense Key : 0x5 [current]
>> [ 93.108595] sd 0:0:0:4: [sde] tag#31 ASC=0x21 ASCQ=0x4
>> [ 93.108605] sd 0:0:0:4: [sde] tag#31 CDB: opcode=0x8a 8a 00 00 00 00 00 01 ee d9 4e 00 00 00 01 03 00
>> [ 93.108607] critical target error, dev sde, sector 259443312 op 0x1:(WRITE) flags 0x800 phys_seg 1 prio class 0
>> [ 93.108612] sde: zone 2639: Aborting plugged BIOs
>> [ 93.108626] CPU: 1 UID: 1000 PID: 1831 Comm: CachedAppOptimi Tainted: G W O 6.12.81-android16-6-maybe-dirty-4k #1 de5ea2c0fc3867082493fabcae9896176e2e435e
>> [ 93.108630] Tainted: [W]=WARN, [O]=OOT_MODULE
>> [ 93.108631] Hardware name: KODIAK DVT 1.0 based on MALIBU (DT)
>> [ 93.108632] Call trace:
>> [ 93.108633] dump_backtrace+0xec/0x128
>> [ 93.108641] show_stack+0x18/0x28
>> [ 93.108645] dump_stack_lvl+0x40/0xb8
>> [ 93.108649] dump_stack+0x18/0x28
>> [ 93.108652] f2fs_stop_checkpoint+0x1f0/0x2d8
>> [ 93.108654] f2fs_write_end_bio+0x50/0x694
>> [ 93.108657] f2fs_write_end_io+0x80/0x94
>> [ 93.108660] bio_endio+0x114/0x224
>> [ 93.108662] __dm_io_complete+0xf4/0x278
>> [ 93.108665] clone_endio+0xc0/0x26c
>> [ 93.108669] bio_endio+0x114/0x224
>> [ 93.108671] blk_zone_write_plug_bio_endio+0x104/0x334
>> [ 93.108674] bio_endio+0x160/0x224
>> [ 93.108676] blk_update_request+0x17c/0x218
>>
>> On 10/14, Nanzhe Zhao wrote:
>>> This series supports large folios for most readable/writable files
>>> in buffered I/O paths, including normal files, block-layer encrypted
>>> files, and atomic files except for inline-data files, compressed files,
>>> and quota files.
>>>
>>> It also extends f2fs_folio_state to coexist with f2fs page-private
>>> flags and to handle large folio write path and partial truncate of
>>> large folios correctly. A valid large folio always carries a
>>> f2fs_folio_state at its folio->private in the current implementation.
>>>
>>> Benchmark details can be found in the RFC v2 cover letter [1].
>>>
>>> Changes in v5:
>>> - Rebased onto the f2fs dev-test branch (d1685c24b6c3).
>>> - Dropped the two prerequisite bug fixes, which are now merged:
>>> c04f209773ec ("f2fs: read i_size once in f2fs_vm_page_mkwrite")
>>> b3c984358925 ("f2fs: remove mappedtodisk flag usage in mmap write path")
>>> - Link to v4: [2]
>>>
>>> Many thanks to Chao and Daeho for your extensive reviews and valuable
>>> suggestions!
>>>
>>> [1] https://lore.kernel.org/r/20260622160830.324455-1-zhaonanzhe@xiaomi.com
>>> [2] https://lore.kernel.org/linux-f2fs-devel/20261013115621.968742-1-nzzhao.sigma@gmail.com/
>>>
>>> Nanzhe Zhao (16):
>>> f2fs: extend folio state for large folio write path
>>> f2fs: carry subpage offset and count in write IO
>>> f2fs: support regular file buffered writes on large folios
>>> f2fs: support atomic file large folios buffered write
>>> f2fs: support large folio writeback
>>> f2fs: account large folio dirty data at block granularity
>>> f2fs: prepare mmap write faults for large folios
>>> f2fs: make GC migration large-folio aware
>>> f2fs: optimize small block size large folio read
>>> f2fs: support partial uptodate large folio read
>>> f2fs: handle partial truncate of large folio dirty subpages
>>> f2fs: wait for folio writeback before ffs_detach_free
>>> f2fs: fix zeroing paths for large folios
>>> f2fs: handle block cloning within the same large folio
>>> f2fs: allow large folio support to writeable files
>>> f2fs: make compressed files compatible with large folio
>>>
>>> Documentation/filesystems/f2fs.rst | 10 +
>>> fs/f2fs/checkpoint.c | 40 +-
>>> fs/f2fs/compress.c | 7 +-
>>> fs/f2fs/data.c | 1467 +++++++++++++++++++++++++---
>>> fs/f2fs/dir.c | 2 +-
>>> fs/f2fs/f2fs.h | 170 +++-
>>> fs/f2fs/file.c | 226 +++--
>>> fs/f2fs/gc.c | 38 +-
>>> fs/f2fs/inline.c | 9 +-
>>> fs/f2fs/inode.c | 4 +-
>>> fs/f2fs/namei.c | 1 +
>>> fs/f2fs/node.c | 2 +-
>>> fs/f2fs/segment.c | 5 +-
>>> 13 files changed, 1716 insertions(+), 265 deletions(-)
>>>
>>> --
>>> 2.43.0
>>>
>>>
>>>
>>> _______________________________________________
>>> Linux-f2fs-devel mailing list
>>> Linux-f2fs-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>>
>>
>> _______________________________________________
>> Linux-f2fs-devel mailing list
>> Linux-f2fs-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re: [f2fs-dev] [PATCH v5 00/16] f2fs: support & optimize large folios for writable files
2026-10-15 2:13 ` Jaegeuk Kim via Linux-f2fs-devel
@ 2026-10-15 3:33 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-15 3:33 UTC (permalink / raw)
To: Jaegeuk Kim
Cc: Nanzhe Zhao, Barry Song, linux-f2fs-devel, Juan Yescas,
Daeho Jeong, Pengfei Li, Dev Jain, linux-kernel,
David Hildenbrand, Bo Zhang, Kalesh Singh, Ryan Roberts,
Nanzhe Zhao
Hi Jaeguk:
>Ok, this comes when applying "f2fs: carry subpage offset and count in write IO".
>
So we didn't reproduce this bug with the whole series patched on dev-test?
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re:Re: [f2fs-dev] [PATCH v5 00/16] f2fs: support & optimize large folios for writable files
@ 2026-10-15 3:33 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-15 3:33 UTC (permalink / raw)
To: Jaegeuk Kim
Cc: Nanzhe Zhao, Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong,
linux-kernel, Dev Jain, David Hildenbrand, Pengfei Li, Bo Zhang,
Kalesh Singh, linux-f2fs-devel, Ryan Roberts
Hi Jaeguk:
>Ok, this comes when applying "f2fs: carry subpage offset and count in write IO".
>
So we didn't reproduce this bug with the whole series patched on dev-test?
Thanks,
^ permalink raw reply [flat|nested] 52+ messages in thread
* Re:Re: [f2fs-dev] [PATCH v5 00/16] f2fs: support & optimize large folios for writable files
2026-10-15 2:13 ` Jaegeuk Kim via Linux-f2fs-devel
@ 2026-10-15 8:40 ` Nanzhe Zhao
-1 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-15 8:40 UTC (permalink / raw)
To: Jaegeuk Kim
Cc: Nanzhe Zhao, Barry Song, Nanzhe Zhao, Juan Yescas, Daeho Jeong,
linux-kernel, Dev Jain, David Hildenbrand, Pengfei Li, Bo Zhang,
Kalesh Singh, linux-f2fs-devel, Ryan Roberts
Hi Jaeguk:
At 2026-10-15 10:13:53, "Jaegeuk Kim" <jaegeuk@kernel.org> wrote:
>Ok, this comes when applying "f2fs: carry subpage offset and count in write IO".
>
>On 10/14, Jaegeuk Kim via Linux-f2fs-devel wrote:
>> Hi Nanzhe,
>>
>> Could you please check IO submission path for Zoned block device?
>> I hit this.
>>
>> [ 93.100225] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100420] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100551] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100948] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101432] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101762] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101907] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.102564] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103054] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103447] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103667] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104294] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104373] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104449] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105220] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105253] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105532] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
Could you tell me which line of code prints this log? I've found a bit difficult to find in my f2fs dev-test kernel tree and pixel android mainline kernel tree..
Thanks,
Nanzhe
^ permalink raw reply [flat|nested] 52+ messages in thread* Re: [f2fs-dev] [PATCH v5 00/16] f2fs: support & optimize large folios for writable files
@ 2026-10-15 8:40 ` Nanzhe Zhao
0 siblings, 0 replies; 52+ messages in thread
From: Nanzhe Zhao @ 2026-10-15 8:40 UTC (permalink / raw)
To: Jaegeuk Kim
Cc: Nanzhe Zhao, Barry Song, linux-f2fs-devel, Juan Yescas,
Daeho Jeong, Pengfei Li, Dev Jain, linux-kernel,
David Hildenbrand, Bo Zhang, Kalesh Singh, Ryan Roberts,
Nanzhe Zhao
Hi Jaeguk:
At 2026-10-15 10:13:53, "Jaegeuk Kim" <jaegeuk@kernel.org> wrote:
>Ok, this comes when applying "f2fs: carry subpage offset and count in write IO".
>
>On 10/14, Jaegeuk Kim via Linux-f2fs-devel wrote:
>> Hi Nanzhe,
>>
>> Could you please check IO submission path for Zoned block device?
>> I hit this.
>>
>> [ 93.100225] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100420] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100551] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.100948] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101432] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101762] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.101907] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.102564] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103054] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103447] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.103667] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104294] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104373] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.104449] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105220] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105253] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
>> [ 93.105532] sd 0:0:0:4: Retrying unaligned write for zone 2639; offset 259443312; zone offset 19056; I/O scheduler (none); rq 00000000653b6a70 {.op=WRI
Could you tell me which line of code prints this log? I've found a bit difficult to find in my f2fs dev-test kernel tree and pixel android mainline kernel tree..
Thanks,
Nanzhe
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 52+ messages in thread