Skip to content

Commit 8e8118f

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: remove packet hotpath stats
These counters sit in hot path and do show up in perf, this is especially true for 'found' and 'searched' which get incremented for every packet processed. Information like searched=212030105 new=623431 found=333613 delete=623327 does not seem too helpful nowadays: - on busy systems found and searched will overflow every few hours (these are 32bit integers), other more busy ones every few days. - for debugging there are better methods, such as iptables' trace target, the conntrack log sysctls. Nowadays we also have perf tool. This removes packet path stat counters except those that are expected to be 0 (or close to 0) on a normal system, e.g. 'insert_failed' (race happened) or 'invalid' (proto tracker rejects). The insert stat is retained for the ctnetlink case. The found stat is retained for the tuple-is-taken check when NAT has to determine if it needs to pick a different source address. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 6bd1430 commit 8e8118f

File tree

5 files changed

+11
-29
lines changed

5 files changed

+11
-29
lines changed

include/linux/netfilter/nf_conntrack_common.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44
#include <uapi/linux/netfilter/nf_conntrack_common.h>
55

66
struct ip_conntrack_stat {
7-
unsigned int searched;
87
unsigned int found;
9-
unsigned int new;
108
unsigned int invalid;
119
unsigned int ignore;
12-
unsigned int delete;
13-
unsigned int delete_list;
1410
unsigned int insert;
1511
unsigned int insert_failed;
1612
unsigned int drop;

include/uapi/linux/netfilter/nfnetlink_conntrack.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,13 @@ enum ctattr_secctx {
231231

232232
enum ctattr_stats_cpu {
233233
CTA_STATS_UNSPEC,
234-
CTA_STATS_SEARCHED,
234+
CTA_STATS_SEARCHED, /* no longer used */
235235
CTA_STATS_FOUND,
236-
CTA_STATS_NEW,
236+
CTA_STATS_NEW, /* no longer used */
237237
CTA_STATS_INVALID,
238238
CTA_STATS_IGNORE,
239-
CTA_STATS_DELETE,
240-
CTA_STATS_DELETE_LIST,
239+
CTA_STATS_DELETE, /* no longer used */
240+
CTA_STATS_DELETE_LIST, /* no longer used */
241241
CTA_STATS_INSERT,
242242
CTA_STATS_INSERT_FAILED,
243243
CTA_STATS_DROP,

net/netfilter/nf_conntrack_core.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ static void
379379
destroy_conntrack(struct nf_conntrack *nfct)
380380
{
381381
struct nf_conn *ct = (struct nf_conn *)nfct;
382-
struct net *net = nf_ct_net(ct);
383382
struct nf_conntrack_l4proto *l4proto;
384383

385384
pr_debug("destroy_conntrack(%p)\n", ct);
@@ -406,7 +405,6 @@ destroy_conntrack(struct nf_conntrack *nfct)
406405

407406
nf_ct_del_from_dying_or_unconfirmed_list(ct);
408407

409-
NF_CT_STAT_INC(net, delete);
410408
local_bh_enable();
411409

412410
if (ct->master)
@@ -438,7 +436,6 @@ static void nf_ct_delete_from_lists(struct nf_conn *ct)
438436

439437
nf_ct_add_to_dying_list(ct);
440438

441-
NF_CT_STAT_INC(net, delete_list);
442439
local_bh_enable();
443440
}
444441

@@ -529,11 +526,8 @@ ____nf_conntrack_find(struct net *net, const struct nf_conntrack_zone *zone,
529526
if (nf_ct_is_dying(ct))
530527
continue;
531528

532-
if (nf_ct_key_equal(h, tuple, zone, net)) {
533-
NF_CT_STAT_INC_ATOMIC(net, found);
529+
if (nf_ct_key_equal(h, tuple, zone, net))
534530
return h;
535-
}
536-
NF_CT_STAT_INC_ATOMIC(net, searched);
537531
}
538532
/*
539533
* if the nulls value we got at the end of this lookup is
@@ -798,7 +792,6 @@ __nf_conntrack_confirm(struct sk_buff *skb)
798792
*/
799793
__nf_conntrack_hash_insert(ct, hash, reply_hash);
800794
nf_conntrack_double_unlock(hash, reply_hash);
801-
NF_CT_STAT_INC(net, insert);
802795
local_bh_enable();
803796

804797
help = nfct_help(ct);
@@ -857,7 +850,6 @@ nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
857850
rcu_read_unlock();
858851
return 1;
859852
}
860-
NF_CT_STAT_INC_ATOMIC(net, searched);
861853
}
862854

863855
if (get_nulls_value(n) != hash) {
@@ -1177,10 +1169,8 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,
11771169
}
11781170
spin_unlock(&nf_conntrack_expect_lock);
11791171
}
1180-
if (!exp) {
1172+
if (!exp)
11811173
__nf_ct_try_assign_helper(ct, tmpl, GFP_ATOMIC);
1182-
NF_CT_STAT_INC(net, new);
1183-
}
11841174

11851175
/* Now it is inserted into the unconfirmed list, bump refcount */
11861176
nf_conntrack_get(&ct->ct_general);

net/netfilter/nf_conntrack_netlink.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,13 +1984,9 @@ ctnetlink_ct_stat_cpu_fill_info(struct sk_buff *skb, u32 portid, u32 seq,
19841984
nfmsg->version = NFNETLINK_V0;
19851985
nfmsg->res_id = htons(cpu);
19861986

1987-
if (nla_put_be32(skb, CTA_STATS_SEARCHED, htonl(st->searched)) ||
1988-
nla_put_be32(skb, CTA_STATS_FOUND, htonl(st->found)) ||
1989-
nla_put_be32(skb, CTA_STATS_NEW, htonl(st->new)) ||
1987+
if (nla_put_be32(skb, CTA_STATS_FOUND, htonl(st->found)) ||
19901988
nla_put_be32(skb, CTA_STATS_INVALID, htonl(st->invalid)) ||
19911989
nla_put_be32(skb, CTA_STATS_IGNORE, htonl(st->ignore)) ||
1992-
nla_put_be32(skb, CTA_STATS_DELETE, htonl(st->delete)) ||
1993-
nla_put_be32(skb, CTA_STATS_DELETE_LIST, htonl(st->delete_list)) ||
19941990
nla_put_be32(skb, CTA_STATS_INSERT, htonl(st->insert)) ||
19951991
nla_put_be32(skb, CTA_STATS_INSERT_FAILED,
19961992
htonl(st->insert_failed)) ||

net/netfilter/nf_conntrack_standalone.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,13 @@ static int ct_cpu_seq_show(struct seq_file *seq, void *v)
352352
seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
353353
"%08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
354354
nr_conntracks,
355-
st->searched,
355+
0,
356356
st->found,
357-
st->new,
357+
0,
358358
st->invalid,
359359
st->ignore,
360-
st->delete,
361-
st->delete_list,
360+
0,
361+
0,
362362
st->insert,
363363
st->insert_failed,
364364
st->drop,

0 commit comments

Comments
 (0)