Skip to contentSkip to conversation

netfilter: remove extra timer from ecache extension

PATCH Superseded Florian Westphal 2 participants 4 messages Dec 4, 2012

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH v2 1/1 netfilter: remove extra timer from ecache extension

This brings the (per-conntrack) ecache extension back to 24 bytes in size (was 112 byte on x86_64 with lockdep on).

Instead we use a per-ns tasklet to re-trigger event delivery. When we enqueue a ct entry into the dying list, the tasklet is scheduled.

The tasklet will then deliver up to 20 entries. It will re-sched itself unless all the pending events could be delivered.

While at it, dying list handling is moved into ecache.c, since its only revlevant if ct events are enabled.

---
Changes since V1:
- rebase on top of nf-next master
- remove nf_ct_release_dying_list (we can simply wait for the tasklet until all entries are gone. This should happen very quickly since all listeners are gone at this point).

 include/net/netfilter/nf_conntrack.h        |    1 -
 include/net/netfilter/nf_conntrack_ecache.h |    4 +-
 include/net/netns/conntrack.h               |    5 ++-
 net/netfilter/nf_conntrack_core.c           |   54 +--------------------------
 net/netfilter/nf_conntrack_ecache.c         |   54 ++++++++++++++++++++++-----
 net/netfilter/nf_conntrack_netlink.c        |    2 +-
 6 files changed, 54 insertions(+), 66 deletions(-)
include/net/netfilter/nf_conntrack.h +0 -1
index caca0c4..e1cc862 100644
@@ -182,7 +182,6 @@ __nf_conntrack_find(struct net *net, u16 zone,
 
 extern int nf_conntrack_hash_check_insert(struct nf_conn *ct);
 extern void nf_ct_delete_from_lists(struct nf_conn *ct);
-extern void nf_ct_dying_timeout(struct nf_conn *ct);
 
 extern void nf_conntrack_flush_report(struct net *net, u32 pid, int report);
 
include/net/netfilter/nf_conntrack_ecache.h +3 -1
index 5654d29..07c71e9 100644
@@ -18,7 +18,6 @@ struct nf_conntrack_ecache {
 	u16 ctmask;		/* bitmask of ct events to be delivered */
 	u16 expmask;		/* bitmask of expect events to be delivered */
 	u32 portid;		/* netlink portid of destroyer */
-	struct timer_list timeout;
 };
 
 static inline struct nf_conntrack_ecache *
@@ -207,6 +206,7 @@ nf_ct_expect_event(enum ip_conntrack_expect_events event,
 	nf_ct_expect_event_report(event, exp, 0, 0);
 }
 
+extern void nf_ct_dying_schedule(struct net *net);
 extern int nf_conntrack_ecache_init(struct net *net);
 extern void nf_conntrack_ecache_fini(struct net *net);
 
@@ -232,6 +232,8 @@ static inline void nf_ct_expect_event_report(enum ip_conntrack_expect_events e,
  					     u32 portid,
  					     int report) {}
 
+static inline void nf_ct_dying_schedule(struct net *net) { }
+
 static inline int nf_conntrack_ecache_init(struct net *net)
 {
 	return 0;
include/net/netns/conntrack.h +4 -1
index a1d83cc..0cef968 100644
@@ -4,6 +4,7 @@
 #include <linux/list.h>
 #include <linux/list_nulls.h>
 #include <linux/atomic.h>
+#include <linux/interrupt.h>
 #include <linux/netfilter/nf_conntrack_tcp.h>
 
 struct ctl_table_header;
@@ -71,11 +72,13 @@ struct netns_ct {
 	struct hlist_head	*expect_hash;
 	struct hlist_nulls_head	unconfirmed;
 	struct hlist_nulls_head	dying;
+#ifdef CONFIG_NF_CONNTRACK_EVENTS
+	struct tasklet_struct dying_tasklet;
+#endif
 	struct ip_conntrack_stat __percpu *stat;
 	struct nf_ct_event_notifier __rcu *nf_conntrack_event_cb;
 	struct nf_exp_event_notifier __rcu *nf_expect_event_cb;
 	int			sysctl_events;
-	unsigned int		sysctl_events_retry_timeout;
 	int			sysctl_acct;
 	int			sysctl_tstamp;
 	int			sysctl_checksum;
net/netfilter/nf_conntrack_core.c +2 -52

78 lines not on this page · raw message

net/netfilter/nf_conntrack_ecache.c +44 -10

96 lines not on this page · raw message

net/netfilter/nf_conntrack_netlink.c +1 -1
index 4e078cd..6e808ad 100644
@@ -992,7 +992,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
 					      nlmsg_report(nlh)) < 0) {
 			nf_ct_delete_from_lists(ct);
 			/* we failed to report the event, try later */
-			nf_ct_dying_timeout(ct);
+			nf_ct_dying_schedule(net);
 			nf_ct_put(ct);
 			return 0;
 		}
Signature · 1 line
1.7.8.6
#1 lore raw

Hi Florian,

Quoted 11 lines · Florian Westphal

This brings the (per-conntrack) ecache extension back to 24 bytes in size (was 112 byte on x86_64 with lockdep on).

Instead we use a per-ns tasklet to re-trigger event delivery. When we enqueue a ct entry into the dying list, the tasklet is scheduled.

The tasklet will then deliver up to 20 entries. It will re-sched itself unless all the pending events could be delivered.

While at it, dying list handling is moved into ecache.c, since its only revlevant if ct events are enabled.

Just tested this. My testbed consists of two firewalls in HA running conntrackd with event reliable mode. I've got a client that generates lots of small TCP flows that goes through the firewalls and reach a benchmark server.

This is my analysis:

conntrack -C shows:

253244
254798
256754
258807
261548 <--- we hit table full, dropping packets 176849 <--- it seems the tasklet gets a chance to run
given that we get less interruptions from the NIC
166449 <--- it slightly empty the dying list
131176
55602
28316
28317
28317

#  hits  hits/s  ^h/s  ^bytes   kB/s  errs   rst  tout  mhtime
4796894 15727 16509   2393805   2227     0     0     0   0.005
4813038 15728 16144   2340880   2227     0     0     0   0.005
4828796 15728 15758   2284910   2227     0     0     0   0.005
4845279 15731 16483   2390035   2227     0     0     0   0.005
4860956 15731 15677   2273165   2227     0     0     0   0.005
4876826 15731 15870   2301150   2227     0     0     0   0.005
4883165 15701  6339    919155   2223     0     0     0   0.004
4883165 15651     0         0   2216     0     0     0   0.000  <--- table full
4883165 15601     0         0   2209     0     0     0   0.000
4894657 15588 11492   1666340   2207     0     0     0   3.008
4913408 15598 18751   2718895   2208     0     0     0   0.004
4931896 15607 18488   2680760   2210     0     0     0   0.004

So it seems the tasklet gets starved under heavy load.

This happens on and on, so after some time we hit table full and again the dying list is empty.

These are old HP proliant DL145G2 from 2005, that's why the maximum flows/s looks low.

Looking at the number and the behaviour under heavy stress, I think we have to consider a different approach.

author maintainer
#2 lore raw
Quoted 21 lines · Pablo Neira Ayuso
Quoted 11 lines · Florian Westphal

This brings the (per-conntrack) ecache extension back to 24 bytes in size (was 112 byte on x86_64 with lockdep on).

Instead we use a per-ns tasklet to re-trigger event delivery. When we enqueue a ct entry into the dying list, the tasklet is scheduled.

The tasklet will then deliver up to 20 entries. It will re-sched itself unless all the pending events could be delivered.

While at it, dying list handling is moved into ecache.c, since its only revlevant if ct events are enabled.

Just tested this. My testbed consists of two firewalls in HA running conntrackd with event reliable mode. I've got a client that generates lots of small TCP flows that goes through the firewalls and reach a benchmark server.

This is my analysis:

conntrack -C shows:

[..]

Quoted 7 lines

261548 <--- we hit table full, dropping packets 176849 <--- it seems the tasklet gets a chance to run
given that we get less interruptions from the NIC
166449 <--- it slightly empty the dying list
131176
55602
28316

[..]

Quoted 16 lines
#  hits  hits/s  ^h/s  ^bytes   kB/s  errs   rst  tout  mhtime
4796894 15727 16509   2393805   2227     0     0     0   0.005
4813038 15728 16144   2340880   2227     0     0     0   0.005
4828796 15728 15758   2284910   2227     0     0     0   0.005
4845279 15731 16483   2390035   2227     0     0     0   0.005
4860956 15731 15677   2273165   2227     0     0     0   0.005
4876826 15731 15870   2301150   2227     0     0     0   0.005
4883165 15701  6339    919155   2223     0     0     0   0.004
4883165 15651     0         0   2216     0     0     0   0.000  <--- table full
4883165 15601     0         0   2209     0     0     0   0.000
4894657 15588 11492   1666340   2207     0     0     0   3.008
4913408 15598 18751   2718895   2208     0     0     0   0.004
4931896 15607 18488   2680760   2210     0     0     0   0.004

So it seems the tasklet gets starved under heavy load.

Quoted 8 lines

This happens on and on, so after some time we hit table full and again the dying list is empty.

These are old HP proliant DL145G2 from 2005, that's why the maximum flows/s looks low.

Looking at the number and the behaviour under heavy stress, I think we have to consider a different approach.

Thanks for testing. Is that a single cpu machine?

If yes, I think this result might be because the tasklet busy-loop competes with conntrackd for cpu, so essentially we waste cycles on futile re-delivery instead of leaving the cpu to conntrackd, (which should process events).

If thats true, then we might be able to improve this by avoiding the 'tasklet re-scheds itself'. This would also solve the 'softirqd eats 100% cpu' when conntrackd is stopped/suspended.

I'll see if I can cook up a patch some time tomorrow.

Thanks,
Florian

#3 lore raw
Quoted 50 lines · Florian Westphal
Quoted 21 lines · Pablo Neira Ayuso
Quoted 11 lines · Florian Westphal

This brings the (per-conntrack) ecache extension back to 24 bytes in size (was 112 byte on x86_64 with lockdep on).

Instead we use a per-ns tasklet to re-trigger event delivery. When we enqueue a ct entry into the dying list, the tasklet is scheduled.

The tasklet will then deliver up to 20 entries. It will re-sched itself unless all the pending events could be delivered.

While at it, dying list handling is moved into ecache.c, since its only revlevant if ct events are enabled.

Just tested this. My testbed consists of two firewalls in HA running conntrackd with event reliable mode. I've got a client that generates lots of small TCP flows that goes through the firewalls and reach a benchmark server.

This is my analysis:

conntrack -C shows:

[..]

Quoted 7 lines

261548 <--- we hit table full, dropping packets 176849 <--- it seems the tasklet gets a chance to run
given that we get less interruptions from the NIC
166449 <--- it slightly empty the dying list
131176
55602
28316

[..]

Quoted 19 lines
#  hits  hits/s  ^h/s  ^bytes   kB/s  errs   rst  tout  mhtime
4796894 15727 16509   2393805   2227     0     0     0   0.005
4813038 15728 16144   2340880   2227     0     0     0   0.005
4828796 15728 15758   2284910   2227     0     0     0   0.005
4845279 15731 16483   2390035   2227     0     0     0   0.005
4860956 15731 15677   2273165   2227     0     0     0   0.005
4876826 15731 15870   2301150   2227     0     0     0   0.005
4883165 15701  6339    919155   2223     0     0     0   0.004
4883165 15651     0         0   2216     0     0     0   0.000  <--- table full
4883165 15601     0         0   2209     0     0     0   0.000
4894657 15588 11492   1666340   2207     0     0     0   3.008
4913408 15598 18751   2718895   2208     0     0     0   0.004
4931896 15607 18488   2680760   2210     0     0     0   0.004

So it seems the tasklet gets starved under heavy load.

This happens on and on, so after some time we hit table full and again the dying list is empty.

Quoted 7 lines
Quoted 5 lines

These are old HP proliant DL145G2 from 2005, that's why the maximum flows/s looks low.

Looking at the number and the behaviour under heavy stress, I think we have to consider a different approach.

Thanks for testing. Is that a single cpu machine?

Single cpu with two cores.

Quoted 4 lines

If yes, I think this result might be because the tasklet busy-loop competes with conntrackd for cpu, so essentially we waste cycles on futile re-delivery instead of leaving the cpu to conntrackd, (which should process events).

Makes sense.

Quoted 5 lines

If thats true, then we might be able to improve this by avoiding the 'tasklet re-scheds itself'. This would also solve the 'softirqd eats 100% cpu' when conntrackd is stopped/suspended.

I'll see if I can cook up a patch some time tomorrow.

That's fine.

Thanks.