]> git.ipfire.org Git - thirdparty/openssl.git/commit
Introduce new internal hashtable implementation
authorNeil Horman <nhorman@openssl.org>
Sun, 28 Jan 2024 15:50:38 +0000 (10:50 -0500)
committerPauli <ppzgs1@gmail.com>
Wed, 24 Apr 2024 02:03:30 +0000 (12:03 +1000)
commitcc4ea5e00028e8e0fe3acbf5027497c077f84446
tree8230073fa847312b71b0537acd8fffa7e063f660
parent7e45ac6891ade57cb0141402745d144c4ce342cb
Introduce new internal hashtable implementation

Create a new hashtable that is more efficient than the existing LHASH_OF
implementation.  the new ossl_ht api offers several new features that
improve performance opportunistically

* A more generalized hash function.  Currently using fnv1a, provides a
  more general hash function, but can still be overridden where needed

* Improved locking and reference counting.  This hash table is
  internally locked with an RCU lock, and optionally reference counts
  elements, allowing for users to not have to create and manage their
  own read/write locks

* Lockless operation.  The hash table can be configured to operate
  locklessly on the read side, improving performance, at the sacrifice
  of the ability to grow the hash table or delete elements from it

* A filter function allowing for the retrieval of several elements at a
  time matching a given criteria without having to hold a lock
  permanently

* a doall_until iterator variant, that allows callers which need to
  iterate over the entire hash table until a given condition is met (as
  defined by the return value of the iterator callback).  This allows
  for callers attempting to do expensive cache searches for a small
  number of elements to terminate the iteration early, saving cpu cycles

* Dynamic type safety.  The hash table provides operations to set and
  get data of a specific type without having to define a type at the
  instatiation point

* Multiple data type storage.  The hash table can store multiple data
  types allowing for more flexible usage

* Ubsan safety.  Because the API deals with concrete single types
  (HT_KEY and HT_VALUE), leaving specific type casting to the call
  recipient with dynamic type validation, this implementation is safe
  from the ubsan undefined behavior warnings that require additional
  thunking on callbacks.

Testing of this new hashtable with an equivalent hash function, I can
observe approximately a 6% performance improvement in the lhash_test

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23671)
14 files changed:
crypto/build.info
crypto/hashtable/build.info [new file with mode: 0644]
crypto/hashtable/hashtable.c [new file with mode: 0644]
crypto/mem.c
doc/internal/man3/ossl_ht_new.pod [new file with mode: 0644]
doc/man3/CRYPTO_THREAD_run_once.pod
doc/man3/OPENSSL_malloc.pod
include/internal/hashtable.h [new file with mode: 0644]
include/openssl/crypto.h.in
test/build.info
test/lhash_test.c
util/libcrypto.num
util/other.syms
util/platform_symbols/unix-symbols.txt