[PATCH v2 09/16] f2fs: add support in f2fs to handle multiple writeback contexts

Kundan Kumar
2025-10-14T12:11:11Z

Add support to handle multiple writeback contexts and check for
dirty_exceeded across all the writeback contexts.

Made a new helper for same.

Signed-off-by: Kundan Kumar <kundan.kumar@samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
---
fs/f2fs/node.c | 4 ++--
fs/f2fs/segment.h | 2 +-
include/linux/backing-dev.h | 18 +++++++++++++++---
3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 1693da9417f9..cd75aa98a1ca 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -73,7 +73,7 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type)
if (excess_cached_nats(sbi))
res = false;
} else if (type == DIRTY_DENTS) {
- if (sbi->sb->s_bdi->wb_ctx[0]->wb.dirty_exceeded)
+ if (bdi_wb_dirty_limit_exceeded(sbi->sb->s_bdi))
return false;
mem_size = get_pages(sbi, F2FS_DIRTY_DENTS);
res = mem_size < ((avail_ram * nm_i->ram_thresh / 100) >> 1);
@@ -114,7 +114,7 @@ bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type)
res = false;
#endif
} else {
- if (!sbi->sb->s_bdi->wb_ctx[0]->wb.dirty_exceeded)
+ if (!bdi_wb_dirty_limit_exceeded(sbi->sb->s_bdi))
return true;
}
return res;
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 7e5b7b1a5d2b..8487bd5d4394 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -993,7 +993,7 @@ static inline bool sec_usage_check(struct f2fs_sb_info *sbi, unsigned int secno)
*/
static inline int nr_pages_to_skip(struct f2fs_sb_info *sbi, int type)
{
- if (sbi->sb->s_bdi->wb_ctx[0]->wb.dirty_exceeded)
+ if (bdi_wb_dirty_limit_exceeded(sbi->sb->s_bdi))
return 0;

if (type == DATA)
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
index 59bbb69d300c..bb35f8fa4973 100644
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -51,6 +51,21 @@ static inline bool wb_has_dirty_io(struct bdi_writeback *wb)
return test_bit(WB_has_dirty_io, &wb->state);
}

+#define for_each_bdi_wb_ctx(bdi, wbctx) \
+ for (int __i = 0; __i < (bdi)->nr_wb_ctx \
+ && ((wbctx) = (bdi)->wb_ctx[__i]) != NULL; __i++)
+
+static inline bool bdi_wb_dirty_limit_exceeded(struct backing_dev_info *bdi)
+{
+ struct bdi_writeback_ctx *bdi_wb_ctx;
+
+ for_each_bdi_wb_ctx(bdi, bdi_wb_ctx) {
+ if (bdi_wb_ctx->wb.dirty_exceeded)
+ return true;
+ }
+ return false;
+}
+
static inline bool bdi_has_dirty_io(struct backing_dev_info *bdi)
{
/*
@@ -149,9 +164,6 @@ static inline bool mapping_can_writeback(struct address_space *mapping)
}

#define DEFAULT_WB_CTX 0
-#define for_each_bdi_wb_ctx(bdi, wbctx) \
- for (int __i = 0; __i < (bdi)->nr_wb_ctx \
- && ((wbctx) = (bdi)->wb_ctx[__i]) != NULL; __i++)

static inline struct bdi_writeback_ctx *
fetch_bdi_writeback_ctx(struct inode *inode)
--
2.25.1