mbox series

[v3,0/3] Inline some hashtab functions to improve performance

Message ID 20200708112447.292321-1-omosnace@redhat.com (mailing list archive)
Headers show
Series Inline some hashtab functions to improve performance | expand

Message

Ondrej Mosnacek July 8, 2020, 11:24 a.m. UTC
Right now, hashtab_search() and hashtab_insert() are defined in
hashtab.c and need to call functions indirectly via function
pointers. It turns out that defining (the relevent parts of) these
functions inline in the header and passing the function pointers as
arguments makes them significantly faster.

The first patch is a minor refactoring of symtab usage in preparation
for the next patch. The second patch modifies the hashtab interface so
that callbacks are always passed directly. The last patch finishes the
job by moving some of the function definitions to the header.

The last two patches could be also just one patch, but are kept separate
for easier review of changes in the functions that are being moved
around.

For more details, please refer to the respective patch descriptions.

Changes in v3:
 - add perf numbers for two more use cases positively affected: policy
   load and MCS relabeling
 - drop inlining of hashtab_map() (perf-testing that change alone showed
   zero difference in both policy load and relabeling time)
 - reword the commit message of patch 2

I intended to refactor the code to hide the awkward hashtab funcions
away, but it turned out the result would be even more messy than the
current version, so I left the other code unchanged from v2. I do
believe the performance gain is worth making the hashtab interface more
low-level.

Changes in v2:
 - drop already applied v1 patches 1 and 2
 - reword patch descriptions to better explain what is going on and why
 - split out some of the symtab changes into a separate patch
 - tweak the signature and argument names of symtab_insert()

Ondrej Mosnacek (3):
  selinux: specialize symtab insert and search functions
  selinux: prepare for inlining of hashtab functions
  selinux: complete the inlining of hashtab functions

 security/selinux/ss/conditional.c |   4 +-
 security/selinux/ss/conditional.h |   2 +-
 security/selinux/ss/hashtab.c     |  59 ++------------
 security/selinux/ss/hashtab.h     |  77 +++++++++++++++---
 security/selinux/ss/mls.c         |  23 +++---
 security/selinux/ss/policydb.c    | 128 +++++++++++++++++++-----------
 security/selinux/ss/policydb.h    |   9 +++
 security/selinux/ss/services.c    |  38 ++++-----
 security/selinux/ss/symtab.c      |  21 ++++-
 security/selinux/ss/symtab.h      |   3 +
 10 files changed, 214 insertions(+), 150 deletions(-)