All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Paolo Abeni' <pabeni@redhat.com>,
	"'willemdebruijn.kernel@gmail.com'"
	<willemdebruijn.kernel@gmail.com>,
	"'davem@davemloft.net'" <davem@davemloft.net>,
	"'dsahern@kernel.org'" <dsahern@kernel.org>,
	"'Eric Dumazet'" <edumazet@google.com>,
	"'kuba@kernel.org'" <kuba@kernel.org>,
	"'netdev@vger.kernel.org'" <netdev@vger.kernel.org>
Subject: RE: [PATCH 1/2] Move hash calculation inside udp4_lib_lookup2()
Date: Wed, 26 Jul 2023 14:02:33 +0000	[thread overview]
Message-ID: <4deda035df8142a6977ce844eb705bdb@AcuMS.aculab.com> (raw)
In-Reply-To: <fce08e76da7e3882319ae935c38e9e2eccf2dcae.camel@redhat.com>

From: Paolo Abeni
> Sent: 26 July 2023 14:44
> 
> On Wed, 2023-07-26 at 12:05 +0000, David Laight wrote:
> > Pass the udptable address into udp4_lib_lookup2() instead of the hash slot.
> >
> > While ipv4_portaddr_hash(net, IP_ADDR_ANY, 0) is constant for each net
> > (the port is an xor) the value isn't saved.
> > Since the hash function doesn't get simplified when passed zero the hash
> 
> Are you sure? could you please objdump and compare the binary code
> generated before and after the patch? In theory all the callers up to
> __jhash_final() included should be inlined, and the compiler should be
> able to optimze at least rol32(0, <n>).

I looked the hash is 20+ instructions and pretty much all of
them appeared twice.
(I'm in the wrong building to have a buildable kernel tree.)

It has to be said that ipv4_portaddr_hash(net, IPADDR_ANY, port)
could just be net_hash_mix(net) ^ port.
(Or maybe you could use a different random value.)

I'm not even sure the relatively expensive mixing of 'saddr'
is needed - it is one of the local IPv4 addresses.
Mixing in the remote address for connected sockets might
be useful for any server code that uses a lot of connected
udp sockets - but that isn't done.

We will have hundreds of udp sockets with different ports that
are not connected (I don't know if they get bound to a local
address). So a remote address hash wouldn't help.

If you look at the generated code for __udp4_lib_lookup()
it is actually quite horrid.
Too many called functions with too many parameters.
Things spill to the stack all the time.

The reuse_port code made it a whole lot worse.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2023-07-26 14:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-26 11:51 [PATCH 0/2] udp: rescan hash2 list if chains crossed David Laight
2023-07-26 12:05 ` [PATCH 1/2] Move hash calculation inside udp4_lib_lookup2() David Laight
2023-07-26 13:44   ` Paolo Abeni
2023-07-26 14:02     ` David Laight [this message]
2023-07-26 14:03       ` Eric Dumazet
2023-07-26 14:06         ` David Laight
2023-07-26 15:42     ` David Laight
2023-07-26 12:05 ` [PATCH 2/2] Rescan the hash2 list if the hash chains have got cross-linked David Laight
2023-07-26 13:36   ` Paolo Abeni
2023-07-26 13:37   ` Eric Dumazet
2023-07-26 14:13     ` David Laight
2023-07-26 14:21       ` Eric Dumazet
2023-07-26 14:39         ` David Laight
2023-07-26 14:48           ` Eric Dumazet

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=4deda035df8142a6977ce844eb705bdb@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemdebruijn.kernel@gmail.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.