From: Ingo Molnar Bela found the following bug: touch_cache() only touched 2 thirds of the cache buffer (hence wasting memory and possibly making calibration less accurate). Fixes http://bugzilla.kernel.org/show_bug.cgi?id=7476 Signed-off-by: Ingo Molnar Cc: Bela Lubkin Signed-off-by: Andrew Morton --- kernel/sched.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff -puN kernel/sched.c~sched-fix-migration-cost-estimator kernel/sched.c --- a/kernel/sched.c~sched-fix-migration-cost-estimator +++ a/kernel/sched.c @@ -5738,14 +5738,24 @@ static void touch_cache(void *__cache, u unsigned long *cache = __cache; int i; + /* + * We access the buffer via 6 independent 'streams' of + * read/write access which are interleaved: + * + * [---> <---|---> <---|---> <---] + * + * We touch every cacheline in the buffer. (iteration + * step is 32 bytes on 32-bit systems, 64 bytes on + * 64-bit systems) + */ for (i = 0; i < size/6; i += 8) { - switch (i % 6) { - case 0: cache[i]++; - case 1: cache[size-1-i]++; - case 2: cache[chunk1-i]++; - case 3: cache[chunk1+i]++; - case 4: cache[chunk2-i]++; - case 5: cache[chunk2+i]++; + switch (i % 6*8) { + case 0*8: cache[i]++; + case 1*8: cache[size-1-i]++; + case 2*8: cache[chunk1-i]++; + case 3*8: cache[chunk1+i]++; + case 4*8: cache[chunk2-i]++; + case 5*8: cache[chunk2+i]++; } } } _