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

blockgroup_lock.h: simplify definition of NR_BG_LOCKS

We can use ilog2() to more easily produce the desired NR_BG_LOCKS. This
works because ilog2() is evaluated at compile-time when its argument is
a compile-time constant.

I did not change the chosen NR_BG_LOCKS values.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>

authored by

Eric Biggers and committed by
Theodore Ts'o
7c5f6b32 9e5ab85d

+2 -20
+2 -20
include/linux/blockgroup_lock.h
··· 10 10 #include <linux/cache.h> 11 11 12 12 #ifdef CONFIG_SMP 13 - 14 - /* 15 - * We want a power-of-two. Is there a better way than this? 16 - */ 17 - 18 - #if NR_CPUS >= 32 19 - #define NR_BG_LOCKS 128 20 - #elif NR_CPUS >= 16 21 - #define NR_BG_LOCKS 64 22 - #elif NR_CPUS >= 8 23 - #define NR_BG_LOCKS 32 24 - #elif NR_CPUS >= 4 25 - #define NR_BG_LOCKS 16 26 - #elif NR_CPUS >= 2 27 - #define NR_BG_LOCKS 8 13 + #define NR_BG_LOCKS (4 << ilog2(NR_CPUS < 32 ? NR_CPUS : 32)) 28 14 #else 29 - #define NR_BG_LOCKS 4 30 - #endif 31 - 32 - #else /* CONFIG_SMP */ 33 15 #define NR_BG_LOCKS 1 34 - #endif /* CONFIG_SMP */ 16 + #endif 35 17 36 18 struct bgl_lock { 37 19 spinlock_t lock;