Skip to content

Commit 8a73179

Browse files
htejunaxboe
authored andcommitted
writeback: reorganize [__]wb_update_bandwidth()
__wb_update_bandwidth() is called from two places - fs/fs-writeback.c::balance_dirty_pages() and mm/page-writeback.c::wb_writeback(). The latter updates only the write bandwidth while the former also deals with the dirty ratelimit. The two callsites are distinguished by whether @thresh parameter is zero or not, which is cryptic. In addition, the two files define their own different versions of wb_update_bandwidth() on top of __wb_update_bandwidth(), which is confusing to say the least. This patch cleans up [__]wb_update_bandwidth() in the following ways. * __wb_update_bandwidth() now takes explicit @update_ratelimit parameter to gate dirty ratelimit handling. * mm/page-writeback.c::wb_update_bandwidth() is flattened into its caller - balance_dirty_pages(). * fs/fs-writeback.c::wb_update_bandwidth() is moved to mm/page-writeback.c and __wb_update_bandwidth() is made static. * While at it, add a lockdep assertion to __wb_update_bandwidth(). Except for the lockdep addition, this is pure reorganization and doesn't introduce any behavioral changes. Signed-off-by: Tejun Heo <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Jan Kara <[email protected]> Cc: Wu Fengguang <[email protected]> Cc: Greg Thelen <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 0d960a3 commit 8a73179

File tree

3 files changed

+23
-41
lines changed

3 files changed

+23
-41
lines changed

fs/fs-writeback.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,16 +1087,6 @@ static bool over_bground_thresh(struct bdi_writeback *wb)
10871087
return false;
10881088
}
10891089

1090-
/*
1091-
* Called under wb->list_lock. If there are multiple wb per bdi,
1092-
* only the flusher working on the first wb should do it.
1093-
*/
1094-
static void wb_update_bandwidth(struct bdi_writeback *wb,
1095-
unsigned long start_time)
1096-
{
1097-
__wb_update_bandwidth(wb, 0, 0, 0, 0, 0, start_time);
1098-
}
1099-
11001090
/*
11011091
* Explicit flushing or periodic writeback of "old" data.
11021092
*

include/linux/writeback.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,7 @@ int dirty_writeback_centisecs_handler(struct ctl_table *, int,
157157
void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty);
158158
unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh);
159159

160-
void __wb_update_bandwidth(struct bdi_writeback *wb,
161-
unsigned long thresh,
162-
unsigned long bg_thresh,
163-
unsigned long dirty,
164-
unsigned long bdi_thresh,
165-
unsigned long bdi_dirty,
166-
unsigned long start_time);
167-
160+
void wb_update_bandwidth(struct bdi_writeback *wb, unsigned long start_time);
168161
void page_writeback_init(void);
169162
void balance_dirty_pages_ratelimited(struct address_space *mapping);
170163

mm/page-writeback.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,19 +1160,22 @@ static void wb_update_dirty_ratelimit(struct bdi_writeback *wb,
11601160
trace_bdi_dirty_ratelimit(wb->bdi, dirty_rate, task_ratelimit);
11611161
}
11621162

1163-
void __wb_update_bandwidth(struct bdi_writeback *wb,
1164-
unsigned long thresh,
1165-
unsigned long bg_thresh,
1166-
unsigned long dirty,
1167-
unsigned long wb_thresh,
1168-
unsigned long wb_dirty,
1169-
unsigned long start_time)
1163+
static void __wb_update_bandwidth(struct bdi_writeback *wb,
1164+
unsigned long thresh,
1165+
unsigned long bg_thresh,
1166+
unsigned long dirty,
1167+
unsigned long wb_thresh,
1168+
unsigned long wb_dirty,
1169+
unsigned long start_time,
1170+
bool update_ratelimit)
11701171
{
11711172
unsigned long now = jiffies;
11721173
unsigned long elapsed = now - wb->bw_time_stamp;
11731174
unsigned long dirtied;
11741175
unsigned long written;
11751176

1177+
lockdep_assert_held(&wb->list_lock);
1178+
11761179
/*
11771180
* rate-limit, only update once every 200ms.
11781181
*/
@@ -1189,7 +1192,7 @@ void __wb_update_bandwidth(struct bdi_writeback *wb,
11891192
if (elapsed > HZ && time_before(wb->bw_time_stamp, start_time))
11901193
goto snapshot;
11911194

1192-
if (thresh) {
1195+
if (update_ratelimit) {
11931196
global_update_bandwidth(thresh, dirty, now);
11941197
wb_update_dirty_ratelimit(wb, thresh, bg_thresh, dirty,
11951198
wb_thresh, wb_dirty,
@@ -1203,20 +1206,9 @@ void __wb_update_bandwidth(struct bdi_writeback *wb,
12031206
wb->bw_time_stamp = now;
12041207
}
12051208

1206-
static void wb_update_bandwidth(struct bdi_writeback *wb,
1207-
unsigned long thresh,
1208-
unsigned long bg_thresh,
1209-
unsigned long dirty,
1210-
unsigned long wb_thresh,
1211-
unsigned long wb_dirty,
1212-
unsigned long start_time)
1209+
void wb_update_bandwidth(struct bdi_writeback *wb, unsigned long start_time)
12131210
{
1214-
if (time_is_after_eq_jiffies(wb->bw_time_stamp + BANDWIDTH_INTERVAL))
1215-
return;
1216-
spin_lock(&wb->list_lock);
1217-
__wb_update_bandwidth(wb, thresh, bg_thresh, dirty,
1218-
wb_thresh, wb_dirty, start_time);
1219-
spin_unlock(&wb->list_lock);
1211+
__wb_update_bandwidth(wb, 0, 0, 0, 0, 0, start_time, false);
12201212
}
12211213

12221214
/*
@@ -1467,8 +1459,15 @@ static void balance_dirty_pages(struct address_space *mapping,
14671459
if (dirty_exceeded && !wb->dirty_exceeded)
14681460
wb->dirty_exceeded = 1;
14691461

1470-
wb_update_bandwidth(wb, dirty_thresh, background_thresh,
1471-
nr_dirty, wb_thresh, wb_dirty, start_time);
1462+
if (time_is_before_jiffies(wb->bw_time_stamp +
1463+
BANDWIDTH_INTERVAL)) {
1464+
spin_lock(&wb->list_lock);
1465+
__wb_update_bandwidth(wb, dirty_thresh,
1466+
background_thresh, nr_dirty,
1467+
wb_thresh, wb_dirty, start_time,
1468+
true);
1469+
spin_unlock(&wb->list_lock);
1470+
}
14721471

14731472
dirty_ratelimit = wb->dirty_ratelimit;
14741473
pos_ratio = wb_position_ratio(wb, dirty_thresh,

0 commit comments

Comments
 (0)