Re: [PATCH v2 05/16] writeback: modify bdi_writeback search logic to search across all wb ctxs

Jan Kara
2025-10-21T12:05:47Z

On Tue 14-10-25 17:38:34, Kundan Kumar wrote:
> Since we have multiple cgwb per bdi, embedded in writeback_ctx now, we
> iterate over all of them to find the associated writeback.
>
> Signed-off-by: Kundan Kumar <kundan.kumar@samsung.com>
> Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
> ---
> fs/fs-writeback.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
> index 56c048e22f72..93f8ea340247 100644
> --- a/fs/fs-writeback.c
> +++ b/fs/fs-writeback.c
> @@ -1090,7 +1090,8 @@ int cgroup_writeback_by_id(u64 bdi_id, int memcg_id,
> {
> struct backing_dev_info *bdi;
> struct cgroup_subsys_state *memcg_css;
> - struct bdi_writeback *wb;
> + struct bdi_writeback *wb = NULL;
> + struct bdi_writeback_ctx *bdi_wb_ctx;
> struct wb_writeback_work *work;
> unsigned long dirty;
> int ret;
> @@ -1114,7 +1115,11 @@ int cgroup_writeback_by_id(u64 bdi_id, int memcg_id,
> * And find the associated wb. If the wb isn't there already
> * there's nothing to flush, don't create one.
> */
> - wb = wb_get_lookup(bdi->wb_ctx[0], memcg_css);
> + for_each_bdi_wb_ctx(bdi, bdi_wb_ctx) {
> + wb = wb_get_lookup(bdi_wb_ctx, memcg_css);
> + if (wb)
> + break;
> + }

This is wrong. We need to run writeback for all bdi_writeback structures
for given memcg_css. Not just for the one we found first. Otherwise
cgroup_writeback_by_id() wouldn't properly relieve the dirty pages pressure
from a foreign dirtying of a memcg (see the big comment before
mem_cgroup_track_foreign_dirty_slowpath() for more background on why
cgroup_writeback_by_id() exists).

Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR