From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: torvalds@linux-foundation.org, tj@kernel.org,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, paul.gortmaker@windriver.com,
davem@davemloft.net, rostedt@goodmis.org, mingo@elte.hu,
ebiederm@xmission.com, aarcange@redhat.com, ericvh@gmail.com,
netdev@vger.kernel.org, josh@joshtriplett.org,
eric.dumazet@gmail.com, axboe@kernel.dk, agk@redhat.com,
dm-devel@redhat.com, neilb@suse.de, ccaulfie@redhat.com,
teigland@redhat.com, Trond.Myklebust@netapp.com,
bfields@fieldses.org, fweisbec@gmail.com, jesse@nicira.com,
venkat.x.venkatsubra@oracle.com, ejt@redhat.com,
snitzer@redhat.com, edumazet@google.com,
linux-nfs@vger.kernel.org, dev@openvswitch.org,
rds-devel@oss.oracle.com, lw@cn.fujitsu.com
Subject: Re: [PATCH v2 01/16] hashtable: introduce a small and naive hashtable
Date: Sun, 19 Aug 2012 09:16:37 -0400 [thread overview]
Message-ID: <20120819131637.GA8272@Krystal> (raw)
In-Reply-To: <1345337550-24304-2-git-send-email-levinsasha928@gmail.com>
* Sasha Levin (levinsasha928@gmail.com) wrote:
> This hashtable implementation is using hlist buckets to provide a simple
> hashtable to prevent it from getting reimplemented all over the kernel.
>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
> include/linux/hashtable.h | 284 +++++++++++++++++++++++++++++++++++++++++++++
[...]
Hi Sasha,
There are still a few API naming nits that I'd like to discuss:
> +
> +/**
> + * hash_for_each_size - iterate over a hashtable
> + * @name: hashtable to iterate
> + * @bits: bit count of hashing function of the hashtable
> + * @bkt: integer to use as bucket loop cursor
> + * @node: the &struct list_head to use as a loop cursor for each bucket
> + * @obj: the type * to use as a loop cursor for each bucket
> + * @member: the name of the hlist_node within the struct
> + */
> +#define hash_for_each_size(name, bits, bkt, node, obj, member) \
What is the meaning of "for each size" ?
By looking at the implementation, I see that it takes an extra "bits"
argument to specify the key width.
But in the other patches of this patchset, I cannot find a single user
of the "*_size" API. If you do not typically expect users to specify
this parameter by hand (thanks to use of HASH_BITS(name) in for_each
functions that do not take the bits parameter), I would recommend to
only expose hash_for_each() and similar defines, but not the *_size
variants.
So I recommend merging hash_for_each_size into hash_for_each (and
doing similarly for other *_size variants). On the plus side, it will
cut down the number of for_each macros from 12 down to 6, which is more
reasonable.
> + for (bkt = 0; bkt < HASH_SIZE(bits); bkt++) \
> + hlist_for_each_entry(obj, node, &name[bkt], member)
> +
> +/**
> + * hash_for_each - iterate over a hashtable
> + * @name: hashtable to iterate
> + * @bkt: integer to use as bucket loop cursor
> + * @node: the &struct list_head to use as a loop cursor for each bucket
> + * @obj: the type * to use as a loop cursor for each bucket
> + * @member: the name of the hlist_node within the struct
> + */
> +#define hash_for_each(name, bkt, node, obj, member) \
> + hash_for_each_size(name, HASH_BITS(name), bkt, node, obj, member)
> +
[...]
> +/**
> + * hash_for_each_possible - iterate over all possible objects for a given key
> + * @name: hashtable to iterate
> + * @obj: the type * to use as a loop cursor for each bucket
> + * @bits: bit count of hashing function of the hashtable
> + * @node: the &struct list_head to use as a loop cursor for each bucket
> + * @member: the name of the hlist_node within the struct
> + * @key: the key of the objects to iterate over
> + */
> +#define hash_for_each_possible_size(name, obj, bits, node, member, key) \
> + hlist_for_each_entry(obj, node, &name[hash_min(key, bits)], member)
Second point: "for_each_possible" does not express the iteration scope.
Citing WordNet: "possible adj 1: capable of happening or existing;" --
which has nothing to do with iteration on duplicate keys within a hash
table.
I would recommend to rename "possible" to "duplicate", e.g.:
hash_for_each_duplicate()
which clearly says what is the scope of this iteration: duplicate keys.
Thanks,
Mathieu
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
next prev parent reply other threads:[~2012-08-19 13:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-19 0:52 [PATCH v2 00/16] generic hashtable implementation Sasha Levin
2012-08-19 0:52 ` [PATCH v2 01/16] hashtable: introduce a small and naive hashtable Sasha Levin
2012-08-19 13:16 ` Mathieu Desnoyers [this message]
2012-08-19 14:16 ` Mathieu Desnoyers
2012-08-19 16:17 ` Sasha Levin
2012-08-19 16:08 ` Sasha Levin
2012-08-19 0:52 ` [PATCH 02/16] user_ns: use new hashtable implementation Sasha Levin
2012-08-19 0:52 ` [PATCH v2 02/16] userns: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 03/16] mm,ksm: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 04/16] workqueue: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 05/16] mm/huge_memory: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 06/16] tracepoint: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 07/16] net,9p: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 08/16] block,elevator: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 09/16] SUNRPC/cache: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 10/16] dlm: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 11/16] net,l2tp: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 12/16] dm: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 13/16] lockd: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 14/16] net,rds: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 15/16] openvswitch: " Sasha Levin
2012-08-19 0:52 ` [PATCH v2 16/16] tracing output: " Sasha Levin
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=20120819131637.GA8272@Krystal \
--to=mathieu.desnoyers@efficios.com \
--cc=Trond.Myklebust@netapp.com \
--cc=aarcange@redhat.com \
--cc=agk@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=bfields@fieldses.org \
--cc=ccaulfie@redhat.com \
--cc=davem@davemloft.net \
--cc=dev@openvswitch.org \
--cc=dm-devel@redhat.com \
--cc=ebiederm@xmission.com \
--cc=edumazet@google.com \
--cc=ejt@redhat.com \
--cc=eric.dumazet@gmail.com \
--cc=ericvh@gmail.com \
--cc=fweisbec@gmail.com \
--cc=jesse@nicira.com \
--cc=josh@joshtriplett.org \
--cc=levinsasha928@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=lw@cn.fujitsu.com \
--cc=mingo@elte.hu \
--cc=neilb@suse.de \
--cc=netdev@vger.kernel.org \
--cc=paul.gortmaker@windriver.com \
--cc=rds-devel@oss.oracle.com \
--cc=rostedt@goodmis.org \
--cc=snitzer@redhat.com \
--cc=teigland@redhat.com \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=venkat.x.venkatsubra@oracle.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 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).