From: Kundan Kumar <kundan.kumar@samsung.com>
To: jaegeuk@kernel.org, chao@kernel.org, viro@zeniv.linux.org.uk,
brauner@kernel.org, jack@suse.cz, miklos@szeredi.hu,
agruenba@redhat.com, trondmy@kernel.org, anna@kernel.org,
akpm@linux-foundation.org, willy@infradead.org,
mcgrof@kernel.org, clm@meta.com, david@fromorbit.com,
amir73il@gmail.com, axboe@kernel.dk, hch@lst.de,
ritesh.list@gmail.com, djwong@kernel.org, dave@stgolabs.net,
wangyufei@vivo.com
Cc: linux-f2fs-devel@lists.sourceforge.net,
linux-fsdevel@vger.kernel.org, gfs2@lists.linux.dev,
linux-nfs@vger.kernel.org, linux-mm@kvack.org,
gost.dev@samsung.com, kundan.kumar@samsung.com,
anuj20.g@samsung.com, vishak.g@samsung.com, joshi.k@samsung.com
Subject: [PATCH v2 07/16] writeback: modify sync related functions to iterate over all writeback contexts
Date: Tue, 14 Oct 2025 17:38:36 +0530 [thread overview]
Message-ID: <20251014120845.2361-8-kundan.kumar@samsung.com> (raw)
In-Reply-To: <20251014120845.2361-1-kundan.kumar@samsung.com>
Modify sync related functions to iterate over all writeback contexts.
Signed-off-by: Kundan Kumar <kundan.kumar@samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
---
fs/fs-writeback.c | 66 +++++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 22 deletions(-)
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 432f392c8256..7bf1f6c1c0ba 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -2753,11 +2753,13 @@ static void wait_sb_inodes(struct super_block *sb)
mutex_unlock(&sb->s_sync_lock);
}
-static void __writeback_inodes_sb_nr(struct super_block *sb, unsigned long nr,
- enum wb_reason reason, bool skip_if_busy)
+static void __writeback_inodes_sb_nr_ctx(struct super_block *sb,
+ unsigned long nr,
+ enum wb_reason reason,
+ bool skip_if_busy,
+ struct bdi_writeback_ctx *bdi_wb_ctx)
{
- struct backing_dev_info *bdi = sb->s_bdi;
- DEFINE_WB_COMPLETION(done, bdi->wb_ctx[0]);
+ DEFINE_WB_COMPLETION(done, bdi_wb_ctx);
struct wb_writeback_work work = {
.sb = sb,
.sync_mode = WB_SYNC_NONE,
@@ -2767,13 +2769,23 @@ static void __writeback_inodes_sb_nr(struct super_block *sb, unsigned long nr,
.reason = reason,
};
+ bdi_split_work_to_wbs(sb->s_bdi, bdi_wb_ctx, &work, skip_if_busy);
+ wb_wait_for_completion(&done);
+}
+
+static void __writeback_inodes_sb_nr(struct super_block *sb, unsigned long nr,
+ enum wb_reason reason, bool skip_if_busy)
+{
+ struct backing_dev_info *bdi = sb->s_bdi;
+ struct bdi_writeback_ctx *bdi_wb_ctx;
+
if (!bdi_has_dirty_io(bdi) || bdi == &noop_backing_dev_info)
return;
WARN_ON(!rwsem_is_locked(&sb->s_umount));
- bdi_split_work_to_wbs(sb->s_bdi, bdi->wb_ctx[0], &work,
- skip_if_busy);
- wb_wait_for_completion(&done);
+ for_each_bdi_wb_ctx(bdi, bdi_wb_ctx)
+ __writeback_inodes_sb_nr_ctx(sb, nr, reason, skip_if_busy,
+ bdi_wb_ctx);
}
/**
@@ -2826,17 +2838,11 @@ void try_to_writeback_inodes_sb(struct super_block *sb, enum wb_reason reason)
}
EXPORT_SYMBOL(try_to_writeback_inodes_sb);
-/**
- * sync_inodes_sb - sync sb inode pages
- * @sb: the superblock
- *
- * This function writes and waits on any dirty inode belonging to this
- * super_block.
- */
-void sync_inodes_sb(struct super_block *sb)
+static void sync_inodes_bdi_wb_ctx(struct super_block *sb,
+ struct backing_dev_info *bdi,
+ struct bdi_writeback_ctx *bdi_wb_ctx)
{
- struct backing_dev_info *bdi = sb->s_bdi;
- DEFINE_WB_COMPLETION(done, bdi->wb_ctx[0]);
+ DEFINE_WB_COMPLETION(done, bdi_wb_ctx);
struct wb_writeback_work work = {
.sb = sb,
.sync_mode = WB_SYNC_ALL,
@@ -2847,6 +2853,25 @@ void sync_inodes_sb(struct super_block *sb)
.for_sync = 1,
};
+ /* protect against inode wb switch, see inode_switch_wbs_work_fn() */
+ bdi_down_write_wb_ctx_switch_rwsem(bdi_wb_ctx);
+ bdi_split_work_to_wbs(bdi, bdi_wb_ctx, &work, false);
+ wb_wait_for_completion(&done);
+ bdi_up_write_wb_ctx_switch_rwsem(bdi_wb_ctx);
+}
+
+/**
+ * sync_inodes_sb - sync sb inode pages
+ * @sb: the superblock
+ *
+ * This function writes and waits on any dirty inode belonging to this
+ * super_block.
+ */
+void sync_inodes_sb(struct super_block *sb)
+{
+ struct backing_dev_info *bdi = sb->s_bdi;
+ struct bdi_writeback_ctx *bdi_wb_ctx;
+
/*
* Can't skip on !bdi_has_dirty() because we should wait for !dirty
* inodes under writeback and I_DIRTY_TIME inodes ignored by
@@ -2856,11 +2881,8 @@ void sync_inodes_sb(struct super_block *sb)
return;
WARN_ON(!rwsem_is_locked(&sb->s_umount));
- /* protect against inode wb switch, see inode_switch_wbs_work_fn() */
- bdi_down_write_wb_ctx_switch_rwsem(bdi->wb_ctx[0]);
- bdi_split_work_to_wbs(bdi, bdi->wb_ctx[0], &work, false);
- wb_wait_for_completion(&done);
- bdi_up_write_wb_ctx_switch_rwsem(bdi->wb_ctx[0]);
+ for_each_bdi_wb_ctx(bdi, bdi_wb_ctx)
+ sync_inodes_bdi_wb_ctx(sb, bdi, bdi_wb_ctx);
wait_sb_inodes(sb);
}
--
2.25.1
next prev parent reply other threads:[~2025-10-14 12:10 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20251014120958epcas5p267c3c9f9dbe6ffc53c25755327de89f9@epcas5p2.samsung.com>
2025-10-14 12:08 ` [PATCH v2 00/16] Parallelizing filesystem writeback Kundan Kumar
2025-10-14 12:08 ` [PATCH v2 01/16] writeback: add infra for parallel writeback Kundan Kumar
2025-10-21 11:52 ` Jan Kara
2025-10-14 12:08 ` [PATCH v2 02/16] writeback: add support to initialize and free multiple writeback ctxs Kundan Kumar
2025-10-14 12:08 ` [PATCH v2 03/16] writeback: link bdi_writeback to its corresponding bdi_writeback_ctx Kundan Kumar
2025-10-14 12:08 ` [PATCH v2 04/16] writeback: affine inode to a writeback ctx within a bdi Kundan Kumar
2025-10-21 11:58 ` Jan Kara
2025-10-14 12:08 ` [PATCH v2 05/16] writeback: modify bdi_writeback search logic to search across all wb ctxs Kundan Kumar
2025-10-21 12:05 ` Jan Kara
2025-10-14 12:08 ` [PATCH v2 06/16] writeback: invoke all writeback contexts for flusher and dirtytime writeback Kundan Kumar
2025-10-14 12:08 ` Kundan Kumar [this message]
2025-10-14 12:08 ` [PATCH v2 08/16] writeback: add support to collect stats for all writeback ctxs Kundan Kumar
2025-10-14 12:08 ` [PATCH v2 09/16] f2fs: add support in f2fs to handle multiple writeback contexts Kundan Kumar
2025-10-15 7:29 ` Christoph Hellwig
2025-10-14 12:08 ` [PATCH v2 10/16] fuse: add support for multiple writeback contexts in fuse Kundan Kumar
2025-10-14 12:08 ` [PATCH v2 11/16] gfs2: add support in gfs2 to handle multiple writeback contexts Kundan Kumar
2025-10-14 12:08 ` [PATCH v2 12/16] nfs: add support in nfs " Kundan Kumar
2025-10-14 12:08 ` [PATCH v2 13/16] writeback: configure the num of writeback contexts between 0 and number of online cpus Kundan Kumar
2025-10-14 12:08 ` [PATCH v2 14/16] writeback: segregated allocation and free of writeback contexts Kundan Kumar
2025-10-14 12:08 ` [PATCH v2 15/16] writeback: added support to change the number of writebacks using a sysfs attribute Kundan Kumar
2025-10-14 12:08 ` [PATCH v2 16/16] writeback: added XFS support for matching writeback count to allocation group count Kundan Kumar
2025-10-15 7:30 ` Christoph Hellwig
2025-10-15 1:03 ` [PATCH v2 00/16] Parallelizing filesystem writeback Andrew Morton
2025-10-15 8:54 ` Kundan Kumar
2025-10-15 7:31 ` Christoph Hellwig
2025-10-20 22:46 ` Dave Chinner
2025-10-21 10:36 ` Kundan Kumar
2025-10-21 12:11 ` Jan Kara
2025-10-23 11:41 ` Kundan Kumar
2025-10-22 4:39 ` Christoph Hellwig
2025-10-29 6:05 ` Kundan Kumar
2025-10-29 6:09 ` Darrick J. Wong
2025-10-29 8:55 ` Christoph Hellwig
2025-11-07 9:24 ` Kundan Kumar
2025-11-07 13:37 ` Christoph Hellwig
2025-11-11 5:41 ` 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=20251014120845.2361-8-kundan.kumar@samsung.com \
--to=kundan.kumar@samsung.com \
--cc=agruenba@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=amir73il@gmail.com \
--cc=anna@kernel.org \
--cc=anuj20.g@samsung.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=chao@kernel.org \
--cc=clm@meta.com \
--cc=dave@stgolabs.net \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=gfs2@lists.linux.dev \
--cc=gost.dev@samsung.com \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=jaegeuk@kernel.org \
--cc=joshi.k@samsung.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=miklos@szeredi.hu \
--cc=ritesh.list@gmail.com \
--cc=trondmy@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=vishak.g@samsung.com \
--cc=wangyufei@vivo.com \
--cc=willy@infradead.org \
/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