Skip to content

Commit 044aea9

Browse files
committed
selinux: de-crapify avc cache stat code generation
You can turn off the avc cache stats, but distributions seem to not do that (perhaps because several performance tuning how-to's talk about the avc cache statistics). Which is sad, because the code it generates is truly horrendous, with the statistics update being sandwitched between get_cpu/put_cpu which in turn causes preemption disables etc. We're talking ten+ instructions just to increment a per-cpu variable in some pretty hot code. Fix the craziness by just using 'this_cpu_inc()' instead. Suddenly we only need a single 'inc' instruction to increment the statistics. This is quite noticeable in the incredibly hot avc_has_perm_noaudit() function (which triggers all the statistics by virtue of doing an avc_lookup() call). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 39ab05c commit 044aea9

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

‎security/selinux/avc.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@
3838
#define AVC_CACHE_RECLAIM 16
3939

4040
#ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
41-
#define avc_cache_stats_incr(field) \
42-
do { \
43-
per_cpu(avc_cache_stats, get_cpu()).field++; \
44-
put_cpu(); \
45-
} while (0)
41+
#define avc_cache_stats_incr(field) this_cpu_inc(avc_cache_stats.field)
4642
#else
4743
#define avc_cache_stats_incr(field) do {} while (0)
4844
#endif

0 commit comments

Comments
 (0)