]> git.baikalelectronics.ru Git - kernel.git/commit
selinux: reduce the use of hard-coded hash sizes
authorOndrej Mosnacek <omosnace@redhat.com>
Wed, 26 Feb 2020 15:54:52 +0000 (16:54 +0100)
committerPaul Moore <paul@paul-moore.com>
Fri, 28 Feb 2020 00:23:20 +0000 (19:23 -0500)
commit88de4e1c48522b333f36f382f755b52456f76fae
treeb96a691c16032ea1f3c959034ef7fda70e59c3ef
parent5fdbf37ac17beac659997380520abffd3ec8ef2e
selinux: reduce the use of hard-coded hash sizes

Instead allocate hash tables with just the right size based on the
actual number of elements (which is almost always known beforehand, we
just need to defer the hashtab allocation to the right time). The only
case when we don't know the size (with the current policy format) is the
new filename transitions hashtable. Here I just left the existing value.

After this patch, the time to load Fedora policy on x86_64 decreases
from 790 ms to 167 ms. If the unconfined module is removed, it decreases
from 750 ms to 122 ms. It is also likely that other operations are going
to be faster, mainly string_to_context_struct() or mls_compute_sid(),
but I didn't try to quantify that.

The memory usage of all hash table arrays increases from ~58 KB to
~163 KB (with Fedora policy on x86_64).

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/hashtab.c
security/selinux/ss/hashtab.h
security/selinux/ss/policydb.c
security/selinux/ss/policydb.h