Commit 8e602ce2980fd6941dc0d3dda12e5095e8206f34

Authored by Eric Dumazet
Committed by David S. Miller
1 parent c60ce4e265

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>

Showing 2 changed files with 15 additions and 11 deletions Side-by-side Diff

include/net/net_namespace.h
... ... @@ -41,6 +41,8 @@
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 */
... ... @@ -52,7 +54,8 @@
52 54 struct ctl_table_set sysctls;
53 55 #endif
54 56  
55   - struct net_device *loopback_dev; /* The loopback */
  57 + struct sock *rtnl; /* rtnetlink socket */
  58 + struct sock *genl_sock;
56 59  
57 60 struct list_head dev_base_head;
58 61 struct hlist_head *dev_name_head;
59 62  
60 63  
... ... @@ -60,11 +63,9 @@
60 63  
61 64 /* core fib_rules */
62 65 struct list_head rules_ops;
63   - spinlock_t rules_mod_lock;
64 66  
65   - struct sock *rtnl; /* rtnetlink socket */
66   - struct sock *genl_sock;
67 67  
  68 + struct net_device *loopback_dev; /* The loopback */
68 69 struct netns_core core;
69 70 struct netns_mib mib;
70 71 struct netns_packet packet;
71 72  
... ... @@ -84,13 +85,15 @@
84 85 struct sock *nfnl;
85 86 struct sock *nfnl_stash;
86 87 #endif
87   -#ifdef CONFIG_XFRM
88   - struct netns_xfrm xfrm;
89   -#endif
90 88 #ifdef CONFIG_WEXT_CORE
91 89 struct sk_buff_head wext_nlevents;
92 90 #endif
93 91 struct net_generic *gen;
  92 +
  93 + /* Note : following structs are cache line aligned */
  94 +#ifdef CONFIG_XFRM
  95 + struct netns_xfrm xfrm;
  96 +#endif
94 97 };
95 98  
96 99  
include/net/netns/xfrm.h
... ... @@ -43,10 +43,6 @@
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;
... ... @@ -57,6 +53,11 @@
57 53 u32 sysctl_acq_expires;
58 54 #ifdef CONFIG_SYSCTL
59 55 struct ctl_table_header *sysctl_hdr;
  56 +#endif
  57 +
  58 + struct dst_ops xfrm4_dst_ops;
  59 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  60 + struct dst_ops xfrm6_dst_ops;
60 61 #endif
61 62 };
62 63