[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5eb8631d430248999116ce8ced13e4b2@AcuMS.aculab.com>
Date: Wed, 26 Jul 2023 12:05:07 +0000
From: David Laight <David.Laight@...LAB.COM>
To: "'willemdebruijn.kernel@...il.com'" <willemdebruijn.kernel@...il.com>,
"'davem@...emloft.net'" <davem@...emloft.net>, "'dsahern@...nel.org'"
<dsahern@...nel.org>, 'Eric Dumazet' <edumazet@...gle.com>,
"'kuba@...nel.org'" <kuba@...nel.org>, "'pabeni@...hat.com'"
<pabeni@...hat.com>, "'netdev@...r.kernel.org'" <netdev@...r.kernel.org>
Subject: [PATCH 1/2] Move hash calculation inside udp4_lib_lookup2()
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
might as well be computed inside udp4_lib_lookup2().
This reduces the cache footprint and allows additional checks.
Signed-off-by: David Laight <david.laight@...lab.com>
---
net/ipv4/udp.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 42a96b3547c9..ad64d6c4cd99 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -439,12 +439,18 @@ static struct sock *udp4_lib_lookup2(struct net *net,
__be32 saddr, __be16 sport,
__be32 daddr, unsigned int hnum,
int dif, int sdif,
- struct udp_hslot *hslot2,
+ struct udp_table *udptable,
struct sk_buff *skb)
{
+ unsigned int hash2, slot2;
+ struct udp_hslot *hslot2;
struct sock *sk, *result;
int score, badness;
+ hash2 = ipv4_portaddr_hash(net, daddr, hnum);
+ slot2 = hash2 & udptable->mask;
+ hslot2 = &udptable->hash2[slot2];
+
result = NULL;
badness = 0;
udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
@@ -495,18 +501,12 @@ struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
int sdif, struct udp_table *udptable, struct sk_buff *skb)
{
unsigned short hnum = ntohs(dport);
- unsigned int hash2, slot2;
- struct udp_hslot *hslot2;
struct sock *result, *sk;
- hash2 = ipv4_portaddr_hash(net, daddr, hnum);
- slot2 = hash2 & udptable->mask;
- hslot2 = &udptable->hash2[slot2];
-
/* Lookup connected or non-wildcard socket */
result = udp4_lib_lookup2(net, saddr, sport,
daddr, hnum, dif, sdif,
- hslot2, skb);
+ udptable, skb);
if (!IS_ERR_OR_NULL(result) && result->sk_state == TCP_ESTABLISHED)
goto done;
@@ -525,13 +525,9 @@ struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
goto done;
/* Lookup wildcard sockets */
- hash2 = ipv4_portaddr_hash(net, htonl(INADDR_ANY), hnum);
- slot2 = hash2 & udptable->mask;
- hslot2 = &udptable->hash2[slot2];
-
result = udp4_lib_lookup2(net, saddr, sport,
htonl(INADDR_ANY), hnum, dif, sdif,
- hslot2, skb);
+ udptable, skb);
done:
if (IS_ERR(result))
return NULL;
--
2.17.1
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists