[PATCH 04/13] writeback: affine inode to a writeback ctx within a bdi

Kundan Kumar
2025-05-29T11:33:40Z

Affine inode to a writeback context. This helps in minimizing the
filesytem fragmentation due to inode being processed by different
threads.

Signed-off-by: Kundan Kumar <kundan.kumar@samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Suggested-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
fs/fs-writeback.c | 3 ++-
include/linux/backing-dev.h | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 0959fff46235..9529e16c9b66 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -265,7 +265,8 @@ void __inode_attach_wb(struct inode *inode, struct folio *folio)
{
struct backing_dev_info *bdi = inode_to_bdi(inode);
struct bdi_writeback *wb = NULL;
- struct bdi_writeback_ctx *bdi_writeback_ctx = bdi->wb_ctx_arr[0];
+ struct bdi_writeback_ctx *bdi_writeback_ctx =
+ fetch_bdi_writeback_ctx(inode);

if (inode_cgwb_enabled(inode)) {
struct cgroup_subsys_state *memcg_css;
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
index fbccb483e59c..30a812fbd488 100644
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -157,7 +157,7 @@ fetch_bdi_writeback_ctx(struct inode *inode)
{
struct backing_dev_info *bdi = inode_to_bdi(inode);

- return bdi->wb_ctx_arr[0];
+ return bdi->wb_ctx_arr[inode->i_ino % bdi->nr_wb_ctx];
}

#ifdef CONFIG_CGROUP_WRITEBACK
--
2.25.1