Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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/20241023100032.62952-1-jimzhao.ai@gmail.com
Signed-off-by: Jim Zhao <jimzhao.ai@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Jim Zhao and committed by
Andrew Morton
39ac9985 72237693

+22 -3
+22 -3
mm/page-writeback.c
··· 917 917 unsigned long thresh) 918 918 { 919 919 struct wb_domain *dom = dtc_dom(dtc); 920 + struct bdi_writeback *wb = dtc->wb; 920 921 u64 wb_thresh; 922 + u64 wb_max_thresh; 921 923 unsigned long numerator, denominator; 922 924 unsigned long wb_min_ratio, wb_max_ratio; 923 925 ··· 933 931 wb_thresh *= numerator; 934 932 wb_thresh = div64_ul(wb_thresh, denominator); 935 933 936 - wb_min_max_ratio(dtc->wb, &wb_min_ratio, &wb_max_ratio); 934 + wb_min_max_ratio(wb, &wb_min_ratio, &wb_max_ratio); 937 935 938 936 wb_thresh += (thresh * wb_min_ratio) / (100 * BDI_RATIO_SCALE); 939 - if (wb_thresh > (thresh * wb_max_ratio) / (100 * BDI_RATIO_SCALE)) 940 - wb_thresh = thresh * wb_max_ratio / (100 * BDI_RATIO_SCALE); 937 + wb_max_thresh = thresh * wb_max_ratio / (100 * BDI_RATIO_SCALE); 938 + if (wb_thresh > wb_max_thresh) 939 + wb_thresh = wb_max_thresh; 940 + 941 + /* 942 + * With strictlimit flag, the wb_thresh is treated as 943 + * a hard limit in balance_dirty_pages() and wb_position_ratio(). 944 + * It's possible that wb_thresh is close to zero, not because 945 + * the device is slow, but because it has been inactive. 946 + * To prevent occasional writes from being blocked, we raise wb_thresh. 947 + */ 948 + if (unlikely(wb->bdi->capabilities & BDI_CAP_STRICTLIMIT)) { 949 + unsigned long limit = hard_dirty_limit(dom, dtc->thresh); 950 + u64 wb_scale_thresh = 0; 951 + 952 + if (limit > dtc->dirty) 953 + wb_scale_thresh = (limit - dtc->dirty) / 100; 954 + wb_thresh = max(wb_thresh, min(wb_scale_thresh, wb_max_thresh / 4)); 955 + } 941 956 942 957 return wb_thresh; 943 958 }