[PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache

STALE5290d

Revision v1 of 2 in this series.

6 messages, 2 authors, 2012-02-21 · open the first message on its own page

[PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache

From: Tony Zelenoff <hidden>
Date: 2012-02-21 17:26:35

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 rhel6 3/3] net/netfilter: refactor nf_ct_deliver_cached_events

From: Tony Zelenoff <hidden>
Date: 2012-02-21 17:26:35

* identation lowered
* some CPU cycles saved at delayed item variable initialization

Signed-off-by: Tony Zelenoff <redacted>
---
 net/netfilter/nf_conntrack_ecache.c |   55 ++++++++++++++++++----------------
 1 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index 9b8e986..577a0e8 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -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();
-- 
1.7.1

[PATCH rhel6 2/3] net/netfilter: refactor notifier registration

From: Tony Zelenoff <hidden>
Date: 2012-02-21 17:26:35

* ret variable initialization removed as useless
* Similar code strings concatenated and functions code
  flow became more plain

Signed-off-by: Tony Zelenoff <redacted>
---
 net/netfilter/nf_conntrack_ecache.c |   26 ++++++++++----------------
 1 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index aa15977..9b8e986 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -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;
 }
-- 
1.7.1

[PATCH rhel6 1/3] net/netfilter: whitespace removed

From: Tony Zelenoff <hidden>
Date: 2012-02-21 17:26:35

Signed-off-by: Tony Zelenoff <redacted>
---
 net/netfilter/nf_conntrack_ecache.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index 14af632..aa15977 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -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:
-- 
1.7.1

Re: [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache

From: David Miller <davem@davemloft.net>
Date: 2012-02-21 19:04:57

From: Tony Zelenoff <redacted>
Date: Tue, 21 Feb 2012 21:26:28 +0400
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.
Patches based on net-next tree.
Then why does your subject line say "rhel6"?

Re: [PATCH rhel6 0/3] net/netfilter: minor refactoring of conntrack ecache

From: Tony Zelenoff <hidden>
Date: 2012-02-21 19:21:24

2/21/12 11:04 PM, David Miller пишет:
From: Tony Zelenoff<redacted>
Date: Tue, 21 Feb 2012 21:26:28 +0400
quoted
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
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help