Skip to content

Commit 57fc978

Browse files
author
Wu Fengguang
committed
writeback: control dirty pause time
The dirty pause time shall ultimately be controlled by adjusting nr_dirtied_pause, since there is relationship pause = pages_dirtied / task_ratelimit Assuming pages_dirtied ~= nr_dirtied_pause task_ratelimit ~= dirty_ratelimit We get nr_dirtied_pause ~= dirty_ratelimit * desired_pause Here dirty_ratelimit is preferred over task_ratelimit because it's more stable. It's also important to limit possible large transitional errors: - bw is changing quickly - pages_dirtied << nr_dirtied_pause on entering dirty exceeded area - pages_dirtied >> nr_dirtied_pause on btrfs (to be improved by a separate fix, but still expect non-trivial errors) So we end up using the above formula inside clamp_val(). The best test case for this code is to run 100 "dd bs=4M" tasks on btrfs and check its pause time distribution. Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
1 parent c8462cc commit 57fc978

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎mm/page-writeback.c‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,10 @@ static void balance_dirty_pages(struct address_space *mapping,
10861086
task_ratelimit = (u64)dirty_ratelimit *
10871087
pos_ratio >> RATELIMIT_CALC_SHIFT;
10881088
pause = (HZ * pages_dirtied) / (task_ratelimit | 1);
1089+
if (unlikely(pause <= 0)) {
1090+
pause = 1; /* avoid resetting nr_dirtied_pause below */
1091+
break;
1092+
}
10891093
pause = min(pause, max_pause);
10901094

10911095
pause:
@@ -1107,7 +1111,21 @@ static void balance_dirty_pages(struct address_space *mapping,
11071111
bdi->dirty_exceeded = 0;
11081112

11091113
current->nr_dirtied = 0;
1110-
current->nr_dirtied_pause = dirty_poll_interval(nr_dirty, dirty_thresh);
1114+
if (pause == 0) { /* in freerun area */
1115+
current->nr_dirtied_pause =
1116+
dirty_poll_interval(nr_dirty, dirty_thresh);
1117+
} else if (pause <= max_pause / 4 &&
1118+
pages_dirtied >= current->nr_dirtied_pause) {
1119+
current->nr_dirtied_pause = clamp_val(
1120+
dirty_ratelimit * (max_pause / 2) / HZ,
1121+
pages_dirtied + pages_dirtied / 8,
1122+
pages_dirtied * 4);
1123+
} else if (pause >= max_pause) {
1124+
current->nr_dirtied_pause = 1 | clamp_val(
1125+
dirty_ratelimit * (max_pause / 2) / HZ,
1126+
pages_dirtied / 4,
1127+
pages_dirtied - pages_dirtied / 8);
1128+
}
11111129

11121130
if (writeback_in_progress(bdi))
11131131
return;

0 commit comments

Comments
 (0)