Commit dee96113 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] shrink_slab: math precision fix

From: Nick Piggin <piggin@cyberone.com.au>

In shrink_slab(), do the multiply before the divide to avoid losing
precision.
parent 29d8c59c
...@@ -135,7 +135,7 @@ EXPORT_SYMBOL(remove_shrinker); ...@@ -135,7 +135,7 @@ EXPORT_SYMBOL(remove_shrinker);
* *
* We do weird things to avoid (scanned*seeks*entries) overflowing 32 bits. * We do weird things to avoid (scanned*seeks*entries) overflowing 32 bits.
*/ */
static int shrink_slab(long scanned, unsigned int gfp_mask) static int shrink_slab(unsigned long scanned, unsigned int gfp_mask)
{ {
struct shrinker *shrinker; struct shrinker *shrinker;
long pages; long pages;
...@@ -147,7 +147,7 @@ static int shrink_slab(long scanned, unsigned int gfp_mask) ...@@ -147,7 +147,7 @@ static int shrink_slab(long scanned, unsigned int gfp_mask)
list_for_each_entry(shrinker, &shrinker_list, list) { list_for_each_entry(shrinker, &shrinker_list, list) {
unsigned long long delta; unsigned long long delta;
delta = 4 * (scanned / shrinker->seeks); delta = (4 * scanned) / shrinker->seeks;
delta *= (*shrinker->shrinker)(0, gfp_mask); delta *= (*shrinker->shrinker)(0, gfp_mask);
do_div(delta, pages + 1); do_div(delta, pages + 1);
shrinker->nr += delta; shrinker->nr += delta;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment