[PATCH v6 4/5] writeback, cgroup: support switching multiple inodes at once

From: Roman Gushchin
Date: Wed Jun 02 2021 - 20:55:59 EST


Currently only a single inode can be switched to another writeback
structure at once. That means to switch an inode a separate
inode_switch_wbs_context structure must be allocated, and a separate
rcu callback and work must be scheduled.

It's fine for the existing ad-hoc switching, which is not happening
that often, but sub-optimal for massive switching required in order to
release a writeback structure. To prepare for it, let's add a support
for switching multiple inodes at once.

Instead of containing a single inode pointer, inode_switch_wbs_context
will contain a NULL-terminated array of inode
pointers. inode_do_switch_wbs() will be called for each inode.

Signed-off-by: Roman Gushchin <guro@xxxxxx>
---
fs/fs-writeback.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 212494d89cc2..49d7b23a7cfe 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -335,10 +335,10 @@ static struct bdi_writeback *inode_to_wb_and_lock_list(struct inode *inode)
}

struct inode_switch_wbs_context {
- struct inode *inode;
- struct bdi_writeback *new_wb;
-
struct rcu_work work;
+
+ struct bdi_writeback *new_wb;
+ struct inode *inodes[];
};

static void bdi_down_write_wb_switch_rwsem(struct backing_dev_info *bdi)
@@ -473,10 +473,14 @@ static void inode_switch_wbs_work_fn(struct work_struct *work)
{
struct inode_switch_wbs_context *isw =
container_of(to_rcu_work(work), struct inode_switch_wbs_context, work);
+ struct inode **inodep;
+
+ for (inodep = &isw->inodes[0]; *inodep; inodep++) {
+ inode_do_switch_wbs(*inodep, isw->new_wb);
+ iput(*inodep);
+ }

- inode_do_switch_wbs(isw->inode, isw->new_wb);
wb_put(isw->new_wb);
- iput(isw->inode);
kfree(isw);
atomic_dec(&isw_nr_in_flight);
}
@@ -503,7 +507,7 @@ static void inode_switch_wbs(struct inode *inode, int new_wb_id)
if (atomic_read(&isw_nr_in_flight) > WB_FRN_MAX_IN_FLIGHT)
return;

- isw = kzalloc(sizeof(*isw), GFP_ATOMIC);
+ isw = kzalloc(sizeof(*isw) + 2 * sizeof(struct inode *), GFP_ATOMIC);
if (!isw)
return;

@@ -528,7 +532,7 @@ static void inode_switch_wbs(struct inode *inode, int new_wb_id)
__iget(inode);
spin_unlock(&inode->i_lock);

- isw->inode = inode;
+ isw->inodes[0] = inode;

/*
* In addition to synchronizing among switchers, I_WB_SWITCH tells
--
2.31.1