Commit 257313b2a87795e07a0bdf58d0fffbdba8b31051
1 parent
044aea9b83
Exists in
master
and in
39 other branches
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>
Showing 3 changed files with 11 additions and 9 deletions Side-by-side Diff
security/selinux/avc.c
... | ... | @@ -343,11 +343,10 @@ |
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) |
... | ... | @@ -765,7 +764,7 @@ |
765 | 764 | rcu_read_lock(); |
766 | 765 | |
767 | 766 | node = avc_lookup(ssid, tsid, tclass); |
768 | - if (!node) { | |
767 | + if (unlikely(!node)) { | |
769 | 768 | rcu_read_unlock(); |
770 | 769 | |
771 | 770 | if (in_avd) |
security/selinux/include/avc.h
security/selinux/selinuxfs.c
... | ... | @@ -1380,10 +1380,14 @@ |
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 |