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 08:50:31 -0500	[thread overview]
Message-ID: <54B522A7.2080109@tycho.nsa.gov> (raw)
In-Reply-To: <A906E10A-6726-4208-993B-4D6AB21B202E@jolla.com>

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.

> 
>>
>> I've also considered reworking the libsepol check_assertions() code to
>> not expand the avtab in order to provide better traceback to the
>> original source allow rule that violated the neverallow.  This would
>> require more work by check_assertion_helper to check each attribute
>> associated with the source and target, just as with
>> context_struct_compute_av.
> 
> Yeah; I expect there is a lot of room for algorithmic improvement here.
> I wish I had time to understand and fix it. We could probably get this
> running on the order of seconds instead of minutes, and using _much_
> less memory.
> 
> Even after these patches, expand_module spends 60% in avtab_search_node
> (and 13% malloc_consolidate, the rest is trivial). Next step would be to
> reduce the number of elements or lookups.
> 
> One interesting note: this fully expanded table is built twice under
> expand_module, for hierarchy_check_constraints and check_assertions. We
> could cut runtime almost in half by reusing the table.

Yes, they were originally written to permit running them independently,
so certainly when they are both run, we could avoid that duplication.

  reply	other threads:[~2015-01-13 13:50 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 [this message]
2015-01-13 14:00         ` Stephen Smalley
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=54B522A7.2080109@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.