Skip to content

Commit ce7f49a

Browse files
edumazetkuba-moo
authored andcommitted
net: move rps_sock_flow_table to net_hotdata
rps_sock_flow_table and rps_cpu_mask are used in fast path. Move them to net_hotdata for better cache locality. Signed-off-by: Eric Dumazet <[email protected]> Acked-by: Soheil Hassas Yeganeh <[email protected]> Reviewed-by: David Ahern <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 490a79f commit ce7f49a

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

include/net/hotdata.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ struct net_hotdata {
2727
struct kmem_cache *skbuff_cache;
2828
struct kmem_cache *skbuff_fclone_cache;
2929
struct kmem_cache *skb_small_head_cache;
30+
#ifdef CONFIG_RPS
31+
struct rps_sock_flow_table __rcu *rps_sock_flow_table;
32+
u32 rps_cpu_mask;
33+
#endif
3034
int gro_normal_batch;
3135
int netdev_budget;
3236
int netdev_budget_usecs;

include/net/rps.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/types.h>
66
#include <linux/static_key.h>
77
#include <net/sock.h>
8+
#include <net/hotdata.h>
89

910
#ifdef CONFIG_RPS
1011

@@ -64,14 +65,11 @@ struct rps_sock_flow_table {
6465

6566
#define RPS_NO_CPU 0xffff
6667

67-
extern u32 rps_cpu_mask;
68-
extern struct rps_sock_flow_table __rcu *rps_sock_flow_table;
69-
7068
static inline void rps_record_sock_flow(struct rps_sock_flow_table *table,
7169
u32 hash)
7270
{
7371
unsigned int index = hash & table->mask;
74-
u32 val = hash & ~rps_cpu_mask;
72+
u32 val = hash & ~net_hotdata.rps_cpu_mask;
7573

7674
/* We only give a hint, preemption can change CPU under us */
7775
val |= raw_smp_processor_id();
@@ -93,7 +91,7 @@ static inline void sock_rps_record_flow_hash(__u32 hash)
9391
if (!hash)
9492
return;
9593
rcu_read_lock();
96-
sock_flow_table = rcu_dereference(rps_sock_flow_table);
94+
sock_flow_table = rcu_dereference(net_hotdata.rps_sock_flow_table);
9795
if (sock_flow_table)
9896
rps_record_sock_flow(sock_flow_table, hash);
9997
rcu_read_unlock();

net/core/dev.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4450,12 +4450,6 @@ static inline void ____napi_schedule(struct softnet_data *sd,
44504450

44514451
#ifdef CONFIG_RPS
44524452

4453-
/* One global table that all flow-based protocols share. */
4454-
struct rps_sock_flow_table __rcu *rps_sock_flow_table __read_mostly;
4455-
EXPORT_SYMBOL(rps_sock_flow_table);
4456-
u32 rps_cpu_mask __read_mostly;
4457-
EXPORT_SYMBOL(rps_cpu_mask);
4458-
44594453
struct static_key_false rps_needed __read_mostly;
44604454
EXPORT_SYMBOL(rps_needed);
44614455
struct static_key_false rfs_needed __read_mostly;
@@ -4547,7 +4541,7 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
45474541
if (!hash)
45484542
goto done;
45494543

4550-
sock_flow_table = rcu_dereference(rps_sock_flow_table);
4544+
sock_flow_table = rcu_dereference(net_hotdata.rps_sock_flow_table);
45514545
if (flow_table && sock_flow_table) {
45524546
struct rps_dev_flow *rflow;
45534547
u32 next_cpu;
@@ -4557,10 +4551,10 @@ static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb,
45574551
* This READ_ONCE() pairs with WRITE_ONCE() from rps_record_sock_flow().
45584552
*/
45594553
ident = READ_ONCE(sock_flow_table->ents[hash & sock_flow_table->mask]);
4560-
if ((ident ^ hash) & ~rps_cpu_mask)
4554+
if ((ident ^ hash) & ~net_hotdata.rps_cpu_mask)
45614555
goto try_rps;
45624556

4563-
next_cpu = ident & rps_cpu_mask;
4557+
next_cpu = ident & net_hotdata.rps_cpu_mask;
45644558

45654559
/* OK, now we know there is a match,
45664560
* we can look at the local (per receive queue) flow table

net/core/sysctl_net_core.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
140140

141141
mutex_lock(&sock_flow_mutex);
142142

143-
orig_sock_table = rcu_dereference_protected(rps_sock_flow_table,
143+
orig_sock_table = rcu_dereference_protected(
144+
net_hotdata.rps_sock_flow_table,
144145
lockdep_is_held(&sock_flow_mutex));
145146
size = orig_size = orig_sock_table ? orig_sock_table->mask + 1 : 0;
146147

@@ -161,7 +162,8 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
161162
mutex_unlock(&sock_flow_mutex);
162163
return -ENOMEM;
163164
}
164-
rps_cpu_mask = roundup_pow_of_two(nr_cpu_ids) - 1;
165+
net_hotdata.rps_cpu_mask =
166+
roundup_pow_of_two(nr_cpu_ids) - 1;
165167
sock_table->mask = size - 1;
166168
} else
167169
sock_table = orig_sock_table;
@@ -172,7 +174,8 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
172174
sock_table = NULL;
173175

174176
if (sock_table != orig_sock_table) {
175-
rcu_assign_pointer(rps_sock_flow_table, sock_table);
177+
rcu_assign_pointer(net_hotdata.rps_sock_flow_table,
178+
sock_table);
176179
if (sock_table) {
177180
static_branch_inc(&rps_needed);
178181
static_branch_inc(&rfs_needed);

0 commit comments

Comments
 (0)