mm: fix arithmetic for bdi min_ratio and max_ratio
Subsystems (4)
v3 cover mm: fix arithmetic for bdi min_ratio and max_ratio
changes since v2:
- patch 2: drop div64_u64(), instead write it out mathematically (Matthew Wilcox)
changes since v1:
- split the previous v1 patch into two separate patches with corresponding "Fixes" tag (Andrew Morton)
- patch 2: remove "UL" suffix for the "100" constant
v1: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
Jingbo Xu (2):
mm: fix arithmetic for bdi min_ratio
mm: fix arithmetic for max_prop_frac when setting max_ratio
mm/page-writeback.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.19.1.6.gb485710b
PATCH v3 1/2 mm: fix arithmetic for bdi min_ratio
Since now bdi->min_ratio is part per million, fix the wrong arithmetic. Otherwise it will fail with -EINVAL when setting a reasonable min_ratio, as it tries to set min_ratio to (min_ratio * BDI_RATIO_SCALE) in percentage unit, which exceeds 100% anyway.
# cat /sys/class/bdi/253\:0/min_ratio
0
# cat /sys/class/bdi/253\:0/max_ratio
100
# echo 1 > /sys/class/bdi/253\:0/min_ratio
-bash: echo: write error: Invalid argument--- mm/page-writeback.c | 1 - 1 file changed, 1 deletion(-)
mm/page-writeback.c +0 -1
@@ -692,7 +692,6 @@ static int __bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_raif (min_ratio >100 *BDI_RATIO_SCALE )return -EINVAL ; - min_ratio *=BDI_RATIO_SCALE ;spin_lock_bh (&bdi_lock);if (min_ratio > bdi->max_ratio) {
Signature · 1 line
2.19.1.6.gb485710b
Re: [PATCH v3 1/2] mm: fix arithmetic for bdi min_ratio
Quoted 12 lines · Jingbo Xu
Since now
bdi->min_ratiois part per million, fix the wrong arithmetic. Otherwise it will fail with-EINVALwhen setting a reasonablemin_ratio, as it tries to setmin_ratioto (min_ratio*BDI_RATIO_SCALE) in percentage unit, which exceeds 100% anyway.# cat /sys/class/bdi/253\:0/min_ratio 0 # cat /sys/class/bdi/253\:0/max_ratio 100 # echo 1 > /sys/class/bdi/253\:0/min_ratio -bash: echo: write error: Invalid argument
Quoted 3 lines
Fixes 8021fb3232f2 ("mm: split off __bdi_set_min_ratio() function")Reported-by Joseph Qi <[email protected]>Signed-off-by Jingbo Xu <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 20 lines
--- mm/page-writeback.c | 1 - 1 file changed, 1 deletion(-)mm/page-writeback.c +0
-1@@ -692,7 +692,6 @@ static int __bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_raif (min_ratio >100 *BDI_RATIO_SCALE )return -EINVAL ; - min_ratio *=BDI_RATIO_SCALE ;spin_lock_bh (&bdi_lock);if (min_ratio > bdi->max_ratio) {Signature · 1 line
2.19.1.6.gb485710b
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v3 2/2 mm: fix arithmetic for max_prop_frac when setting max_ratio
In reply to Jingbo XuSince now bdi->max_ratio is part per million, fix the wrong arithmetic for max_prop_frac when setting max_ratio. Otherwise the miscalculated max_prop_frac will affect the incrementing of writeout completion count when max_ratio is not 100%.
--- mm/page-writeback.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page-writeback.c +2 -1
@@ -728,7 +728,8 @@ static int __bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ra ret = -EINVAL ; }else { bdi->max_ratio = max_ratio; - bdi->max_prop_frac = (FPROP_FRAC_BASE * max_ratio) /100 ; + bdi->max_prop_frac = (FPROP_FRAC_BASE * max_ratio) / + (100 *BDI_RATIO_SCALE ); }spin_unlock_bh (&bdi_lock);
Signature · 1 line
2.19.1.6.gb485710b
Re: [PATCH v3 2/2] mm: fix arithmetic for max_prop_frac when setting max_ratio
Quoted 7 lines · Jingbo Xu
Since now
bdi->max_ratiois part per million, fix the wrong arithmetic formax_prop_fracwhen settingmax_ratio. Otherwise the miscalculatedmax_prop_fracwill affect the incrementing of writeout completion count whenmax_ratiois not 100%.Fixes efc3e6ad53ea ("mm: split off __bdi_set_max_ratio() function")Signed-off-by Jingbo Xu <[email protected]>
Good catch. Feel free to add:
Honza
Quoted 22 lines
--- mm/page-writeback.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/page-writeback.c +2
-1@@ -728,7 +728,8 @@ static int __bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ra ret = -EINVAL ; }else { bdi->max_ratio = max_ratio; - bdi->max_prop_frac = (FPROP_FRAC_BASE * max_ratio) /100 ; + bdi->max_prop_frac = (FPROP_FRAC_BASE * max_ratio) / + (100 *BDI_RATIO_SCALE ); }spin_unlock_bh (&bdi_lock);Signature · 1 line
2.19.1.6.gb485710b
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
It would be good if the cover letter describes what this fixes.
Quoted 23 lines · Jingbo Xu
changes since v2:
- patch 2: dropdiv64_u64(), instead write it out mathematically (Matthew Wilcox)changes since v1:
- split the previous v1 patch into two separate patches with corresponding "Fixes" tag (Andrew Morton)
- patch 2: remove "UL" suffix for the "100" constantv1:
https://lore.kernel.org/all/[email protected]/
v2:
https://lore.kernel.org/all/[email protected]/Jingbo Xu (2):
mm: fix arithmetic for bdimin_ratio
mm: fix arithmetic formax_prop_fracwhen settingmax_ratiomm/page-writeback.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Signature · 1 line
2.19.1.6.gb485710b
Quoted 1 line · Stefan Roesch
It would be good if the cover letter describes what this fixes.
Thanks. Would notice that next time :)
Quoted 25 lines · Jingbo Xu
Quoted 23 lines
changes since v2:
- patch 2: dropdiv64_u64(), instead write it out mathematically (Matthew Wilcox)changes since v1:
- split the previous v1 patch into two separate patches with corresponding "Fixes" tag (Andrew Morton)
- patch 2: remove "UL" suffix for the "100" constantv1:
https://lore.kernel.org/all/[email protected]/
v2:
https://lore.kernel.org/all/[email protected]/Jingbo Xu (2):
mm: fix arithmetic for bdimin_ratio
mm: fix arithmetic formax_prop_fracwhen settingmax_ratiomm/page-writeback.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Signature · 1 line
2.19.1.6.gb485710b
Signature · 2 lines
Thanks, Jingbo