All of lore.kernel.org
 help / color / mirror / Atom feed
From: Valerie Aurora Henson <vaurora@redhat.com>
To: Jeff Moyer <jmoyer@redhat.com>, Paul Wankadia <junyer@google.com>
Cc: autofs@linux.kernel.org
Subject: Re: [PATCH 1/4] Make hash table scale to thousands of entries
Date: Fri, 9 Jan 2009 14:51:51 -0500	[thread overview]
Message-ID: <20090109195151.GH32333@shell> (raw)
In-Reply-To: <x49mye0ffvg.fsf@segfault.boston.devel.redhat.com>

On Fri, Jan 09, 2009 at 02:17:55PM -0500, Jeff Moyer wrote:
> Valerie Aurora Henson <vaurora@redhat.com> writes:
> > From: Paul Wankadia <junyer@google.com>
> > Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
> 
> Most patches of this nature come with some description of a performance
> problem and how the patch solves it.  Which caching algorithm is
> implemented below?  There are, of course, many hashing algorithms for
> variable length strings.  Can we get some rationale for the change?  I'm
> not against it, I'd just like a *little* explanation.

This is where I get to blame my cold for being stupid. :) 

Yes, the original author (Paul Wankadia, now cc'd) gave me a little
information on that front, I just forgot to pass it on.  It's the
"One-at-a-Time" hash function by Bob Jenkins. See:

http://burtleburtle.net/bob/hash/doobs.html

What I vaguely recall from our conversation is an order of magnitude
improvement in elapsed time for large (thousands) numbers of maps, but
I'll let Paul be more specific.  Do we have a test for thousands of
entries somewhere in our automated tests?

-VAL

> 
> Cheers,
> Jeff
> 
> > ---
> >  include/automount.h |    2 +-
> >  lib/cache.c         |   29 ++++++++++++++++++-----------
> >  2 files changed, 19 insertions(+), 12 deletions(-)
> >
> > diff --git a/include/automount.h b/include/automount.h
> > index 1ba0d3c..2a082b5 100644
> > --- a/include/automount.h
> > +++ b/include/automount.h
> > @@ -126,7 +126,7 @@ struct autofs_point;
> >  #define CHE_DUPLICATE	0x0020
> >  #define CHE_UNAVAIL	0x0040
> >  
> > -#define HASHSIZE		77
> > +#define HASHSIZE		4096
> >  #define NEGATIVE_TIMEOUT	10
> >  #define UMOUNT_RETRIES		8
> >  #define EXPIRE_RETRIES		3
> > diff --git a/lib/cache.c b/lib/cache.c
> > index ce47e04..36b8294 100644
> > --- a/lib/cache.c
> > +++ b/lib/cache.c
> > @@ -281,20 +281,27 @@ struct mapent_cache *cache_init_null_cache(struct master *master)
> >  	return mc;
> >  }
> >  
> > -static unsigned int hash(const char *key)
> > +static u_int32_t hash(const char *key)
> >  {
> > -	unsigned long hashval;
> > +	u_int32_t hashval;
> >  	char *s = (char *) key;
> >  
> > -	for (hashval = 0; *s != '\0';)
> > -		hashval += *s++;
> > +	for (hashval = 0; *s != '\0';) {
> > +		hashval += (unsigned char) *s++;
> > +		hashval += (hashval << 10);
> > +		hashval ^= (hashval >> 6);
> > +	}
> > +
> > +	hashval += (hashval << 3);
> > +	hashval ^= (hashval >> 11);
> > +	hashval += (hashval << 15);
> >  
> >  	return hashval % HASHSIZE;
> >  }
> >  
> > -static unsigned int ino_hash(dev_t dev, ino_t ino)
> > +static u_int32_t ino_hash(dev_t dev, ino_t ino)
> >  {
> > -	unsigned long hashval;
> > +	u_int32_t hashval;
> >  
> >  	hashval = dev + ino;
> >  
> > @@ -303,7 +310,7 @@ static unsigned int ino_hash(dev_t dev, ino_t ino)
> >  
> >  int cache_set_ino_index(struct mapent_cache *mc, const char *key, dev_t dev, ino_t ino)
> >  {
> > -	unsigned int ino_index = ino_hash(dev, ino);
> > +	u_int32_t ino_index = ino_hash(dev, ino);
> >  	struct mapent *me;
> >  
> >  	me = cache_lookup_distinct(mc, key);
> > @@ -325,7 +332,7 @@ struct mapent *cache_lookup_ino(struct mapent_cache *mc, dev_t dev, ino_t ino)
> >  {
> >  	struct mapent *me = NULL;
> >  	struct list_head *head, *p;
> > -	unsigned int ino_index;
> > +	u_int32_t ino_index;
> >  
> >  	ino_index_lock(mc);
> >  	ino_index = ino_hash(dev, ino);
> > @@ -371,7 +378,7 @@ struct mapent *cache_lookup_first(struct mapent_cache *mc)
> >  struct mapent *cache_lookup_next(struct mapent_cache *mc, struct mapent *me)
> >  {
> >  	struct mapent *this;
> > -	unsigned long hashval;
> > +	u_int32_t hashval;
> >  	unsigned int i;
> >  
> >  	if (!me)
> > @@ -532,7 +539,7 @@ int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, c
> >  {
> >  	struct mapent *me, *existing = NULL;
> >  	char *pkey, *pent;
> > -	unsigned int hashval = hash(key);
> > +	u_int32_t hashval = hash(key);
> >  	int status;
> >  
> >  	me = (struct mapent *) malloc(sizeof(struct mapent));
> > @@ -752,7 +759,7 @@ int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key
> >  int cache_delete(struct mapent_cache *mc, const char *key)
> >  {
> >  	struct mapent *me = NULL, *pred;
> > -	unsigned int hashval = hash(key);
> > +	u_int32_t hashval = hash(key);
> >  	int status, ret = CHE_OK;
> >  	char *this;

  reply	other threads:[~2009-01-09 19:51 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-09 18:46 [PATCH 0/4] autofs scaling and cleanup patches Valerie Aurora Henson
2009-01-09 18:47 ` [PATCH 1/4] Make hash table scale to thousands of entries Valerie Aurora Henson
2009-01-09 18:47   ` [PATCH 2/4] Make MAX_ERR_BUF and PARSE_MAX_BUF use easier to audit Valerie Aurora Henson
2009-01-09 18:47     ` [PATCH 3/4] Easy alloca() replacements Valerie Aurora Henson
2009-01-09 18:47       ` [PATCH 4/4] Replace <linux/string.h> with <string.h> Valerie Aurora Henson
2009-01-12  5:59         ` Ian Kent
2009-01-09 20:48       ` [PATCH 3/4] Easy alloca() replacements Valerie Aurora Henson
2009-01-10  3:18       ` Ian Kent
2009-01-16 22:11         ` Valerie Aurora Henson
2009-01-09 19:00     ` [PATCH 2/4] Make MAX_ERR_BUF and PARSE_MAX_BUF use easier to audit Jeff Moyer
2009-01-09 19:54       ` Valerie Aurora Henson
2009-01-09 19:17   ` [PATCH 1/4] Make hash table scale to thousands of entries Jeff Moyer
2009-01-09 19:51     ` Valerie Aurora Henson [this message]
2009-01-10  1:19       ` Paul Wankadia
2009-01-11 16:42         ` Ian Kent
2009-01-11 23:25           ` Paul Wankadia
2009-01-12  1:13             ` Ian Kent
2009-01-12  1:19             ` Ian Kent
2009-01-12  2:10               ` Paul Wankadia
2009-01-12  4:02               ` Ian Kent
2009-01-12  4:58                 ` Ian Kent
2009-01-13  1:52                   ` Paul Wankadia
2009-01-13  2:24                     ` Ian Kent
2009-01-13  4:15                       ` Ian Kent
2009-01-13  5:07                         ` Paul Wankadia
2009-01-13  5:19                           ` Ian Kent
2009-01-14  3:43                             ` Paul Wankadia
2009-01-14  8:47                               ` Ian Kent
2009-01-14 10:52                                 ` Paul Wankadia
2009-01-14 13:17                                   ` Ian Kent
2009-01-14 14:20                                     ` Paul Wankadia
2009-01-15  1:41                                       ` Ian Kent
2009-01-15 15:04                                         ` Jeff Moyer
2009-01-15 15:16                                           ` Ian Kent
2009-01-15 20:33                                             ` Paul Wankadia
2009-01-15 20:41                                               ` Jeff Moyer
2009-01-15 20:57                                                 ` Paul Wankadia
2009-01-16  0:27                                                   ` Ian Kent
2009-01-16  0:40                                                     ` Ian Kent
2009-01-16  1:43                                                       ` Ian Kent
2009-01-16  3:59                                                         ` Paul Wankadia
2009-01-16  4:21                                                           ` Ian Kent
2009-01-16  5:05                                                             ` Ian Kent
2009-01-16  6:04                                                             ` Paul Wankadia
2009-01-16  6:24                                                               ` Ian Kent
2009-01-16  6:39                                                                 ` Ian Kent
2009-01-17 17:11                                                                   ` Paul Wankadia
2009-01-18  3:26                                                                     ` Ian Kent
2009-01-19  1:28                                                                       ` Paul Wankadia
2009-01-19  2:03                                                                         ` Ian Kent
2009-01-19  5:23                                                                           ` Paul Wankadia
2009-01-19  6:13                                                                             ` Ian Kent
2009-01-16  5:23                                                         ` Ian Kent
2009-01-16  0:33                                             ` Ian Kent
2009-01-10 14:45       ` Ian Kent
2009-01-10  2:07     ` Ian Kent
2009-01-10  3:29   ` Ian Kent
2009-01-10  3:57     ` Ian Kent
2009-01-13  5:51   ` Ian Kent
2009-01-14  3:58     ` Paul Wankadia
2009-01-14  8:48       ` Ian Kent
2009-01-15  2:47         ` Valerie Aurora Henson
2009-01-15  3:02           ` Ian Kent
2009-01-16 21:39             ` Valerie Aurora Henson
2009-01-15  5:06           ` Paul Wankadia
2009-01-15  4:42       ` Ian Kent

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=20090109195151.GH32333@shell \
    --to=vaurora@redhat.com \
    --cc=autofs@linux.kernel.org \
    --cc=jmoyer@redhat.com \
    --cc=junyer@google.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.