From: Alexander Monakov <amonakov@ispras.ru>
To: musl@lists.openwall.com
Subject: [PATCH v2 2/6] dynlink.c: use bloom filter in gnu hash lookup
Date: Sun, 28 Jun 2015 02:48:31 +0300 [thread overview]
Message-ID: <1435448915-28419-3-git-send-email-amonakov@ispras.ru> (raw)
In-Reply-To: <1435448915-28419-1-git-send-email-amonakov@ispras.ru>
Introduce gnu_lookup_filtered and use it to speed up symbol lookups in
find_sym (do_dlsym is left as is, based on an expectation that frequently
dlsym queries will use a dlopen handle rather than RTLD_NEXT or RTLD_DEFAULT,
and will not need to look at more than one DSO).
---
src/ldso/dynlink.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index 0df81f2..b08596e 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -200,6 +200,19 @@ static Sym *gnu_lookup(const char *s, uint32_t h1, struct dso *dso)
return 0;
}
+static Sym *gnu_lookup_filtered(const char *s, uint32_t h1, struct dso *dso, uint32_t fofs, size_t fmask)
+{
+ uint32_t *hashtab = dso->ghashtab;
+ const size_t *bloomwords = (const void *)(hashtab+4);
+ size_t f = bloomwords[fofs & (hashtab[2]-1)];
+ if (!(f & fmask)) return 0;
+
+ f >>= (h1 >> hashtab[3]) % (8 * sizeof f);
+ if (!(f & 1)) return 0;
+
+ return gnu_lookup(s, h1, dso);
+}
+
#define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON | 1<<STT_TLS)
#define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
@@ -209,14 +222,20 @@ static Sym *gnu_lookup(const char *s, uint32_t h1, struct dso *dso)
static struct symdef find_sym(struct dso *dso, const char *s, int need_def)
{
- uint32_t h = 0, gh = 0;
+ uint32_t h = 0, gh, gho;
+ size_t ghm = 0;
struct symdef def = {0};
for (; dso; dso=dso->next) {
Sym *sym;
if (!dso->global) continue;
if (dso->ghashtab) {
- if (!gh) gh = gnu_hash(s);
- sym = gnu_lookup(s, gh, dso);
+ if (!ghm) {
+ gh = gnu_hash(s);
+ int maskbits = 8 * sizeof ghm;
+ gho = gh / maskbits;
+ ghm = 1ul << gh % maskbits;
+ }
+ sym = gnu_lookup_filtered(s, gh, dso, gho, ghm);
} else {
if (!h) h = sysv_hash(s);
sym = sysv_lookup(s, h, dso);
next prev parent reply other threads:[~2015-06-27 23:48 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-23 23:24 [PATCH 0/5] gnu-hash speedups Alexander Monakov
2015-06-23 23:24 ` [PATCH 1/5] dynlink.c: use bloom filter in gnu hash lookup Alexander Monakov
2015-06-24 5:39 ` Rich Felker
2015-06-24 6:29 ` Alexander Monakov
2015-06-24 6:32 ` Alexander Monakov
2015-06-24 6:50 ` Rich Felker
2015-06-23 23:24 ` [PATCH 2/5] dynlink.c: compute modulus via magic multiplication Alexander Monakov
2015-06-24 4:18 ` Alexander Monakov
2015-06-24 4:19 ` Rich Felker
2015-06-24 4:24 ` Rich Felker
2015-06-24 4:32 ` Alexander Monakov
2015-06-24 5:13 ` Rich Felker
2015-06-24 6:08 ` Alexander Monakov
2015-06-24 6:39 ` Rich Felker
2015-06-23 23:24 ` [PATCH 3/5] dynlink.c: slim down gnu_lookup Alexander Monakov
2015-06-23 23:24 ` [PATCH 4/5] dynlink.c: pass gnu-hash table pointer to gnu_lookup Alexander Monakov
2015-06-23 23:24 ` [PATCH 5/5] dynlink.c: use a faster expression in gnu_hash Alexander Monakov
2015-06-27 23:48 ` [PATCH v2 0/6] gnu-hash speedups Alexander Monakov
2015-06-27 23:48 ` [PATCH v2 1/6] dynlink.c: use a faster expression in gnu_hash Alexander Monakov
2015-06-27 23:48 ` Alexander Monakov [this message]
2015-06-27 23:48 ` [PATCH v2 3/6] dynlink.c: slim down gnu_lookup Alexander Monakov
2015-06-27 23:48 ` [PATCH v2 4/6] dynlink.c: pass gnu-hash table pointer to gnu_lookup Alexander Monakov
2015-06-28 0:05 ` Alexander Monakov
2015-06-28 8:59 ` Alexander Monakov
2015-06-27 23:48 ` [PATCH v2 5/6] dynlink.c: compute modulus via magic multiplication Alexander Monakov
2015-06-30 17:51 ` Rich Felker
2015-06-27 23:48 ` [PATCH v2 6/6] dynlink.c: store bloom filter size in struct dso Alexander Monakov
2015-06-28 2:45 ` [PATCH v2 0/6] gnu-hash speedups Rich Felker
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=1435448915-28419-3-git-send-email-amonakov@ispras.ru \
--to=amonakov@ispras.ru \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).