All of lore.kernel.org
 help / color / mirror / Atom feed
From: KaiGai Kohei <kaigai@ak.jp.nec.com>
To: Eric Paris <eparis@redhat.com>
Cc: Paul Moore <paul.moore@hp.com>,
	selinux@tycho.nsa.gov, sds@tycho.nsa.gov, jmorris@namei.org
Subject: Re: [PATCH 1/5] SELinux: remove the unused ae.used
Date: Fri, 13 Feb 2009 15:45:15 +0900	[thread overview]
Message-ID: <499516FB.7090805@ak.jp.nec.com> (raw)
In-Reply-To: <1234470416.24008.3.camel@localhost.localdomain>

Eric Paris wrote:
> On Thu, 2009-02-12 at 15:15 -0500, Paul Moore wrote:
>> On Thursday 12 February 2009 02:50:43 pm Eric Paris wrote:
>>> Currently SELinux code has an atomic which was intended to track how many
>>> times an avc entry was used and to evict entries when they haven't been
>>> used recently.  Instead we never let this atomic get above 1 and evict when
>>> it is first checked for eviction since it hits zero.  This is a total waste
>>> of time so I'm completely dropping ae.used.
>>>
>>> This change resulted in about a 3% faster avc_has_perm_noaudit when running
>>> oprofile against a tbench benchmark.
>>>
>>> Signed-off-by: Eric Paris <eparis@redhat.com>
>> Looks okay to me, I did notice another optimization (see below) that might be 
>> worth including if you respin the patch.
>>
>> Reviewed by: Paul Moore <paul.moore@hp.com>
>>
>>>  struct avc_node {
>>> @@ -321,16 +320,13 @@ static inline int avc_reclaim_node(void)
>>>
>>>  		rcu_read_lock();
>>>  		list_for_each_entry(node, &avc_cache.slots[hvalue], list) {
>>> -			if (atomic_dec_and_test(&node->ae.used)) {
>>> -				/* Recently Unused */
>>> -				avc_node_delete(node);
>>> -				avc_cache_stats_incr(reclaims);
>>> -				ecx++;
>>> -				if (ecx >= AVC_CACHE_RECLAIM) {
>>> -					rcu_read_unlock();
>>> -					spin_unlock_irqrestore(&avc_cache.slots_lock[hvalue], flags);
>>> -					goto out;
>>> -				}
>>> +			avc_node_delete(node);
>>> +			avc_cache_stats_incr(reclaims);
>>> +			ecx++;
>>> +			if (ecx >= AVC_CACHE_RECLAIM) {
>>> +				rcu_read_unlock();
>>> +				spin_unlock_irqrestore(&avc_cache.slots_lock[hvalue], flags);
>>> +				goto out;
>>>  			}
>>>  		}
>>>  		rcu_read_unlock();
>> Not your fault, but in reviewing this code I realized we aren't really using 
>> the avc_cache.lru_hint atomic either; it looks like it is initialized to zero 
>> and never changes.  With that in mind we could remove the lru_hint field from 
>> the avc_cache and simplify the above function a tiny bit (no need for hvalue, 
>> just use zero).
> 
> My look says the the hvalue there is computed as:
> 
> hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
> 
> Which means it is changed....

This is an aside:

The purpose of avc_cache.lru_hint and AVC_CACHE_SLOTS (512) of spinlocks is
to reduce lock contention during avc_reclaim_node() and avc_insert().

In the reader side (more than 99.99%), we can refer avc_node without locks.
However, RCU requires to acquire locks when we modify linked objects, so
it is necessary to consider the possibility of scalability issue by lock
contention on writer side.
In this case, the purpose of avc_reclaim_node() is to reduce the number
of active avc_node, not to drop a specific one, so it is not necessary
to serialize all the threads which invokes avc_reclaim_node().

Any avc_cache.slots[] has its own spinlock. This design enables to insert
or reclaim independent avc_node in parallel as far as possible. For example,
CPU-1 can insert a new avc_node into the slot[5], even if CPU-2 holds a lock
on the slot[7] in same time.

The selinux/avc.c was rewritten at the kernel-2.6.11 using RCU, because
there was a scalability issue which protects all the reader/writer by a
single spinlock at that time, so we revised this code so carefully on
the viewpoint of scalability.

Thanks,
-- 
OSS Platform Development Division, NEC
KaiGai Kohei <kaigai@ak.jp.nec.com>

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

  reply	other threads:[~2009-02-13  6:45 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-12 19:50 [PATCH 1/5] SELinux: remove the unused ae.used Eric Paris
2009-02-12 19:50 ` [PATCH 2/5] SELinux: more careful use of avd in avc_has_perm_noaudit Eric Paris
2009-02-12 20:30   ` Paul Moore
2009-02-13 14:20   ` Stephen Smalley
2009-02-13 22:45   ` James Morris
2009-02-12 19:50 ` [PATCH 3/5] SELinux: remove unused av.decided field Eric Paris
2009-02-12 20:33   ` Paul Moore
2009-02-13 17:26   ` Stephen Smalley
2009-02-13 22:45   ` James Morris
2009-02-12 19:50 ` [PATCH 4/5] SELinux: code readability with avc_cache Eric Paris
2009-02-12 20:39   ` Paul Moore
2009-02-13 22:45   ` James Morris
2009-02-12 19:51 ` [PATCH 5/5] SELinux: convert the avc cache hash list to an hlist Eric Paris
2009-02-12 20:40   ` Paul Moore
2009-02-13 22:45   ` James Morris
2009-02-12 20:15 ` [PATCH 1/5] SELinux: remove the unused ae.used Paul Moore
2009-02-12 20:26   ` Eric Paris
2009-02-13  6:45     ` KaiGai Kohei [this message]
2009-02-13 14:12 ` Stephen Smalley
2009-02-13 22:44 ` James Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=499516FB.7090805@ak.jp.nec.com \
    --to=kaigai@ak.jp.nec.com \
    --cc=eparis@redhat.com \
    --cc=jmorris@namei.org \
    --cc=paul.moore@hp.com \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.