Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

futex: Force hot variables into a single cache line

futex_hash() references two global variables: the base pointer
futex_queues and the size of the array futex_hashsize. The latter is
marked __read_mostly, while the former is not, so they are likely to
end up very far from each other. This means that futex_hash() is
likely to encounter two cache misses.

We could mark futex_queues as __read_mostly as well, but that doesn't
guarantee they'll end up next to each other (and even if they do, they
may still end up in different cache lines). So put the two variables
in a small singleton struct with sufficient alignment and mark that as
__read_mostly.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: kbuild test robot <fengguang.wu@intel.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: http://lkml.kernel.org/r/1441834601-13633-1-git-send-email-linux@rasmusvillemoes.dk
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

authored by

Rasmus Villemoes and committed by
Thomas Gleixner
ac742d37 93edc8bd

+11 -2
+11 -2
kernel/futex.c
··· 255 255 struct plist_head chain; 256 256 } ____cacheline_aligned_in_smp; 257 257 258 - static unsigned long __read_mostly futex_hashsize; 258 + /* 259 + * The base of the bucket array and its size are always used together 260 + * (after initialization only in hash_futex()), so ensure that they 261 + * reside in the same cacheline. 262 + */ 263 + static struct { 264 + struct futex_hash_bucket *queues; 265 + unsigned long hashsize; 266 + } __futex_data __read_mostly __aligned(2*sizeof(long)); 267 + #define futex_queues (__futex_data.queues) 268 + #define futex_hashsize (__futex_data.hashsize) 259 269 260 - static struct futex_hash_bucket *futex_queues; 261 270 262 271 /* 263 272 * Fault injections for futexes.