From: Christoph Hellwig <hch@lst.de>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Eric Van Hensbergen <ericvh@kernel.org>,
Latchesar Ionkov <lucho@ionkov.net>,
Dominique Martinet <asmadeus@codewreck.org>,
Christian Schoenebeck <linux_oss@crudebyte.com>,
Chris Mason <clm@fb.com>, David Sterba <dsterba@suse.com>,
Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
Josef Bacik <josef@toxicpanda.com>, Jan Kara <jack@suse.cz>,
linux-block@vger.kernel.org, v9fs@lists.linux.dev,
linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org,
linux-fsdevel@vger.kernel.org,
jfs-discussion@lists.sourceforge.net,
ocfs2-devel@lists.linux.dev, linux-xfs@vger.kernel.org,
linux-mm@kvack.org
Subject: [PATCH 05/10] btrfs: push struct writeback_control into start_delalloc_inodes
Date: Mon, 13 Oct 2025 11:58:00 +0900 [thread overview]
Message-ID: <20251013025808.4111128-6-hch@lst.de> (raw)
In-Reply-To: <20251013025808.4111128-1-hch@lst.de>
In preparation for changing the filemap_fdatawrite_wbc API to not expose
the writeback_control to the callers, push the wbc declaration next to
the filemap_fdatawrite_wbc call and just pass thr nr_to_write value to
start_delalloc_inodes.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/btrfs/inode.c | 51 ++++++++++++++++++++----------------------------
1 file changed, 21 insertions(+), 30 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 9edb78fc57fc..b97d6c1f7772 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8709,15 +8709,13 @@ static struct btrfs_delalloc_work *btrfs_alloc_delalloc_work(struct inode *inode
* some fairly slow code that needs optimization. This walks the list
* of all the inodes with pending delalloc and forces them to disk.
*/
-static int start_delalloc_inodes(struct btrfs_root *root,
- struct writeback_control *wbc, bool snapshot,
- bool in_reclaim_context)
+static int start_delalloc_inodes(struct btrfs_root *root, long *nr_to_write,
+ bool snapshot, bool in_reclaim_context)
{
struct btrfs_delalloc_work *work, *next;
LIST_HEAD(works);
LIST_HEAD(splice);
int ret = 0;
- bool full_flush = wbc->nr_to_write == LONG_MAX;
mutex_lock(&root->delalloc_mutex);
spin_lock(&root->delalloc_lock);
@@ -8743,7 +8741,7 @@ static int start_delalloc_inodes(struct btrfs_root *root,
if (snapshot)
set_bit(BTRFS_INODE_SNAPSHOT_FLUSH, &inode->runtime_flags);
- if (full_flush) {
+ if (nr_to_write == NULL) {
work = btrfs_alloc_delalloc_work(tmp_inode);
if (!work) {
iput(tmp_inode);
@@ -8754,9 +8752,20 @@ static int start_delalloc_inodes(struct btrfs_root *root,
btrfs_queue_work(root->fs_info->flush_workers,
&work->work);
} else {
- ret = filemap_fdatawrite_wbc(tmp_inode->i_mapping, wbc);
+ struct writeback_control wbc = {
+ .nr_to_write = *nr_to_write,
+ .sync_mode = WB_SYNC_NONE,
+ .range_start = 0,
+ .range_end = LLONG_MAX,
+ };
+
+ ret = filemap_fdatawrite_wbc(tmp_inode->i_mapping,
+ &wbc);
btrfs_add_delayed_iput(inode);
- if (ret || wbc->nr_to_write <= 0)
+
+ if (*nr_to_write != LONG_MAX)
+ *nr_to_write = wbc.nr_to_write;
+ if (ret || *nr_to_write <= 0)
goto out;
}
cond_resched();
@@ -8782,29 +8791,17 @@ static int start_delalloc_inodes(struct btrfs_root *root,
int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_context)
{
- struct writeback_control wbc = {
- .nr_to_write = LONG_MAX,
- .sync_mode = WB_SYNC_NONE,
- .range_start = 0,
- .range_end = LLONG_MAX,
- };
struct btrfs_fs_info *fs_info = root->fs_info;
if (BTRFS_FS_ERROR(fs_info))
return -EROFS;
-
- return start_delalloc_inodes(root, &wbc, true, in_reclaim_context);
+ return start_delalloc_inodes(root, NULL, true, in_reclaim_context);
}
int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
bool in_reclaim_context)
{
- struct writeback_control wbc = {
- .nr_to_write = nr,
- .sync_mode = WB_SYNC_NONE,
- .range_start = 0,
- .range_end = LLONG_MAX,
- };
+ long *nr_to_write = nr == LONG_MAX ? NULL : &nr;
struct btrfs_root *root;
LIST_HEAD(splice);
int ret;
@@ -8816,13 +8813,6 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
spin_lock(&fs_info->delalloc_root_lock);
list_splice_init(&fs_info->delalloc_roots, &splice);
while (!list_empty(&splice)) {
- /*
- * Reset nr_to_write here so we know that we're doing a full
- * flush.
- */
- if (nr == LONG_MAX)
- wbc.nr_to_write = LONG_MAX;
-
root = list_first_entry(&splice, struct btrfs_root,
delalloc_root);
root = btrfs_grab_root(root);
@@ -8831,9 +8821,10 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
&fs_info->delalloc_roots);
spin_unlock(&fs_info->delalloc_root_lock);
- ret = start_delalloc_inodes(root, &wbc, false, in_reclaim_context);
+ ret = start_delalloc_inodes(root, nr_to_write, false,
+ in_reclaim_context);
btrfs_put_root(root);
- if (ret < 0 || wbc.nr_to_write <= 0)
+ if (ret < 0 || nr <= 0)
goto out;
spin_lock(&fs_info->delalloc_root_lock);
}
--
2.47.3
next prev parent reply other threads:[~2025-10-13 2:58 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-13 2:57 filemap_* writeback interface cleanups Christoph Hellwig
2025-10-13 2:57 ` [PATCH 01/10] mm: don't opencode filemap_fdatawrite_range in filemap_invalidate_inode Christoph Hellwig
2025-10-13 7:41 ` Damien Le Moal
2025-10-13 11:32 ` Jan Kara
2025-10-13 12:46 ` David Hildenbrand
2025-10-13 2:57 ` [PATCH 02/10] 9p: don't opencode filemap_fdatawrite_range in v9fs_mmap_vm_close Christoph Hellwig
2025-10-13 7:42 ` Damien Le Moal
2025-10-13 11:33 ` Jan Kara
2025-10-13 2:57 ` [PATCH 03/10] ocfs2: don't opencode filemap_fdatawrite_range in ocfs2_journal_submit_inode_data_buffers Christoph Hellwig
2025-10-13 7:43 ` Damien Le Moal
2025-10-13 8:59 ` Joseph Qi
2025-10-13 11:34 ` Jan Kara
2025-10-13 2:57 ` [PATCH 04/10] btrfs: use the local tmp_inode variable in start_delalloc_inodes Christoph Hellwig
2025-10-13 7:48 ` Damien Le Moal
2025-10-13 8:11 ` Johannes Thumshirn
2025-10-14 4:44 ` hch
2025-10-14 7:02 ` Johannes Thumshirn
2025-10-14 17:37 ` David Sterba
2025-10-13 2:58 ` Christoph Hellwig [this message]
2025-10-13 7:55 ` [PATCH 05/10] btrfs: push struct writeback_control into start_delalloc_inodes Damien Le Moal
2025-10-13 8:15 ` Daniel Vacek
2025-10-13 8:19 ` Damien Le Moal
2025-10-13 2:58 ` [PATCH 06/10] mm,btrfs: add a filemap_fdatawrite_kick_nr helper Christoph Hellwig
2025-10-13 8:01 ` Damien Le Moal
2025-10-13 11:58 ` Jan Kara
2025-10-14 4:47 ` Christoph Hellwig
2025-10-14 9:33 ` Jan Kara
2025-10-14 20:45 ` Dave Chinner
2025-10-13 12:48 ` David Hildenbrand
2025-10-14 4:49 ` Christoph Hellwig
2025-10-14 11:04 ` David Hildenbrand
2025-10-13 2:58 ` [PATCH 07/10] mm: remove __filemap_fdatawrite Christoph Hellwig
2025-10-13 8:02 ` Damien Le Moal
2025-10-14 4:52 ` Christoph Hellwig
2025-10-13 11:59 ` Jan Kara
2025-10-14 4:53 ` Christoph Hellwig
2025-10-14 9:37 ` Jan Kara
2025-10-13 2:58 ` [PATCH 08/10] mm: remove filemap_fdatawrite_wbc Christoph Hellwig
2025-10-13 8:05 ` Damien Le Moal
2025-10-13 12:00 ` Jan Kara
2025-10-13 12:50 ` David Hildenbrand
2025-10-13 2:58 ` [PATCH 09/10] mm: remove __filemap_fdatawrite_range Christoph Hellwig
2025-10-13 8:09 ` Damien Le Moal
2025-10-13 12:03 ` Jan Kara
2025-10-13 2:58 ` [PATCH 10/10] mm: rename filemap_flush to filemap_fdatawrite_kick Christoph Hellwig
2025-10-13 8:14 ` Damien Le Moal
2025-10-13 8:23 ` Damien Le Moal
2025-10-13 8:12 ` filemap_* writeback interface cleanups Johannes Thumshirn
-- strict thread matches above, loose matches on Subject: below --
2025-10-24 8:04 filemap_* writeback interface cleanups v2 Christoph Hellwig
2025-10-24 8:04 ` [PATCH 05/10] btrfs: push struct writeback_control into start_delalloc_inodes Christoph Hellwig
2025-10-30 18:21 ` David Sterba
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=20251013025808.4111128-6-hch@lst.de \
--to=hch@lst.de \
--cc=asmadeus@codewreck.org \
--cc=brauner@kernel.org \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=ericvh@kernel.org \
--cc=jack@suse.cz \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=jlbec@evilplan.org \
--cc=josef@toxicpanda.com \
--cc=joseph.qi@linux.alibaba.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=linux_oss@crudebyte.com \
--cc=lucho@ionkov.net \
--cc=mark@fasheh.com \
--cc=ocfs2-devel@lists.linux.dev \
--cc=v9fs@lists.linux.dev \
--cc=viro@zeniv.linux.org.uk \
--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;
as well as URLs for NNTP newsgroup(s).