Skip to content

Commit 39ac998

Browse files
Jim Zhaoakpm00
authored andcommitted
mm/page-writeback: raise wb_thresh to prevent write blocking with strictlimit
With the strictlimit flag, wb_thresh acts as a hard limit in balance_dirty_pages() and wb_position_ratio(). When device write operations are inactive, wb_thresh can drop to 0, causing writes to be blocked. The issue occasionally occurs in fuse fs, particularly with network backends, the write thread is blocked frequently during a period. To address it, this patch raises the minimum wb_thresh to a controllable level, similar to the non-strictlimit case. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Jim Zhao <[email protected]> Cc: Matthew Wilcox <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 7223769 commit 39ac998

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

mm/page-writeback.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,9 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc,
917917
unsigned long thresh)
918918
{
919919
struct wb_domain *dom = dtc_dom(dtc);
920+
struct bdi_writeback *wb = dtc->wb;
920921
u64 wb_thresh;
922+
u64 wb_max_thresh;
921923
unsigned long numerator, denominator;
922924
unsigned long wb_min_ratio, wb_max_ratio;
923925

@@ -931,11 +933,28 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc,
931933
wb_thresh *= numerator;
932934
wb_thresh = div64_ul(wb_thresh, denominator);
933935

934-
wb_min_max_ratio(dtc->wb, &wb_min_ratio, &wb_max_ratio);
936+
wb_min_max_ratio(wb, &wb_min_ratio, &wb_max_ratio);
935937

936938
wb_thresh += (thresh * wb_min_ratio) / (100 * BDI_RATIO_SCALE);
937-
if (wb_thresh > (thresh * wb_max_ratio) / (100 * BDI_RATIO_SCALE))
938-
wb_thresh = thresh * wb_max_ratio / (100 * BDI_RATIO_SCALE);
939+
wb_max_thresh = thresh * wb_max_ratio / (100 * BDI_RATIO_SCALE);
940+
if (wb_thresh > wb_max_thresh)
941+
wb_thresh = wb_max_thresh;
942+
943+
/*
944+
* With strictlimit flag, the wb_thresh is treated as
945+
* a hard limit in balance_dirty_pages() and wb_position_ratio().
946+
* It's possible that wb_thresh is close to zero, not because
947+
* the device is slow, but because it has been inactive.
948+
* To prevent occasional writes from being blocked, we raise wb_thresh.
949+
*/
950+
if (unlikely(wb->bdi->capabilities & BDI_CAP_STRICTLIMIT)) {
951+
unsigned long limit = hard_dirty_limit(dom, dtc->thresh);
952+
u64 wb_scale_thresh = 0;
953+
954+
if (limit > dtc->dirty)
955+
wb_scale_thresh = (limit - dtc->dirty) / 100;
956+
wb_thresh = max(wb_thresh, min(wb_scale_thresh, wb_max_thresh / 4));
957+
}
939958

940959
return wb_thresh;
941960
}

0 commit comments

Comments
 (0)