Skip to content

Commit f814bdd

Browse files
jankaraaxboe
authored andcommitted
blk-wbt: Fix detection of dirty-throttled tasks
The detection of dirty-throttled tasks in blk-wbt has been subtly broken since its beginning in 2016. Namely if we are doing cgroup writeback and the throttled task is not in the root cgroup, balance_dirty_pages() will set dirty_sleep for the non-root bdi_writeback structure. However blk-wbt checks dirty_sleep only in the root cgroup bdi_writeback structure. Thus detection of recently throttled tasks is not working in this case (we noticed this when we switched to cgroup v2 and suddently writeback was slow). Since blk-wbt has no easy way to get to proper bdi_writeback and furthermore its intention has always been to work on the whole device rather than on individual cgroups, just move the dirty_sleep timestamp from bdi_writeback to backing_dev_info. That fixes the checking for recently throttled task and saves memory for everybody as a bonus. CC: stable@vger.kernel.org Fixes: b57d74a ("writeback: track if we're sleeping on progress in balance_dirty_pages()") Signed-off-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20240123175826.21452-1-jack@suse.cz [axboe: fixup indentation errors] Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent f3c8998 commit f814bdd

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

block/blk-wbt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ static void wb_timestamp(struct rq_wb *rwb, unsigned long *var)
163163
*/
164164
static bool wb_recent_wait(struct rq_wb *rwb)
165165
{
166-
struct bdi_writeback *wb = &rwb->rqos.disk->bdi->wb;
166+
struct backing_dev_info *bdi = rwb->rqos.disk->bdi;
167167

168-
return time_before(jiffies, wb->dirty_sleep + HZ);
168+
return time_before(jiffies, bdi->last_bdp_sleep + HZ);
169169
}
170170

171171
static inline struct rq_wait *get_rq_wait(struct rq_wb *rwb,

include/linux/backing-dev-defs.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ struct bdi_writeback {
141141
struct delayed_work dwork; /* work item used for writeback */
142142
struct delayed_work bw_dwork; /* work item used for bandwidth estimate */
143143

144-
unsigned long dirty_sleep; /* last wait */
145-
146144
struct list_head bdi_node; /* anchored at bdi->wb_list */
147145

148146
#ifdef CONFIG_CGROUP_WRITEBACK
@@ -179,6 +177,11 @@ struct backing_dev_info {
179177
* any dirty wbs, which is depended upon by bdi_has_dirty().
180178
*/
181179
atomic_long_t tot_write_bandwidth;
180+
/*
181+
* Jiffies when last process was dirty throttled on this bdi. Used by
182+
* blk-wbt.
183+
*/
184+
unsigned long last_bdp_sleep;
182185

183186
struct bdi_writeback wb; /* the root writeback info for this bdi */
184187
struct list_head wb_list; /* list of all wbs */

mm/backing-dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
436436
INIT_LIST_HEAD(&wb->work_list);
437437
INIT_DELAYED_WORK(&wb->dwork, wb_workfn);
438438
INIT_DELAYED_WORK(&wb->bw_dwork, wb_update_bandwidth_workfn);
439-
wb->dirty_sleep = jiffies;
440439

441440
err = fprop_local_init_percpu(&wb->completions, gfp);
442441
if (err)
@@ -921,6 +920,7 @@ int bdi_init(struct backing_dev_info *bdi)
921920
INIT_LIST_HEAD(&bdi->bdi_list);
922921
INIT_LIST_HEAD(&bdi->wb_list);
923922
init_waitqueue_head(&bdi->wb_waitq);
923+
bdi->last_bdp_sleep = jiffies;
924924

925925
return cgwb_bdi_init(bdi);
926926
}

mm/page-writeback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ static int balance_dirty_pages(struct bdi_writeback *wb,
19211921
break;
19221922
}
19231923
__set_current_state(TASK_KILLABLE);
1924-
wb->dirty_sleep = now;
1924+
bdi->last_bdp_sleep = jiffies;
19251925
io_schedule_timeout(pause);
19261926

19271927
current->dirty_paused_when = now + pause;

0 commit comments

Comments
 (0)