]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
selinux: avoid unnecessary avc cache stat hit count
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 20 May 2011 04:22:53 +0000 (21:22 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 20 May 2011 04:22:53 +0000 (21:22 -0700)
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>
security/selinux/avc.c
security/selinux/include/avc.h
security/selinux/selinuxfs.c

index 5971e30e8239c90f107f768a47f5c1963d9efb3e..3d2715fd35ea4c8dc11b580a7ee1fb946b9c4257 100644 (file)
@@ -343,11 +343,10 @@ static struct avc_node *avc_lookup(u32 ssid, u32 tsid, u16 tclass)
        node = avc_search_node(ssid, tsid, tclass);
 
        if (node)
-               avc_cache_stats_incr(hits);
-       else
-               avc_cache_stats_incr(misses);
+               return node;
 
-       return node;
+       avc_cache_stats_incr(misses);
+       return NULL;
 }
 
 static int avc_latest_notif_update(int seqno, int is_insert)
@@ -765,7 +764,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
        rcu_read_lock();
 
        node = avc_lookup(ssid, tsid, tclass);
-       if (!node) {
+       if (unlikely(!node)) {
                rcu_read_unlock();
 
                if (in_avd)
index e77b2ac2908b7f754113bb6dd5023427da5f35fb..47fda963495ddc0c5fa8f0d36468dff014035764 100644 (file)
@@ -41,7 +41,6 @@ struct sk_buff;
  */
 struct avc_cache_stats {
        unsigned int lookups;
-       unsigned int hits;
        unsigned int misses;
        unsigned int allocations;
        unsigned int reclaims;
index ea39cb742ae5b0422d90643024ce8a3bf812973f..c0e1a0f524624c97b3f5950df74c04ab2269212c 100644 (file)
@@ -1380,10 +1380,14 @@ static int sel_avc_stats_seq_show(struct seq_file *seq, void *v)
        if (v == SEQ_START_TOKEN)
                seq_printf(seq, "lookups hits misses allocations reclaims "
                           "frees\n");
-       else
-               seq_printf(seq, "%u %u %u %u %u %u\n", st->lookups,
-                          st->hits, st->misses, st->allocations,
+       else {
+               unsigned int lookups = st->lookups;
+               unsigned int misses = st->misses;
+               unsigned int hits = lookups - misses;
+               seq_printf(seq, "%u %u %u %u %u %u\n", lookups,
+                          hits, misses, st->allocations,
                           st->reclaims, st->frees);
+       }
        return 0;
 }