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

selinux: avoid unnecessary avc cache stat hit count

There is no point in counting hits - we can calculate it from the number
of lookups and misses.

This makes the avc statistics a bit smaller, and makes the code
generation better too.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+11 -9
+4 -5
security/selinux/avc.c
··· 343 343 node = avc_search_node(ssid, tsid, tclass); 344 344 345 345 if (node) 346 - avc_cache_stats_incr(hits); 347 - else 348 - avc_cache_stats_incr(misses); 346 + return node; 349 347 350 - return node; 348 + avc_cache_stats_incr(misses); 349 + return NULL; 351 350 } 352 351 353 352 static int avc_latest_notif_update(int seqno, int is_insert) ··· 764 765 rcu_read_lock(); 765 766 766 767 node = avc_lookup(ssid, tsid, tclass); 767 - if (!node) { 768 + if (unlikely(!node)) { 768 769 rcu_read_unlock(); 769 770 770 771 if (in_avd)
-1
security/selinux/include/avc.h
··· 41 41 */ 42 42 struct avc_cache_stats { 43 43 unsigned int lookups; 44 - unsigned int hits; 45 44 unsigned int misses; 46 45 unsigned int allocations; 47 46 unsigned int reclaims;
+7 -3
security/selinux/selinuxfs.c
··· 1380 1380 if (v == SEQ_START_TOKEN) 1381 1381 seq_printf(seq, "lookups hits misses allocations reclaims " 1382 1382 "frees\n"); 1383 - else 1384 - seq_printf(seq, "%u %u %u %u %u %u\n", st->lookups, 1385 - st->hits, st->misses, st->allocations, 1383 + else { 1384 + unsigned int lookups = st->lookups; 1385 + unsigned int misses = st->misses; 1386 + unsigned int hits = lookups - misses; 1387 + seq_printf(seq, "%u %u %u %u %u %u\n", lookups, 1388 + hits, misses, st->allocations, 1386 1389 st->reclaims, st->frees); 1390 + } 1387 1391 return 0; 1388 1392 } 1389 1393