selinux: reduce locking overhead in inode_free_security()
selinux: reduce locking overhead in inode_free_security()

The inode_free_security() function just took the superblock's isec_lock
before checking and trying to remove the inode security struct from the
linked list. In many cases, the list was empty and so the lock taking
is wasteful as no useful work is done. On multi-socket systems with
a large number of CPUs, there can also be a fair amount of spinlock
contention on the isec_lock if many tasks are exiting at the same time.

This patch changes the code to check the state of the list first before
taking the lock and attempting to dequeue it. The list_del_init()
can be called more than once on the same list with no harm as long
as they are properly serialized. It should not be possible to have
inode_free_security() called concurrently with list_add(). For better
safety, however, we use list_empty_careful() here even though it is
still not completely safe in case that happens.

Signed-off-by: Waiman Long <a123fdd9fb50e93f03393cfddab9c182b4164439@hp.com>
Acked-by: Stephen Smalley <d6e1285e1c84d3d5885c2124fdacc780e9fc0a94@tycho.nsa.gov>
Signed-off-by: Paul Moore <88a1d58bf22a647dce58dd91f9595600dceabba9@redhat.com>

KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs