selinux: complete the inlining of hashtab functions
authorOndrej Mosnacek <omosnace@redhat.com>
Thu, 9 Jul 2020 19:19:52 +0000 (21:19 +0200)
committerPaul Moore <paul@paul-moore.com>
Thu, 9 Jul 2020 23:08:16 +0000 (19:08 -0400)
commit54b27f9287a7b3dfc85549f01fc9d292c92c68b9
tree199b02edb0cb7db79325043e7de30761a8ef8b78
parent24def7bb92c19337cee26d506f87dc4eeeba7a19
selinux: complete the inlining of hashtab functions

Move (most of) the definitions of hashtab_search() and hashtab_insert()
to the header file. In combination with the previous patch, this avoids
calling the callbacks indirectly by function pointers and allows for
better optimization, leading to a drastic performance improvement of
these operations.

With this patch, I measured a speed up in the following areas (measured
on x86_64 F32 VM with 4 CPUs):
  1. Policy load (`load_policy`) - takes ~150 ms instead of ~230 ms.
  2. `chcon -R unconfined_u:object_r:user_tmp_t:s0:c381,c519 /tmp/linux-src`
     where /tmp/linux-src is an extracted linux-5.7 source tarball -
     takes ~522 ms instead of ~576 ms. This is because of many
     symtab_search() calls in string_to_context_struct() when there are
     many categories specified in the context.
  3. `stress-ng --msg 1 --msg-ops 10000000` - takes 12.41 s instead of
     13.95 s (consumes 18.6 s of kernel CPU time instead of 21.6 s).
     This is thanks to security_transition_sid() being ~43% faster after
     this patch.

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/hashtab.c
security/selinux/ss/hashtab.h