Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: move ptype_all into net_hotdata

ptype_all is used in rx/tx fast paths.

Move it to net_hotdata for better cache locality.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://lore.kernel.org/r/20240306160031.874438-5-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
0b91fa4b f59b5416

+13 -13
-1
include/linux/netdevice.h
··· 5306 5306 #define PTYPE_HASH_SIZE (16) 5307 5307 #define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1) 5308 5308 5309 - extern struct list_head ptype_all __read_mostly; 5310 5309 extern struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly; 5311 5310 5312 5311 extern struct net_device *blackhole_netdev;
+1
include/net/hotdata.h
··· 7 7 /* Read mostly data used in network fast paths. */ 8 8 struct net_hotdata { 9 9 struct list_head offload_base; 10 + struct list_head ptype_all; 10 11 int gro_normal_batch; 11 12 int netdev_budget; 12 13 int netdev_budget_usecs;
+7 -9
net/core/dev.c
··· 161 161 162 162 static DEFINE_SPINLOCK(ptype_lock); 163 163 struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly; 164 - struct list_head ptype_all __read_mostly; /* Taps */ 165 164 166 165 static int netif_rx_internal(struct sk_buff *skb); 167 166 static int call_netdevice_notifiers_extack(unsigned long val, ··· 539 540 static inline struct list_head *ptype_head(const struct packet_type *pt) 540 541 { 541 542 if (pt->type == htons(ETH_P_ALL)) 542 - return pt->dev ? &pt->dev->ptype_all : &ptype_all; 543 + return pt->dev ? &pt->dev->ptype_all : &net_hotdata.ptype_all; 543 544 else 544 545 return pt->dev ? &pt->dev->ptype_specific : 545 546 &ptype_base[ntohs(pt->type) & PTYPE_HASH_MASK]; ··· 2225 2226 */ 2226 2227 bool dev_nit_active(struct net_device *dev) 2227 2228 { 2228 - return !list_empty(&ptype_all) || !list_empty(&dev->ptype_all); 2229 + return !list_empty(&net_hotdata.ptype_all) || 2230 + !list_empty(&dev->ptype_all); 2229 2231 } 2230 2232 EXPORT_SYMBOL_GPL(dev_nit_active); 2231 2233 ··· 2237 2237 2238 2238 void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) 2239 2239 { 2240 - struct packet_type *ptype; 2240 + struct list_head *ptype_list = &net_hotdata.ptype_all; 2241 + struct packet_type *ptype, *pt_prev = NULL; 2241 2242 struct sk_buff *skb2 = NULL; 2242 - struct packet_type *pt_prev = NULL; 2243 - struct list_head *ptype_list = &ptype_all; 2244 2243 2245 2244 rcu_read_lock(); 2246 2245 again: ··· 2285 2286 pt_prev = ptype; 2286 2287 } 2287 2288 2288 - if (ptype_list == &ptype_all) { 2289 + if (ptype_list == &net_hotdata.ptype_all) { 2289 2290 ptype_list = &dev->ptype_all; 2290 2291 goto again; 2291 2292 } ··· 5386 5387 if (pfmemalloc) 5387 5388 goto skip_taps; 5388 5389 5389 - list_for_each_entry_rcu(ptype, &ptype_all, list) { 5390 + list_for_each_entry_rcu(ptype, &net_hotdata.ptype_all, list) { 5390 5391 if (pt_prev) 5391 5392 ret = deliver_skb(skb, pt_prev, orig_dev); 5392 5393 pt_prev = ptype; ··· 11748 11749 if (netdev_kobject_init()) 11749 11750 goto out; 11750 11751 11751 - INIT_LIST_HEAD(&ptype_all); 11752 11752 for (i = 0; i < PTYPE_HASH_SIZE; i++) 11753 11753 INIT_LIST_HEAD(&ptype_base[i]); 11754 11754
+1
net/core/hotdata.c
··· 7 7 8 8 struct net_hotdata net_hotdata __cacheline_aligned = { 9 9 .offload_base = LIST_HEAD_INIT(net_hotdata.offload_base), 10 + .ptype_all = LIST_HEAD_INIT(net_hotdata.ptype_all), 10 11 .gro_normal_batch = 8, 11 12 12 13 .netdev_budget = 300,
+4 -3
net/core/net-procfs.c
··· 3 3 #include <linux/proc_fs.h> 4 4 #include <linux/seq_file.h> 5 5 #include <net/wext.h> 6 + #include <net/hotdata.h> 6 7 7 8 #include "dev.h" 8 9 ··· 184 183 } 185 184 } 186 185 187 - list_for_each_entry_rcu(pt, &ptype_all, list) { 186 + list_for_each_entry_rcu(pt, &net_hotdata.ptype_all, list) { 188 187 if (i == pos) 189 188 return pt; 190 189 ++i; ··· 232 231 } 233 232 } 234 233 235 - nxt = ptype_all.next; 234 + nxt = net_hotdata.ptype_all.next; 236 235 goto ptype_all; 237 236 } 238 237 239 238 if (pt->type == htons(ETH_P_ALL)) { 240 239 ptype_all: 241 - if (nxt != &ptype_all) 240 + if (nxt != &net_hotdata.ptype_all) 242 241 goto found; 243 242 hash = 0; 244 243 nxt = ptype_base[0].next;