From: Kundan Kumar <kundan.kumar@samsung.com>
To: mcgrof@kernel.org
Cc: patches@lists.linux.dev, Kundan Kumar <kundan.kumar@samsung.com>,
Anuj Gupta <anuj20.g@samsung.com>
Subject: [PATCH v2 04/15] writeback: affine inode to a writeback ctx within a bdi
Date: Thu, 7 Aug 2025 10:26:55 +0530 [thread overview]
Message-ID: <20250807045706.2848-5-kundan.kumar@samsung.com> (raw)
In-Reply-To: <20250807045706.2848-1-kundan.kumar@samsung.com>
Affine inode to a writeback context. This helps in minimizing the
filesytem fragmentation due to inode being processed by different
threads.
To support parallel writeback, wire up a new superblock operation
get_inode_wb_ctx(). Filesystems with 64 bit inode numbers can implement
this callback to return suitable writeback context for the inode.
In fetch_bdi_writeback_ctx(), if the callback is implemented, it is used
to obtain the context. Otherwise the default fallback computes the
writeback context by taking mod with the 32-bit inode number.
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Kundan Kumar <kundan.kumar@samsung.com>
---
fs/fs-writeback.c | 3 ++-
fs/xfs/xfs_super.c | 12 ++++++++++++
include/linux/backing-dev.h | 4 +++-
include/linux/fs.h | 1 +
4 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 5165b7cc86e2..e065cd606b80 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[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/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 0bc4b5489078..645a426d1e41 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -53,6 +53,7 @@
#include <linux/magic.h>
#include <linux/fs_context.h>
#include <linux/fs_parser.h>
+#include <linux/backing-dev.h>
static const struct super_operations xfs_super_operations;
@@ -1294,6 +1295,16 @@ xfs_fs_show_stats(
return 0;
}
+static struct bdi_writeback_ctx *
+xfs_get_inode_wb_ctx(
+ struct inode *inode)
+{
+ struct xfs_inode *ip = XFS_I(inode);
+ struct backing_dev_info *bdi = inode_to_bdi(inode);
+
+ return bdi->wb_ctx[ip->i_ino % bdi->nr_wb_ctx];
+}
+
static const struct super_operations xfs_super_operations = {
.alloc_inode = xfs_fs_alloc_inode,
.destroy_inode = xfs_fs_destroy_inode,
@@ -1310,6 +1321,7 @@ static const struct super_operations xfs_super_operations = {
.free_cached_objects = xfs_fs_free_cached_objects,
.shutdown = xfs_fs_shutdown,
.show_stats = xfs_fs_show_stats,
+ .get_inode_wb_ctx = xfs_get_inode_wb_ctx,
};
static int
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
index 951ab5497500..6f744aadd83e 100644
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -157,7 +157,9 @@ fetch_bdi_writeback_ctx(struct inode *inode)
{
struct backing_dev_info *bdi = inode_to_bdi(inode);
- return bdi->wb_ctx[0];
+ if (inode->i_sb->s_op->get_inode_wb_ctx)
+ return inode->i_sb->s_op->get_inode_wb_ctx(inode);
+ return bdi->wb_ctx[inode->i_ino % bdi->nr_wb_ctx];
}
#ifdef CONFIG_CGROUP_WRITEBACK
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 8e2a041ce430..edcbc5042427 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2367,6 +2367,7 @@ struct super_operations {
long (*free_cached_objects)(struct super_block *,
struct shrink_control *);
void (*shutdown)(struct super_block *sb);
+ struct bdi_writeback_ctx *(*get_inode_wb_ctx)(struct inode *inode);
};
/*
--
2.25.1
next prev parent reply other threads:[~2025-08-07 4:58 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20250807045740epcas5p4cdec49f07b86acf2eea832890393d256@epcas5p4.samsung.com>
2025-08-07 4:56 ` [PATCH v2 00/15] Test patch Parallelizing filesystem writeback Kundan Kumar
2025-08-07 4:56 ` [PATCH v2 01/15] writeback: add infra for parallel writeback Kundan Kumar
2025-08-07 4:56 ` [PATCH v2 02/15] writeback: add support to initialize and free multiple writeback ctxs Kundan Kumar
2025-08-07 4:56 ` [PATCH v2 03/15] writeback: link bdi_writeback to its corresponding bdi_writeback_ctx Kundan Kumar
2025-08-07 4:56 ` Kundan Kumar [this message]
2025-08-07 4:56 ` [PATCH v2 05/15] writeback: modify bdi_writeback search logic to search across all wb ctxs Kundan Kumar
2025-08-07 4:56 ` [PATCH v2 06/15] writeback: invoke all writeback contexts for flusher and dirtytime writeback Kundan Kumar
2025-08-07 4:56 ` [PATCH v2 07/15] writeback: modify sync related functions to iterate over all writeback contexts Kundan Kumar
2025-08-07 4:56 ` [PATCH v2 08/15] writeback: add support to collect stats for all writeback ctxs Kundan Kumar
2025-08-07 4:57 ` [PATCH v2 09/15] f2fs: add support in f2fs to handle multiple writeback contexts Kundan Kumar
2025-08-07 4:57 ` [PATCH v2 10/15] fuse: add support for multiple writeback contexts in fuse Kundan Kumar
2025-08-07 4:57 ` [PATCH v2 11/15] gfs2: add support in gfs2 to handle multiple writeback contexts Kundan Kumar
2025-08-07 4:57 ` [PATCH v2 12/15] nfs: add support in nfs " Kundan Kumar
2025-08-07 4:57 ` [PATCH v2 13/15] writeback: set the num of writeback contexts to number of online cpus Kundan Kumar
2025-08-07 4:57 ` [PATCH v2 14/15] writeback: segregated allocation and free of writeback contexts Kundan Kumar
2025-08-07 4:57 ` [PATCH v2 15/15] writeback: added support to change the number of writebacks using a sysfs attribute Kundan Kumar
2025-08-07 18:34 ` [PATCH v2 00/15] Test patch Parallelizing filesystem writeback Luis Chamberlain
[not found] <CGME20250725155502epcas5p149ee8859fd9a97523bf876b50deaa84f@epcas5p1.samsung.com>
2025-07-25 15:54 ` [PATCH v2 00/15] " Kundan Kumar
2025-07-25 15:54 ` [PATCH v2 04/15] writeback: affine inode to a writeback ctx within a bdi Kundan Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250807045706.2848-5-kundan.kumar@samsung.com \
--to=kundan.kumar@samsung.com \
--cc=anuj20.g@samsung.com \
--cc=mcgrof@kernel.org \
--cc=patches@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox