Commit 8cf4d6a224a0226987d9cba69cb46d93814fe449

Authored by Jesper Dangaard Brouer
Committed by Pablo Neira Ayuso
1 parent 6853605360

net: reorder struct netns_ct for better cache-line usage

Reorder struct netns_ct so that atomic_t "count" changes don't
slowdown users of read mostly fields.

This is based on Eric Dumazet's proposed patch:
 "netfilter: conntrack: remove the central spinlock"
 http://thread.gmane.org/gmane.linux.network/268758/focus=47306

The tricky part of cache-aligning this structure, that it is getting
inlined in struct net (include/net/net_namespace.h), thus changes to
other netns_xxx structures affects our alignment.

Eric's original patch contained an ambiguity on 32-bit regarding
alignment in struct net.  This patch also takes 32-bit into account,
and in case of changed (struct net) alignment sysctl_xxx entries have
been ordered according to how often they are accessed.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Reviewed-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Showing 1 changed file with 17 additions and 16 deletions Inline Diff

include/net/netns/conntrack.h
1 #ifndef __NETNS_CONNTRACK_H 1 #ifndef __NETNS_CONNTRACK_H
2 #define __NETNS_CONNTRACK_H 2 #define __NETNS_CONNTRACK_H
3 3
4 #include <linux/list.h> 4 #include <linux/list.h>
5 #include <linux/list_nulls.h> 5 #include <linux/list_nulls.h>
6 #include <linux/atomic.h> 6 #include <linux/atomic.h>
7 #include <linux/netfilter/nf_conntrack_tcp.h> 7 #include <linux/netfilter/nf_conntrack_tcp.h>
8 8
9 struct ctl_table_header; 9 struct ctl_table_header;
10 struct nf_conntrack_ecache; 10 struct nf_conntrack_ecache;
11 11
12 struct nf_proto_net { 12 struct nf_proto_net {
13 #ifdef CONFIG_SYSCTL 13 #ifdef CONFIG_SYSCTL
14 struct ctl_table_header *ctl_table_header; 14 struct ctl_table_header *ctl_table_header;
15 struct ctl_table *ctl_table; 15 struct ctl_table *ctl_table;
16 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT 16 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
17 struct ctl_table_header *ctl_compat_header; 17 struct ctl_table_header *ctl_compat_header;
18 struct ctl_table *ctl_compat_table; 18 struct ctl_table *ctl_compat_table;
19 #endif 19 #endif
20 #endif 20 #endif
21 unsigned int users; 21 unsigned int users;
22 }; 22 };
23 23
24 struct nf_generic_net { 24 struct nf_generic_net {
25 struct nf_proto_net pn; 25 struct nf_proto_net pn;
26 unsigned int timeout; 26 unsigned int timeout;
27 }; 27 };
28 28
29 struct nf_tcp_net { 29 struct nf_tcp_net {
30 struct nf_proto_net pn; 30 struct nf_proto_net pn;
31 unsigned int timeouts[TCP_CONNTRACK_TIMEOUT_MAX]; 31 unsigned int timeouts[TCP_CONNTRACK_TIMEOUT_MAX];
32 unsigned int tcp_loose; 32 unsigned int tcp_loose;
33 unsigned int tcp_be_liberal; 33 unsigned int tcp_be_liberal;
34 unsigned int tcp_max_retrans; 34 unsigned int tcp_max_retrans;
35 }; 35 };
36 36
37 enum udp_conntrack { 37 enum udp_conntrack {
38 UDP_CT_UNREPLIED, 38 UDP_CT_UNREPLIED,
39 UDP_CT_REPLIED, 39 UDP_CT_REPLIED,
40 UDP_CT_MAX 40 UDP_CT_MAX
41 }; 41 };
42 42
43 struct nf_udp_net { 43 struct nf_udp_net {
44 struct nf_proto_net pn; 44 struct nf_proto_net pn;
45 unsigned int timeouts[UDP_CT_MAX]; 45 unsigned int timeouts[UDP_CT_MAX];
46 }; 46 };
47 47
48 struct nf_icmp_net { 48 struct nf_icmp_net {
49 struct nf_proto_net pn; 49 struct nf_proto_net pn;
50 unsigned int timeout; 50 unsigned int timeout;
51 }; 51 };
52 52
53 struct nf_ip_net { 53 struct nf_ip_net {
54 struct nf_generic_net generic; 54 struct nf_generic_net generic;
55 struct nf_tcp_net tcp; 55 struct nf_tcp_net tcp;
56 struct nf_udp_net udp; 56 struct nf_udp_net udp;
57 struct nf_icmp_net icmp; 57 struct nf_icmp_net icmp;
58 struct nf_icmp_net icmpv6; 58 struct nf_icmp_net icmpv6;
59 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT) 59 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
60 struct ctl_table_header *ctl_table_header; 60 struct ctl_table_header *ctl_table_header;
61 struct ctl_table *ctl_table; 61 struct ctl_table *ctl_table;
62 #endif 62 #endif
63 }; 63 };
64 64
65 struct netns_ct { 65 struct netns_ct {
66 atomic_t count; 66 atomic_t count;
67 unsigned int expect_count; 67 unsigned int expect_count;
68 #ifdef CONFIG_SYSCTL
69 struct ctl_table_header *sysctl_header;
70 struct ctl_table_header *acct_sysctl_header;
71 struct ctl_table_header *tstamp_sysctl_header;
72 struct ctl_table_header *event_sysctl_header;
73 struct ctl_table_header *helper_sysctl_header;
74 #endif
75 char *slabname;
76 unsigned int sysctl_log_invalid; /* Log invalid packets */
77 unsigned int sysctl_events_retry_timeout;
78 int sysctl_events;
79 int sysctl_acct;
80 int sysctl_auto_assign_helper;
81 bool auto_assign_helper_warned;
82 int sysctl_tstamp;
83 int sysctl_checksum;
84
68 unsigned int htable_size; 85 unsigned int htable_size;
69 struct kmem_cache *nf_conntrack_cachep; 86 struct kmem_cache *nf_conntrack_cachep;
70 struct hlist_nulls_head *hash; 87 struct hlist_nulls_head *hash;
71 struct hlist_head *expect_hash; 88 struct hlist_head *expect_hash;
72 struct hlist_nulls_head unconfirmed; 89 struct hlist_nulls_head unconfirmed;
73 struct hlist_nulls_head dying; 90 struct hlist_nulls_head dying;
74 struct hlist_nulls_head tmpl; 91 struct hlist_nulls_head tmpl;
75 struct ip_conntrack_stat __percpu *stat; 92 struct ip_conntrack_stat __percpu *stat;
76 struct nf_ct_event_notifier __rcu *nf_conntrack_event_cb; 93 struct nf_ct_event_notifier __rcu *nf_conntrack_event_cb;
77 struct nf_exp_event_notifier __rcu *nf_expect_event_cb; 94 struct nf_exp_event_notifier __rcu *nf_expect_event_cb;
78 int sysctl_events;
79 unsigned int sysctl_events_retry_timeout;
80 int sysctl_acct;
81 int sysctl_tstamp;
82 int sysctl_checksum;
83 unsigned int sysctl_log_invalid; /* Log invalid packets */
84 int sysctl_auto_assign_helper;
85 bool auto_assign_helper_warned;
86 struct nf_ip_net nf_ct_proto; 95 struct nf_ip_net nf_ct_proto;
87 #if defined(CONFIG_NF_CONNTRACK_LABELS) 96 #if defined(CONFIG_NF_CONNTRACK_LABELS)
88 unsigned int labels_used; 97 unsigned int labels_used;
89 u8 label_words; 98 u8 label_words;