diff options
author | Andrey Ryabinin <aryabinin@virtuozzo.com> | 2016-03-15 17:55:27 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-03-15 19:55:16 -0400 |
commit | d59b1087a98e402ed9a7cc577f4da435f9a555f5 (patch) | |
tree | c0d59e0a254d7c4b9f31ee3a4873423cc200ee35 /mm/page-writeback.c | |
parent | b72d0ffb5dbc4070089b36230b98687ca4577cbc (diff) |
mm/page-writeback: fix dirty_ratelimit calculation
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>
Diffstat (limited to 'mm/page-writeback.c')
-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 6fe7d15bd1f7..d782cbab735a 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c | |||
@@ -1169,6 +1169,7 @@ static void wb_update_dirty_ratelimit(struct dirty_throttle_control *dtc, | |||
1169 | unsigned long balanced_dirty_ratelimit; | 1169 | unsigned long balanced_dirty_ratelimit; |
1170 | unsigned long step; | 1170 | unsigned long step; |
1171 | unsigned long x; | 1171 | unsigned long x; |
1172 | unsigned long shift; | ||
1172 | 1173 | ||
1173 | /* | 1174 | /* |
1174 | * The dirty rate will match the writeout rate in long term, except | 1175 | * The dirty rate will match the writeout rate in long term, except |
@@ -1293,11 +1294,11 @@ static void wb_update_dirty_ratelimit(struct dirty_throttle_control *dtc, | |||
1293 | * rate itself is constantly fluctuating. So decrease the track speed | 1294 | * rate itself is constantly fluctuating. So decrease the track speed |
1294 | * when it gets close to the target. Helps eliminate pointless tremors. | 1295 | * when it gets close to the target. Helps eliminate pointless tremors. |
1295 | */ | 1296 | */ |
1296 | step >>= dirty_ratelimit / (2 * step + 1); | 1297 | shift = dirty_ratelimit / (2 * step + 1); |
1297 | /* | 1298 | if (shift < BITS_PER_LONG) |
1298 | * Limit the tracking speed to avoid overshooting. | 1299 | step = DIV_ROUND_UP(step >> shift, 8); |
1299 | */ | 1300 | else |
1300 | step = (step + 7) / 8; | 1301 | step = 0; |
1301 | 1302 | ||
1302 | if (dirty_ratelimit < balanced_dirty_ratelimit) | 1303 | if (dirty_ratelimit < balanced_dirty_ratelimit) |
1303 | dirty_ratelimit += step; | 1304 | dirty_ratelimit += step; |