From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Sasha Levin <levinsasha928@gmail.com>,
David Laight <David.Laight@ACULAB.COM>,
torvalds@linux-foundation.org, tj@kernel.org,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
ebiederm@xmission.com, neilb@suse.de, bfields@fieldses.org,
ejt@redhat.com, snitzer@redhat.com, edumazet@google.com,
josh@joshtriplett.org, rmallon@gmail.com, palves@redhat.com
Subject: Re: [PATCH v6] hashtable: introduce a small and naive hashtable
Date: Wed, 26 Sep 2012 12:19:56 -0400 [thread overview]
Message-ID: <20120926161956.GB28648@Krystal> (raw)
In-Reply-To: <1348675764.22822.56.camel@gandalf.local.home>
* Steven Rostedt (rostedt@goodmis.org) wrote:
> On Wed, 2012-09-26 at 10:39 -0400, Mathieu Desnoyers wrote:
> > * Sasha Levin (levinsasha928@gmail.com) wrote:
> > > On 09/26/2012 03:59 PM, Steven Rostedt wrote:
> > > > On Wed, 2012-09-26 at 14:45 +0100, David Laight wrote:
> > > >> Amazing how something simple gets lots of comments and versions :-)
> > > >>
> > > >>> ...
> > > >>> + * This has to be a macro since HASH_BITS() will not work on pointers since
> > > >>> + * it calculates the size during preprocessing.
> > > >>> + */
> > > >>> +#define hash_empty(hashtable) \
> > > >>> +({ \
> > > >>> + int __i; \
> > > >>> + bool __ret = true; \
> > > >>> + \
> > > >>> + for (__i = 0; __i < HASH_SIZE(hashtable); __i++) \
> > > >>> + if (!hlist_empty(&hashtable[__i])) \
> > > >>> + __ret = false; \
> > > >>> + \
> > > >>> + __ret; \
> > > >>> +})
> > > >>
> > > >> Actually you could have a #define that calls a function
> > > >> passing in the address and size.
> > > >
> > > > Probably would be cleaner to do so.
> > >
> > > I think it's worth it if it was more complex than a simple loop. We
> > > were doing a similar thing with the _size() functions (see version 4
> > > of this patch), but decided to remove it since it was becoming too
> > > complex.
> >
> > Defining local variables within statement-expressions can have some
> > unexpected side-effects if the "caller" which embeds the macro use the
> > same variable name. See rcu_dereference() as an example (Paul uses an
> > awefully large number of underscores). It should be avoided whenever
> > possible.
> >
> > > >
> > > >
> > > >> Also, should the loop have a 'break' in it?
> > > >
> > > > Yeah it should, and could do:
> > > >
> > > > for (i = 0; i < HASH_SIZE(hashtable); i++)
> > > > if (!hlist_empty(&hashtable[i]))
> > > > break;
> > > >
> > > > return i < HASH_SIZE(hashtable);
> >
> >
> > Hrm, Steven, did you drink you morning coffee before writing this ? ;-)
> > It looks like you did 2 bugs in 4 LOC.
>
> Coffee yes, but head cold as well. :-p
>
> >
> > First, the condition should be reversed, because this function returns
> > whether the hash is empty, not the other way around.
>
> Bah, I was looking at the code the code and got the ret confused. I
> originally had it the opposite, and then reversed it before sending.
>
> >
> > And even then, if we would do:
> >
> > for (i = 0; i < HASH_SIZE(hashtable); i++)
> > if (!hlist_empty(&hashtable[i]))
> > break;
> >
> > return i >= HASH_SIZE(hashtable);
> >
> > What happens if the last entry of the table is non-empty ?
>
> It still works, as 'i' is not incremented due to the break. And i will
> still be less than HASH_SIZE(hashtable). Did you have *your* cup of
> coffee today? ;-)
Ahh, right! Actually I had it already ;-)
>
>
> >
> > So I would advise that Sasha keep his original flag-based
> > implementation, but add the missing break, and move the init and empty
> > define loops into static inlines.
> >
>
> Nah,
Agreed that the flags should be removed. Moving to define + static
inline is still important though.
Thanks,
Mathieu
>
> -- Steve
>
>
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
next prev parent reply other threads:[~2012-09-26 16:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-26 12:48 Sasha Levin
2012-09-26 13:45 ` David Laight
2012-09-26 13:59 ` Steven Rostedt
2012-09-26 14:26 ` Sasha Levin
2012-09-26 14:39 ` Mathieu Desnoyers
2012-09-26 16:09 ` Steven Rostedt
2012-09-26 16:19 ` Mathieu Desnoyers [this message]
2012-09-27 8:25 ` David Laight
2012-09-27 8:33 ` Sasha Levin
2012-09-27 12:09 ` Steven Rostedt
2012-09-27 13:11 ` Mathieu Desnoyers
2012-09-27 13:30 ` Steven Rostedt
2012-09-27 14:36 ` David Laight
2012-09-27 13:03 ` Mathieu Desnoyers
2012-09-26 14:31 ` Mathieu Desnoyers
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=20120926161956.GB28648@Krystal \
--to=mathieu.desnoyers@efficios.com \
--cc=David.Laight@ACULAB.COM \
--cc=akpm@linux-foundation.org \
--cc=bfields@fieldses.org \
--cc=ebiederm@xmission.com \
--cc=edumazet@google.com \
--cc=ejt@redhat.com \
--cc=josh@joshtriplett.org \
--cc=levinsasha928@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=neilb@suse.de \
--cc=palves@redhat.com \
--cc=rmallon@gmail.com \
--cc=rostedt@goodmis.org \
--cc=snitzer@redhat.com \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®