netfilter: remove extra timer from ecache extension
Subsystems (2)
Florian Westphal
maintainerPATCH 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 timer to re-trigger event delivery. When we enqueue a ct entry into the dying list, the timer will be scheduled.
The timer will then deliver up to 20 entries. If not all pending entries could be delivered, it will re-add itself to run again after 2 jiffies. This gives userspace consumers time to drain their sockets.
When userspace listeners don't accept events at all, re-try is done after 10ms.
If an event was sucessfully delivered via the normal delivery path, we take this as a hint that userspace has processed its backlog and re-try pending entries on the next timer tick.
This speeds up re-delivery without adding too much overhead.
While at it, dying list handling is moved into ecache.c, since its only revlevant if ct events are enabled.
---
Pablo,
it would be great if you could give this one a spin in your conntrackd testsetup.
It avoids the "perpertual-busy-retry" of the previous tasklet-based approach.
include/net/netfilter/nf_conntrack.h | 1 - include/net/netfilter/nf_conntrack_ecache.h | 15 ++++++- include/net/netns/conntrack.h | 5 ++- net/netfilter/nf_conntrack_core.c | 55 +---------------------- net/netfilter/nf_conntrack_ecache.c | 64 ++++++++++++++++++++++---- net/netfilter/nf_conntrack_netlink.c | 2 +- 6 files changed, 76 insertions(+), 66 deletions(-)
include/net/netfilter/nf_conntrack.h +0 -1
@@ -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 +14 -1
@@ -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 *
@@ -210,6 +209,17 @@ nf_ct_expect_event(enum ip_conntrack_expect_events event,extern int nf_conntrack_ecache_init (struct net *net);extern void nf_conntrack_ecache_fini (struct net *net); +static inline void nf_ct_dying_timer_set (struct net *net) +{ +if (!net->ct.dying_backlogged) +mod_timer (&net->ct.dying_timer, jiffies); +} + +static inline void nf_ct_dying_timer_retry (struct net *net) +{ +if (net->ct.dying_backlogged) +mod_timer (&net->ct.dying_timer, jiffies); +}#else /* CONFIG_NF_CONNTRACK_EVENTS */ static inline void nf_conntrack_event_cache(enum ip_conntrack_events event,
@@ -232,6 +242,9 @@ static inline void nf_ct_expect_event_report(enum ip_conntrack_expect_events e, u32 portid, int report) {} +static inline void nf_ct_dying_timer_set (struct net *net) { } +static inline void nf_ct_dying_timer_retry (struct net *net) { } +static inline int nf_conntrack_ecache_init (struct net *net) {return 0 ;
include/net/netns/conntrack.h +4 -1
@@ -71,11 +71,14 @@ struct netns_ct {struct hlist_head *expect_hash;struct hlist_nulls_head unconfirmed;struct hlist_nulls_head dying; +#ifdef CONFIG_NF_CONNTRACK_EVENTS +struct timer_list dying_timer; +bool dying_backlogged; +#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 +3 -52
84 lines not on this page · raw message
net/netfilter/nf_conntrack_ecache.c +54 -10
103 lines not on this page · raw message
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -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_timer_set (net);nf_ct_put (ct);return 0 ; }
Signature · 1 line
1.7.8.6
Pablo Neira Ayuso
maintainerHi Florian,
Quoted 22 lines · Florian Westphal
This brings the (per-conntrack) ecache extension back to 24 bytes in size (was 112 byte on
x86_64with lockdep on).Instead we use a per-ns timer to re-trigger event delivery. When we enqueue a ct entry into the dying list, the timer will be scheduled.
The timer will then deliver up to 20 entries. If not all pending entries could be delivered, it will re-add itself to run again after 2 jiffies. This gives userspace consumers time to drain their sockets.
When userspace listeners don't accept events at all, re-try is done after 10ms.
If an event was sucessfully delivered via the normal delivery path, we take this as a hint that userspace has processed its backlog and re-try pending entries on the next timer tick.
This speeds up re-delivery without adding too much overhead.While at it, dying list handling is moved into
ecache.c, since its only revlevant if ct events are enabled.Signed-off-by Florian Westphal <[email protected]>
Quoted 8 lines
---
Pablo,it would be great if you could give this one a spin in your conntrackd testsetup.
It avoids the "perpertual-busy-retry" of the previous tasklet-based approach.
# hits hits/s ^h/s ^bytes kB/s errs rst tout mhtime
1225183 15125 19051 4019761 3116 0 0 6 0.003
1243714 15167 18531 3910041 3125 0 0 6 0.003
1253179 15098 9465 1997115 3111 0 0 6 0.001
1261138 15013 7959 1679349 3093 0 0 6 0.001
1270189 14943 9051 1909761 3079 0 0 6 3.008
1288838 14986 18649 3934939 3088 0 0 6 3.005
1306825 15020 17987 3795257 3095 0 0 6 0.003
1319849 14998 13024 2748064 3090 0 0 6 0.001
1332884 14976 13035 2750385 3085 0 0 6 0.001
1346978 14966 14094 2973834 3083 0 0 6 3.008
1365928 15010 18950 3998450 3092 0 0 6 0.003
1382430 15026 16502 3481922 3096 0 0 6 0.003
1396355 15014 13925 2938175 3093 0 0 6 0.001
1410313 15003 13958 2945138 3091 0 0 6 0.001
1426706 15017 16393 3458923 3094 0 0 6 3.005
1445630 15058 18924 3992964 3102 0 0 6 0.003
# hits hits/s ^h/s ^bytes kB/s errs rst tout mhtime
1458656 15037 13026 2748486 3098 0 0 6 0.001
1471710 15017 13054 2754394 3094 0 0 6 0.001
1484990 14999 13280 2802080 3090 0 0 6 3.008
1504167 15041 19177 4046347 3099 0 0 6 0.004
1517647 15026 13480 2844280 3096 0 0 6 0.002
^^^^^The important is the third column, that represents the real flows per second.
Better and more stable than the previous patch, but still hitting:
[ 623.309409] net_ratelimit: 11 callbacks suppressed [ 623.309470] nf_conntrack: table full, dropping packet
More thoughts:
The current approach ramdomly distributes the retries in the range between 0 and 15 seconds. The random distribution of timers works fine in practise to avoid re-delivery more than one event in one single shot.
Note that the effect of this random distribution is that the busier the dying list gets, the more frequently the routine to re-deliver of *one conntrack* is called.
I think this can be emulated with one single timer. The point would be to keep a counter with the number of conntracks in the dying list. That counter can be used to implement some adaptive timer to trigger the re-delivery routine more frequently for one single conntrack.
Regards.