All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: John Brooks <john.brooks@jolla.com>
Cc: "selinux@tycho.nsa.gov" <selinux@tycho.nsa.gov>
Subject: Re: [PATCH 3/3] Tweak avtab hash table parameters for better performance
Date: Tue, 13 Jan 2015 09:00:28 -0500	[thread overview]
Message-ID: <54B524FC.9050908@tycho.nsa.gov> (raw)
In-Reply-To: <54B522A7.2080109@tycho.nsa.gov>

On 01/13/2015 08:50 AM, Stephen Smalley wrote:
> On 01/12/2015 08:25 PM, John Brooks wrote:
>> On Jan 12, 2015, at 10:47 AM, Stephen Smalley <sds@tycho.nsa.gov
>> <mailto:sds@tycho.nsa.gov>> wrote:
>>>
>>> On 01/07/2015 05:03 PM, John Brooks wrote:
>>>> @@ -341,8 +341,6 @@ int avtab_alloc(avtab_t *h, uint32_t nrules)
>>>> work  = work >> 1;
>>>> shift++;
>>>> }
>>>> -if (shift > 2)
>>>> -shift = shift - 2;
>>>> nslot = 1 << shift;
>>>> if (nslot > MAX_AVTAB_SIZE)
>>>> nslot = MAX_AVTAB_SIZE;
>>>>
>>>
>>> tweakavtab.txt:rules:  101401 entries and 68460/131072 buckets used,
>>> longest chain length 7
>>>
>>> Seems like we're wasting a large number of buckets in that scenario.
>>
>> Good catch. It looks like this is caused by the segment I highlighted
>> above, removing the shift adjustment.
>>
>> changed-nslot.txt:rules:  100967 entries and 68321/131072 buckets used,
>> longest chain length 8
>> original-nslot.txt:rules:  100967 entries and 31017/32768 buckets used,
>> longest chain length 13
>>
>> So, one bucket is allocated per 2-4 elements. The change I actually
>> wanted to make is to the definition of MAX_AVTAB_SIZE: it should be 2x
>> MAX_AVTAB_HASH_BUCKETS to allow allocating a hash with maximum buckets,
>> and that nslot bounding should use MAX_AVTAB_HASH_BUCKETS.
>>
>>>
>>> Also, in the corresponding kernel code (security/selinux/ss/avtab.[hc]),
>>> we've actually shrunk the hash bits from 13 to 11,
>>
>> Interesting. I wonder what the kernel hash eval looks like - it might
>> benefit from a better hash function as well.
> 
> Permission checks in the kernel are usually handled by the AVC (access
> vector cache), so the looking it up in the avtab is the slow path already.

That said, it wouldn't hurt to look at improving the hash function there
as well, and possibly for the AVC too.

One thing to note is that we never envisioned such large policies when
we created SELinux (the original example policy was much smaller).  The
Fedora policy unfortunately ships with every possible module/domain that
one could ever use included, and does not attempt to reduce the policy
to only the subset required for the given system.  Admittedly that is a
hard problem.  In the Android case, we were careful to keep the policy
small from the beginning, but there we have a much smaller and more
constrained userspace environment.

  reply	other threads:[~2015-01-13 14:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-07 22:03 [PATCH 0/3] Improve check_assertions performance through hash tweaks John Brooks
2015-01-07 22:03 ` [PATCH 1/3] Build libsepol with -O2 John Brooks
2015-01-12 17:01   ` Stephen Smalley
2015-01-07 22:03 ` [PATCH 2/3] Use a better hash function for libsepol's avtab John Brooks
2015-01-12 17:30   ` Stephen Smalley
2015-01-13  1:38     ` John Brooks
2015-01-13 13:53       ` Stephen Smalley
2015-01-07 22:03 ` [PATCH 3/3] Tweak avtab hash table parameters for better performance John Brooks
2015-01-12 17:47   ` Stephen Smalley
2015-01-12 17:55     ` Stephen Smalley
2015-01-12 20:07     ` Stephen Smalley
2015-01-13  1:25     ` John Brooks
2015-01-13 13:50       ` Stephen Smalley
2015-01-13 14:00         ` Stephen Smalley [this message]
2015-01-15  0:24 ` [PATCH v2 0/3] Improve check_assertions performance through hash tweaks John Brooks
2015-01-15  0:24   ` [PATCH v2 1/3] Build libsepol with -O2 John Brooks
2015-01-15  0:24   ` [PATCH v2 2/3] Use a better hash function for libsepol's avtab John Brooks
2015-01-15  0:24   ` [PATCH v2 3/3] Tweak avtab hash table parameters for better performance John Brooks
2015-01-15 18:56   ` [PATCH v2 0/3] Improve check_assertions performance through hash tweaks Stephen Smalley

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=54B524FC.9050908@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=john.brooks@jolla.com \
    --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.