Skip to content

Commit ae82291

Browse files
Stefan Roeschakpm00
authored andcommitted
mm: use part per 1000000 for bdi ratios
To get finer granularity for ratio calculations use part per million instead of percentiles. This is especially important if we want to automatically convert byte values to ratios. Otherwise the values that are actually used can be quite different. This is also important for machines with more main memory (1% of 256GB is already 2.5GB). Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Stefan Roesch <[email protected]> Cc: Chris Mason <[email protected]> Cc: Jens Axboe <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 16b837e commit ae82291

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

include/linux/backing-dev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ static inline unsigned long wb_stat_error(void)
102102
#endif
103103
}
104104

105+
/* BDI ratio is expressed as part per 1000000 for finer granularity. */
106+
#define BDI_RATIO_SCALE 10000
107+
105108
int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio);
106109
int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);
107110
int bdi_set_strict_limit(struct backing_dev_info *bdi, unsigned int strict_limit);

mm/backing-dev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static ssize_t min_ratio_store(struct device *dev,
178178

179179
return ret;
180180
}
181-
BDI_SHOW(min_ratio, bdi->min_ratio)
181+
BDI_SHOW(min_ratio, bdi->min_ratio / BDI_RATIO_SCALE)
182182

183183
static ssize_t max_ratio_store(struct device *dev,
184184
struct device_attribute *attr, const char *buf, size_t count)
@@ -197,7 +197,7 @@ static ssize_t max_ratio_store(struct device *dev,
197197

198198
return ret;
199199
}
200-
BDI_SHOW(max_ratio, bdi->max_ratio)
200+
BDI_SHOW(max_ratio, bdi->max_ratio / BDI_RATIO_SCALE)
201201

202202
static ssize_t stable_pages_required_show(struct device *dev,
203203
struct device_attribute *attr,
@@ -809,7 +809,7 @@ int bdi_init(struct backing_dev_info *bdi)
809809

810810
kref_init(&bdi->refcnt);
811811
bdi->min_ratio = 0;
812-
bdi->max_ratio = 100;
812+
bdi->max_ratio = 100 * BDI_RATIO_SCALE;
813813
bdi->max_prop_frac = FPROP_FRAC_BASE;
814814
INIT_LIST_HEAD(&bdi->bdi_list);
815815
INIT_LIST_HEAD(&bdi->wb_list);

mm/page-writeback.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static void wb_min_max_ratio(struct bdi_writeback *wb,
197197
min *= this_bw;
198198
min = div64_ul(min, tot_bw);
199199
}
200-
if (max < 100) {
200+
if (max < 100 * BDI_RATIO_SCALE) {
201201
max *= this_bw;
202202
max = div64_ul(max, tot_bw);
203203
}
@@ -655,6 +655,8 @@ int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio)
655655
unsigned int delta;
656656
int ret = 0;
657657

658+
min_ratio *= BDI_RATIO_SCALE;
659+
658660
spin_lock_bh(&bdi_lock);
659661
if (min_ratio > bdi->max_ratio) {
660662
ret = -EINVAL;
@@ -665,7 +667,7 @@ int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio)
665667
bdi->min_ratio = min_ratio;
666668
} else {
667669
delta = min_ratio - bdi->min_ratio;
668-
if (bdi_min_ratio + delta < 100) {
670+
if (bdi_min_ratio + delta < 100 * BDI_RATIO_SCALE) {
669671
bdi_min_ratio += delta;
670672
bdi->min_ratio = min_ratio;
671673
} else {
@@ -684,6 +686,7 @@ int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned max_ratio)
684686

685687
if (max_ratio > 100)
686688
return -EINVAL;
689+
max_ratio *= BDI_RATIO_SCALE;
687690

688691
spin_lock_bh(&bdi_lock);
689692
if (bdi->min_ratio > max_ratio) {
@@ -775,15 +778,15 @@ static unsigned long __wb_calc_thresh(struct dirty_throttle_control *dtc)
775778
fprop_fraction_percpu(&dom->completions, dtc->wb_completions,
776779
&numerator, &denominator);
777780

778-
wb_thresh = (thresh * (100 - bdi_min_ratio)) / 100;
781+
wb_thresh = (thresh * (100 * BDI_RATIO_SCALE - bdi_min_ratio)) / (100 * BDI_RATIO_SCALE);
779782
wb_thresh *= numerator;
780783
wb_thresh = div64_ul(wb_thresh, denominator);
781784

782785
wb_min_max_ratio(dtc->wb, &wb_min_ratio, &wb_max_ratio);
783786

784-
wb_thresh += (thresh * wb_min_ratio) / 100;
785-
if (wb_thresh > (thresh * wb_max_ratio) / 100)
786-
wb_thresh = thresh * wb_max_ratio / 100;
787+
wb_thresh += (thresh * wb_min_ratio) / (100 * BDI_RATIO_SCALE);
788+
if (wb_thresh > (thresh * wb_max_ratio) / (100 * BDI_RATIO_SCALE))
789+
wb_thresh = thresh * wb_max_ratio / (100 * BDI_RATIO_SCALE);
787790

788791
return wb_thresh;
789792
}

0 commit comments

Comments
 (0)