From: Stephen Hemminger <stephen@networkplumber.org>
To: "Morten Brørup" <mb@smartsharesystems.com>
Cc: dev@dpdk.org, "Wathsala Vithanage" <wathsala.vithanage@arm.com>,
"Yipeng Wang" <yipeng1.wang@intel.com>,
"Sameh Gobriel" <sameh.gobriel@intel.com>,
"Bruce Richardson" <bruce.richardson@intel.com>,
"Vladimir Medvedkin" <vladimir.medvedkin@intel.com>,
"Mattias Rönnblom" <mattias.ronnblom@ericsson.com>
Subject: Re: [PATCH v2 3/4] hash: reduce architecture special cases
Date: Tue, 26 Aug 2025 07:22:10 -0700 [thread overview]
Message-ID: <20250826072210.79659b3b@hermes.local> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9FE73@smartserver.smartshare.dk>
On Tue, 26 Aug 2025 16:13:29 +0200
Morten Brørup <mb@smartsharesystems.com> wrote:
> > From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> > Sent: Tuesday, 26 August 2025 15.42
> >
> > On Tue, 26 Aug 2025 08:55:23 +0200
> > Morten Brørup <mb@smartsharesystems.com> wrote:
> >
> > > > +static int
> > > > +rte_hash_k64_cmp_eq(const void *key1, const void *key2, size_t
> > key_len)
> > > > +{
> > > > + return rte_hash_k32_cmp_eq(key1, key2, key_len) |
> > >
> > > Is the "|" instead of "||", to compare in blocks of 64 bytes instead
> > of 32, intentional?
> >
> > The cost of the conditional branch is usually higher than the cost of
> > doing
> > a few more instructions on cached data.
>
> I agree the key being looked up is very likely cached.
>
> But the key in the hash table might not be, and the 64 byte comparison might cross a cache line.
> I think using half a cache line as the breakpoint (for using conditional branch instead of unconditional load and compare) seems like a better tradeoff than a full cache line. I have no data to back this up, just a hunch.
> In reality, it depends on the use case. If a cache hit is more likely than a cache miss, then the unconditional comparison is preferable.
> No strong opinion. I mainly wanted to ensure this was intentional.
>
>
> While looking into this, I noticed a few instances where your assumption about key1 being aligned is wrong, and the key1/key2 parameters should be swapped:
> https://elixir.bootlin.com/dpdk/v25.07/source/lib/hash/rte_cuckoo_hash.c#L763
> https://elixir.bootlin.com/dpdk/v25.07/source/lib/hash/rte_cuckoo_hash.c#L1319
> https://elixir.bootlin.com/dpdk/v25.07/source/lib/hash/rte_cuckoo_hash.c#L1357
> E.g. when calling rte_hash_add_key_with_hash(), the key parameter can be unaligned, and it ripples down and becomes key1:
> https://elixir.bootlin.com/dpdk/v25.07/source/lib/hash/rte_cuckoo_hash.c#L1259
Ok, lets make 32 byte the watershed as comprimise.
Good catch, best to mark all keys as unaligned, but it won't matter on x86 or Arm64
next prev parent reply other threads:[~2025-08-26 14:22 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-21 20:35 [RFC 0/3] hash: optimize compare logic Stephen Hemminger
2025-08-21 20:35 ` [RFC 1/3] hash: move table of hash compare functions out of header Stephen Hemminger
2025-08-22 9:05 ` Morten Brørup
2025-08-22 16:50 ` Stephen Hemminger
2025-08-21 20:35 ` [RFC 2/3] hash: reduce architecture special cases Stephen Hemminger
2025-08-22 9:20 ` Morten Brørup
2025-08-21 20:35 ` [RFC 3/3] hash: add support for common small key sizes Stephen Hemminger
2025-08-22 7:19 ` Mattias Rönnblom
2025-08-22 9:50 ` Morten Brørup
2025-08-22 15:05 ` Mattias Rönnblom
2025-08-22 18:57 ` Morten Brørup
2025-08-25 6:05 ` Mattias Rönnblom
2025-08-22 16:12 ` Stephen Hemminger
2025-08-22 18:19 ` [PATCH v2 0/4] Cuckoo hash cleanup and optimizations Stephen Hemminger
2025-08-22 18:19 ` [PATCH v2 1/4] hash: move table of hash compare functions out of header Stephen Hemminger
2025-08-22 18:19 ` [PATCH v2 2/4] hash: use static_assert Stephen Hemminger
2025-08-26 6:58 ` Morten Brørup
2025-08-22 18:19 ` [PATCH v2 3/4] hash: reduce architecture special cases Stephen Hemminger
2025-08-26 6:55 ` Morten Brørup
2025-08-26 13:41 ` Stephen Hemminger
2025-08-26 14:13 ` Morten Brørup
2025-08-26 14:22 ` Stephen Hemminger [this message]
2025-08-26 14:36 ` Mattias Rönnblom
2025-08-26 16:25 ` Stephen Hemminger
2025-08-22 18:19 ` [PATCH v2 4/4] hash: add support for common small key sizes Stephen Hemminger
2025-08-26 6:58 ` Morten Brørup
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=20250826072210.79659b3b@hermes.local \
--to=stephen@networkplumber.org \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=mattias.ronnblom@ericsson.com \
--cc=mb@smartsharesystems.com \
--cc=sameh.gobriel@intel.com \
--cc=vladimir.medvedkin@intel.com \
--cc=wathsala.vithanage@arm.com \
--cc=yipeng1.wang@intel.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).