rps: misc changes
Subsystems (2)
cover rps: misc changes
Minor changes in rps:
skb_flow_limit() is probably unused these days,
and data-races are quite theoretical.
Eric Dumazet (4):
net: rps: change skb_flow_limit() hash function
net: rps: annotate data-races around (struct sd_flow_limit)->count
net: add data-race annotations in softnet_seq_show()
net: rps: remove kfree_rcu_mightsleep() use
include/net/rps.h | 5 +++-- net/core/dev.c | 11 +++++++---- net/core/dev.h | 5 +++-- net/core/net-procfs.c | 9 +++++---- net/core/sysctl_net_core.c | 6 +++--- 5 files changed, 21 insertions(+), 15 deletions(-)
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
PATCH 1/4 net: rps: change skb_flow_limit() hash function
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.
--- net/core/dev.c | 2 +- net/core/dev.h | 2 +- net/core/sysctl_net_core.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
net/core/dev.c +1 -1
@@ -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;
net/core/dev.h +1 -1
@@ -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[];
net/core/sysctl_net_core.c +1 -1
@@ -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); } }
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
Re: [PATCH net-next 1/4] net: rps: change skb_flow_limit() hash function
Quoted 10 lines · Eric Dumazet
As explained in commit
f3483c8e1da6("net: rfs: hash function change"), masking low order bits ofskb_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 <[email protected]>
PATCH 2/4 net: rps: annotate data-races around (struct sd_flow_limit)->count
In reply to Eric Dumazetsoftnet_seq_show() can read fl->count while another cpu updates this field from skb_flow_limit().
Make this field an 'unsigned int', as its only consumer only deals with 32 bit.
--- net/core/dev.c | 3 ++- net/core/dev.h | 2 +- net/core/net-procfs.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-)
net/core/dev.c +2 -1
@@ -5049,7 +5049,8 @@ static bool skb_flow_limit(struct sk_buff *skb, unsigned int qlen) fl->buckets[old_flow]--;if (++fl->buckets[new_flow] > (FLOW_LIMIT_HISTORY >>1 )) { - fl->count++; +/* Pairs with READ_ONCE() in softnet_seq_show() */ +WRITE_ONCE (fl->count, fl->count +1 );rcu_read_unlock ();return true; }
net/core/dev.h +1 -1
@@ -15,7 +15,7 @@ struct cpumask;/* Random bits of netdevice that don't need to be exposed */ #define FLOW_LIMIT_HISTORY (1 << 7)/* must be ^2 and !overflow buckets */ struct sd_flow_limit { -u64 count; +unsigned int count;u8 log_buckets;unsigned int history_head;u16 history[FLOW_LIMIT_HISTORY ];
net/core/net-procfs.c +2 -1
@@ -132,8 +132,9 @@ static int softnet_seq_show(struct seq_file *seq, void *v)rcu_read_lock (); fl =rcu_dereference (sd->flow_limit); +/* Pairs with WRITE_ONCE() in skb_flow_limit() */ if (fl) - flow_limit_count = fl->count; + flow_limit_count =READ_ONCE (fl->count);rcu_read_unlock ();#endif
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
Re: [PATCH net-next 2/4] net: rps: annotate data-races around (struct sd_flow_limit)->count
Quoted 7 lines · Eric Dumazet
softnet_seq_show()can readfl->countwhile another cpu updates this field fromskb_flow_limit().Make this field an 'unsigned int', as its only consumer only deals with 32 bit.
Signed-off-by Eric Dumazet <[email protected]>
PATCH 3/4 net: add data-race annotations in softnet_seq_show()
In reply to Eric Dumazetsoftnet_seq_show() reads several fields that might be updated concurrently. Add READ_ONCE() and WRITE_ONCE() annotations.
--- net/core/dev.c | 6 ++++-- net/core/net-procfs.c | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-)
net/core/dev.c +4 -2
@@ -4953,7 +4953,8 @@ static void rps_trigger_softirq(void *data)struct softnet_data *sd = data;____napi_schedule (sd, &sd->backlog); - sd->received_rps++; +/* Pairs with READ_ONCE() in softnet_seq_show() */ + WRITE_ONCE(sd->received_rps, sd->received_rps + 1); }#endif /* CONFIG_RPS */
@@ -7523,7 +7524,8 @@ static __latent_entropy void net_rx_action(void)*/ if (unlikely (budget <=0 ||time_after_eq (jiffies, time_limit))) { - sd->time_squeeze++; +/* Pairs with READ_ONCE() in softnet_seq_show() */ +WRITE_ONCE (sd->time_squeeze, sd->time_squeeze +1 );break ; } }
net/core/net-procfs.c +3 -3
@@ -145,11 +145,11 @@ static int softnet_seq_show(struct seq_file *seq, void *v)seq_printf (seq,"%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x " "%08x %08x\n" , - sd->processed,atomic_read (&sd->dropped), - sd->time_squeeze,0 , +READ_ONCE (sd->processed),atomic_read (&sd->dropped), +READ_ONCE (sd->time_squeeze),0 ,0 ,0 ,0 ,0 ,/* was fastroute */ 0 ,/* was cpu_collision */ - sd->received_rps, flow_limit_count, +READ_ONCE (sd->received_rps), flow_limit_count, input_qlen + process_qlen, (int )seq->index, input_qlen, process_qlen);return 0 ;
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
Re: [PATCH net-next 3/4] net: add data-race annotations in softnet_seq_show()
Quoted 4 lines · Eric Dumazet
softnet_seq_show()reads several fields that might be updated concurrently. AddREAD_ONCE()andWRITE_ONCE()annotations.Signed-off-by Eric Dumazet <[email protected]>
PATCH 4/4 net: rps: remove kfree_rcu_mightsleep() use
In reply to Eric DumazetAdd an rcu_head to sd_flow_limit and rps_sock_flow_table structs to use the more conventional and predictable k[v]free_rcu().
--- include/net/rps.h | 5 +++-- net/core/dev.h | 1 + net/core/sysctl_net_core.c | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-)
include/net/rps.h +3 -2
@@ -57,9 +57,10 @@ struct rps_dev_flow_table {* meaning we use 32-6=26 bits for the hash. */ struct rps_sock_flow_table { -u32 mask; +struct rcu_head rcu; +u32 mask; -u32 ents[]____cacheline_aligned_in_smp ; +u32 ents[]____cacheline_aligned_in_smp ; };#define RPS_SOCK_FLOW_TABLE_SIZE (_num) (offsetof(struct rps_sock_flow_table, ents[_num]))
net/core/dev.h +1 -0
@@ -15,6 +15,7 @@ struct cpumask;/* Random bits of netdevice that don't need to be exposed */ #define FLOW_LIMIT_HISTORY (1 << 7)/* must be ^2 and !overflow buckets */ struct sd_flow_limit { +struct rcu_head rcu;unsigned int count;u8 log_buckets;unsigned int history_head;
net/core/sysctl_net_core.c +2 -2
@@ -201,7 +201,7 @@ static int rps_sock_flow_sysctl(const struct ctl_table *table, int write,if (orig_sock_table) {static_branch_dec (&rps_needed);static_branch_dec (&rfs_needed); -kvfree_rcu_mightsleep (orig_sock_table); +kvfree_rcu (orig_sock_table, rcu); } } }
@@ -239,7 +239,7 @@ static int flow_limit_cpu_sysctl(const struct ctl_table *table, int write, lockdep_is_held(&flow_limit_update_mutex));if (cur && !cpumask_test_cpu (i, mask)) {RCU_INIT_POINTER (sd->flow_limit,NULL ); -kfree_rcu_mightsleep (cur); +kfree_rcu (cur, rcu); }else if (!cur &&cpumask_test_cpu (i, mask)) { cur =kzalloc_node (len,GFP_KERNEL ,cpu_to_node (i));
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
Re: [PATCH net-next 4/4] net: rps: remove kfree_rcu_mightsleep() use
Quoted 4 lines · Eric Dumazet
Add an
rcu_headtosd_flow_limitandrps_sock_flow_tablestructs to use the more conventional and predictable k[v]free_rcu().Signed-off-by Eric Dumazet <[email protected]>
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Mon, 7 Apr 2025 16:35:58 +0000 you wrote:
Minor changes in rps:
skb_flow_limit()is probably unused these days,
and data-races are quite theoretical.
Quoted 7 lines
Eric Dumazet (4):
net: rps: changeskb_flow_limit()hash function
net: rps: annotate data-races around (struct sd_flow_limit)->count
net: add data-race annotations insoftnet_seq_show()
net: rps: removekfree_rcu_mightsleep()use[...]
Here is the summary with links:
- [net-next,1/4] net: rps: change skb_flow_limit() hash function
https://git.kernel.org/netdev/net-next/c/c3025e94daa9 - [net-next,2/4] net: rps: annotate data-races around (struct sd_flow_limit)->count https://git.kernel.org/netdev/net-next/c/7b6f0a852da3 - [net-next,3/4] net: add data-race annotations in softnet_seq_show() https://git.kernel.org/netdev/net-next/c/22d046a778e4 - [net-next,4/4] net: rps: remove kfree_rcu_mightsleep() use https://git.kernel.org/netdev/net-next/c/0a7de4a8f898
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html