diff options
author | Andrey Ryabinin <aryabinin@virtuozzo.com> | 2016-03-15 14:55:27 -0700 |
---|---|---|
committer | Sasha Levin <alexander.levin@microsoft.com> | 2018-02-28 22:09:35 -0500 |
commit | 47e9e29fee362d231c7581a1c25431b4e2c5d107 (patch) | |
tree | 3212cba475590addbd874bc6324fb3c4053c4dac /mm | |
parent | ff295e461f2faae7a520ac3dcc501ef693bd87d3 (diff) |
mm/page-writeback: fix dirty_ratelimit calculation
[ Upstream commit d59b1087a98e402ed9a7cc577f4da435f9a555f5 ]
Calculation of dirty_ratelimit sometimes is not correct. E.g. initial
values of dirty_ratelimit == INIT_BW and step == 0, lead to the
following result:
UBSAN: Undefined behaviour in ../mm/page-writeback.c:1286:7
shift exponent 25600 is too large for 64-bit type 'long unsigned int'
The fix is straightforward - make step 0 if the shift exponent is too
big.
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/page-writeback.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/mm/page-writeback.c b/mm/page-writeback.c index eb59f7eea508..308757ae508d 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -967,6 +967,7 @@ static void bdi_update_dirty_ratelimit(struct backing_dev_info *bdi, unsigned long pos_ratio; unsigned long step; unsigned long x; + unsigned long shift; /* * The dirty rate will match the writeout rate in long term, except @@ -1094,11 +1095,11 @@ static void bdi_update_dirty_ratelimit(struct backing_dev_info *bdi, * rate itself is constantly fluctuating. So decrease the track speed * when it gets close to the target. Helps eliminate pointless tremors. */ - step >>= dirty_ratelimit / (2 * step + 1); - /* - * Limit the tracking speed to avoid overshooting. - */ - step = (step + 7) / 8; + shift = dirty_ratelimit / (2 * step + 1); + if (shift < BITS_PER_LONG) + step = DIV_ROUND_UP(step >> shift, 8); + else + step = 0; if (dirty_ratelimit < balanced_dirty_ratelimit) dirty_ratelimit += step; |