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

netns: reorder fields in struct net

In a network bench, I noticed an unfortunate false sharing between
'loopback_dev' and 'count' fields in "struct net".

'count' is written each time a socket is created or destroyed, while
loopback_dev might be often read in routing code.

Move loopback_dev in a read mostly section of "struct net"

Note: struct netns_xfrm is cache line aligned on SMP.
(It contains a "struct dst_ops")
Move it at the end to avoid holes, and reduce sizeof(struct net) by 128
bytes on ia32.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Eric Dumazet and committed by
David S. Miller
8e602ce2 c60ce4e2

+15 -11
+10 -7
include/net/net_namespace.h
··· 41 41 * destroy on demand 42 42 */ 43 43 #endif 44 + spinlock_t rules_mod_lock; 45 + 44 46 struct list_head list; /* list of network namespaces */ 45 47 struct list_head cleanup_list; /* namespaces on death row */ 46 48 struct list_head exit_list; /* Use only net_mutex */ ··· 54 52 struct ctl_table_set sysctls; 55 53 #endif 56 54 57 - struct net_device *loopback_dev; /* The loopback */ 55 + struct sock *rtnl; /* rtnetlink socket */ 56 + struct sock *genl_sock; 58 57 59 58 struct list_head dev_base_head; 60 59 struct hlist_head *dev_name_head; ··· 63 60 64 61 /* core fib_rules */ 65 62 struct list_head rules_ops; 66 - spinlock_t rules_mod_lock; 67 63 68 - struct sock *rtnl; /* rtnetlink socket */ 69 - struct sock *genl_sock; 70 64 65 + struct net_device *loopback_dev; /* The loopback */ 71 66 struct netns_core core; 72 67 struct netns_mib mib; 73 68 struct netns_packet packet; ··· 85 84 struct sock *nfnl; 86 85 struct sock *nfnl_stash; 87 86 #endif 88 - #ifdef CONFIG_XFRM 89 - struct netns_xfrm xfrm; 90 - #endif 91 87 #ifdef CONFIG_WEXT_CORE 92 88 struct sk_buff_head wext_nlevents; 93 89 #endif 94 90 struct net_generic *gen; 91 + 92 + /* Note : following structs are cache line aligned */ 93 + #ifdef CONFIG_XFRM 94 + struct netns_xfrm xfrm; 95 + #endif 95 96 }; 96 97 97 98
+5 -4
include/net/netns/xfrm.h
··· 43 43 unsigned int policy_count[XFRM_POLICY_MAX * 2]; 44 44 struct work_struct policy_hash_work; 45 45 46 - struct dst_ops xfrm4_dst_ops; 47 - #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 48 - struct dst_ops xfrm6_dst_ops; 49 - #endif 50 46 51 47 struct sock *nlsk; 52 48 struct sock *nlsk_stash; ··· 53 57 u32 sysctl_acq_expires; 54 58 #ifdef CONFIG_SYSCTL 55 59 struct ctl_table_header *sysctl_hdr; 60 + #endif 61 + 62 + struct dst_ops xfrm4_dst_ops; 63 + #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 64 + struct dst_ops xfrm6_dst_ops; 56 65 #endif 57 66 }; 58 67