net/netfilter: minor refactoring of conntrack ecache
Subsystems (3)
cover net/netfilter: minor refactoring of conntrack ecache
While working at my project, saw some issues that better to refactor and save a bit of CPU cycles. So, here they are.
Patches based on net-next tree.
Tony Zelenoff (3):
net/netfilter: whitespace removed net/netfilter: refactor notifier registration net/netfilter: refactor nf_ct_deliver_cached_events
net/netfilter/nf_conntrack_ecache.c | 81 +++++++++++++++++------------------ 1 files changed, 39 insertions(+), 42 deletions(-)
PATCH 1/3 net/netfilter: whitespace removed
--- net/netfilter/nf_conntrack_ecache.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/netfilter/nf_conntrack_ecache.c +1 -1
@@ -70,7 +70,7 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct)else e->missed &= ~missed;spin_unlock_bh (&ct->lock); - } + } } out_unlock:
Signature · 1 line
1.7.1
PATCH 2/3 net/netfilter: refactor notifier registration
In reply to Tony Zelenoff* ret variable initialization removed as useless
* Similar code strings concatenated and functions code flow became more plain
--- net/netfilter/nf_conntrack_ecache.c | 26 ++++++++++---------------- 1 files changed, 10 insertions(+), 16 deletions(-)
net/netfilter/nf_conntrack_ecache.c +10 -16
@@ -81,21 +81,18 @@ EXPORT_SYMBOL_GPL(nf_ct_deliver_cached_events);int nf_conntrack_register_notifier (struct net *net,struct nf_ct_event_notifier *new) { -int ret =0 ; +int ret;struct nf_ct_event_notifier *notify;mutex_lock (&nf_ct_ecache_mutex); notify =rcu_dereference_protected (net->ct.nf_conntrack_event_cb,lockdep_is_held (&nf_ct_ecache_mutex)); -if (notify !=NULL ) { +if (likely (!notify)) { +rcu_assign_pointer (net->ct.nf_conntrack_event_cb, new); + ret =0 ; + }else ret = -EBUSY ; - goto out_unlock; - } -rcu_assign_pointer (net->ct.nf_conntrack_event_cb, new); -mutex_unlock (&nf_ct_ecache_mutex); -return ret; -out_unlock:mutex_unlock (&nf_ct_ecache_mutex);return ret; }
@@ -118,21 +115,18 @@ EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);int nf_ct_expect_register_notifier (struct net *net,struct nf_exp_event_notifier *new) { -int ret =0 ; +int ret;struct nf_exp_event_notifier *notify;mutex_lock (&nf_ct_ecache_mutex); notify =rcu_dereference_protected (net->ct.nf_expect_event_cb,lockdep_is_held (&nf_ct_ecache_mutex)); -if (notify !=NULL ) { +if (likely (!notify)) { +rcu_assign_pointer (net->ct.nf_expect_event_cb, new); + ret =0 ; + }else ret = -EBUSY ; - goto out_unlock; - } -rcu_assign_pointer (net->ct.nf_expect_event_cb, new); -mutex_unlock (&nf_ct_ecache_mutex); -return ret; -out_unlock:mutex_unlock (&nf_ct_ecache_mutex);return ret; }
Signature · 1 line
1.7.1
PATCH 3/3 net/netfilter: refactor nf_ct_deliver_cached_events
In reply to Tony Zelenoff* identation lowered
* some CPU cycles saved at delayed item variable initialization
--- net/netfilter/nf_conntrack_ecache.c | 55 ++++++++++++++++++---------------- 1 files changed, 29 insertions(+), 26 deletions(-)
net/netfilter/nf_conntrack_ecache.c +29 -26
@@ -32,9 +32,11 @@ static DEFINE_MUTEX(nf_ct_ecache_mutex);void nf_ct_deliver_cached_events (struct nf_conn *ct) {struct net *net =nf_ct_net (ct); -unsigned long events; +unsigned long events, missed;struct nf_ct_event_notifier *notify;struct nf_conntrack_ecache *e; +struct nf_ct_event item; +int ret;rcu_read_lock (); notify =rcu_dereference (net->ct.nf_conntrack_event_cb);
@@ -47,31 +49,32 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct) events =xchg (&e->cache,0 ); -if (nf_ct_is_confirmed (ct) && !nf_ct_is_dying (ct) && events) { -struct nf_ct_event item = { - .ct = ct, - .pid =0 , - .report =0 - }; -int ret; -/* We make a copy of the missed event cache without taking -* the lock, thus we may send missed events twice. However, -* this does not harm and it happens very rarely. */ -unsigned long missed = e->missed; - -if (!((events | missed) & e->ctmask)) - goto out_unlock; - - ret = notify->fcn (events | missed, &item); -if (unlikely (ret <0 || missed)) { -spin_lock_bh (&ct->lock); -if (ret <0 ) - e->missed |= events; -else - e->missed &= ~missed; -spin_unlock_bh (&ct->lock); - } - } +if (!nf_ct_is_confirmed (ct) ||nf_ct_is_dying (ct) || !events) + goto out_unlock; + +/* We make a copy of the missed event cache without taking +* the lock, thus we may send missed events twice. However, +* this does not harm and it happens very rarely. */ + missed = e->missed; + +if (!((events | missed) & e->ctmask)) + goto out_unlock; + + item.ct = ct; + item.pid =0 ; + item.report =0 ; + + ret = notify->fcn (events | missed, &item); + +if (likely (ret >=0 && !missed)) + goto out_unlock; + +spin_lock_bh (&ct->lock); +if (ret <0 ) + e->missed |= events; +else + e->missed &= ~missed; +spin_unlock_bh (&ct->lock); out_unlock:rcu_read_unlock ();
Signature · 1 line
1.7.1
David Miller
maintainerFrom: Tony Zelenoff <[email protected]>
Date: Tue, 21 Feb 2012 21:26:28 +0400
Quoted 2 lines
While working at my project, saw some issues that better to refactor and save a bit of CPU cycles. So, here they are.
Send netfilter patches to the netfilter developer list, not here.
Quoted 1 line
Patches based on net-next tree.
Then why does your subject line say "rhel6"?
2/21/12 11:04 PM, David Miller пишет:
Quoted 7 lines
From: Tony Zelenoff<[email protected]>
Date: Tue, 21 Feb 2012 21:26:28 +0400Quoted 2 lines
While working at my project, saw some issues that better to refactor and save a bit of CPU cycles. So, here they are.
Send netfilter patches to the netfilter developer list, not here.
ok, thanks, looks like i've missed it.
Quoted 4 lines
Quoted 2 lines
Patches based on net-next tree.
Then why does your subject line say "rhel6"?
It's default patch subject, that i've set. So sometimes i did not notice and send it... sorry.