[ovs-dev] [PATCH v10 1/1] Avoid dp_hash recirculation for balance-tcp bond selection mode

Ben Pfaff blp at ovn.org
Tue Jan 21 20:54:30 UTC 2020


On Mon, Jan 20, 2020 at 05:09:05PM +0100, Ilya Maximets wrote:
> > +static struct tx_bond *
> > +tx_bond_lookup(const struct hmap *hmap, uint32_t bond_id)
> > +{
> > +    struct tx_bond *tx;
> > +
> > +    HMAP_FOR_EACH_IN_BUCKET (tx, node, hash_bond_id(bond_id), hmap) {
> 
> Why not HMAP_FOR_EACH_WITH_HASH ?

HMAP_FOR_EACH_IN_BUCKET is a small optimization over
HMAP_FOR_EACH_WITH_HASH in cases where the comparison of the key is
cheap.  Comparing the hash is an optimization if the key is expensive to
compare (like an arbitrary string) but it just costs an extra integer
comparison if the key is a small integer as here.

> BTW, it's better to calculate hash before the loop to be sure that
> we're not recalculating it on each iteration.

A lot of code assumes that the hash only gets evaluated once.


More information about the dev mailing list