]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: rps: change skb_flow_limit() hash function
authorEric Dumazet <edumazet@google.com>
Mon, 7 Apr 2025 16:35:59 +0000 (16:35 +0000)
committerJakub Kicinski <kuba@kernel.org>
Tue, 8 Apr 2025 19:30:55 +0000 (12:30 -0700)
As explained in commit f3483c8e1da6 ("net: rfs: hash function change"),
masking low order bits of skb_get_hash(skb) has low entropy.

A NIC with 32 RX queues uses the 5 low order bits of rss key
to select a queue. This means all packets landing to a given
queue share the same 5 low order bits.

Switch to hash_32() to reduce hash collisions.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20250407163602.170356-2-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/dev.c
net/core/dev.h
net/core/sysctl_net_core.c

index 0608605cfc242fc0a3db7032741303c9db21ef74..f674236f34bebb619b02d6e3ab8dfb89dc536142 100644 (file)
@@ -5038,7 +5038,7 @@ static bool skb_flow_limit(struct sk_buff *skb, unsigned int qlen)
        rcu_read_lock();
        fl = rcu_dereference(sd->flow_limit);
        if (fl) {
-               new_flow = skb_get_hash(skb) & (fl->num_buckets - 1);
+               new_flow = hash_32(skb_get_hash(skb), fl->log_buckets);
                old_flow = fl->history[fl->history_head];
                fl->history[fl->history_head] = new_flow;
 
index 7ee203395d8e267b0542532b63243e6d3dda6a66..b1cd44b5f009bfd98e2e8ecde20aa6052cc36282 100644 (file)
@@ -16,7 +16,7 @@ struct cpumask;
 #define FLOW_LIMIT_HISTORY     (1 << 7)  /* must be ^2 and !overflow buckets */
 struct sd_flow_limit {
        u64                     count;
-       unsigned int            num_buckets;
+       u8                      log_buckets;
        unsigned int            history_head;
        u16                     history[FLOW_LIMIT_HISTORY];
        u8                      buckets[];
index c7769ee0d9c55379367bc6d29f8f697c5847360a..5cfe76ede5237f34aee1eee17a3e851b4a4cea92 100644 (file)
@@ -248,7 +248,7 @@ static int flow_limit_cpu_sysctl(const struct ctl_table *table, int write,
                                        ret = -ENOMEM;
                                        goto write_unlock;
                                }
-                               cur->num_buckets = netdev_flow_limit_table_len;
+                               cur->log_buckets = ilog2(netdev_flow_limit_table_len);
                                rcu_assign_pointer(sd->flow_limit, cur);
                        }
                }