Skip to contentSkip to conversation

netfilter: make xt_rateest hash table per net

PATCH Applied Cong Wang 3 participants 3 messages Mar 2, 2018 – Mar 5, 2018

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 netfilter: make xt_rateest hash table per net

As suggested by Eric, we need to make the xt_rateest hash table and its lock per netns to reduce lock contentions.

Cc Florian Westphal <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Pablo Neira Ayuso <[email protected]>
---
 include/net/netfilter/xt_rateest.h |  4 +-
 net/netfilter/xt_RATEEST.c         | 91 +++++++++++++++++++++++++++-----------
 net/netfilter/xt_rateest.c         | 10 ++---
 3 files changed, 72 insertions(+), 33 deletions(-)
include/net/netfilter/xt_rateest.h +2 -2
index b1db13772554..832ab69efda5 100644
@@ -21,7 +21,7 @@ struct xt_rateest {
 	struct net_rate_estimator __rcu *rate_est;
 };
 
-struct xt_rateest *xt_rateest_lookup(const char *name);
-void xt_rateest_put(struct xt_rateest *est);
+struct xt_rateest *xt_rateest_lookup(struct net *net, const char *name);
+void xt_rateest_put(struct net *net, struct xt_rateest *est);
 
 #endif /* _XT_RATEEST_H */
net/netfilter/xt_RATEEST.c +65 -26

191 lines not on this page · raw message

net/netfilter/xt_rateest.c +5 -5
index 755d2f6693a2..bf77326861af 100644
@@ -95,13 +95,13 @@ static int xt_rateest_mt_checkentry(const struct xt_mtchk_param *par)
 	}
 
 	ret  = -ENOENT;
-	est1 = xt_rateest_lookup(info->name1);
+	est1 = xt_rateest_lookup(par->net, info->name1);
 	if (!est1)
 		goto err1;
 
 	est2 = NULL;
 	if (info->flags & XT_RATEEST_MATCH_REL) {
-		est2 = xt_rateest_lookup(info->name2);
+		est2 = xt_rateest_lookup(par->net, info->name2);
 		if (!est2)
 			goto err2;
 	}
@@ -111,7 +111,7 @@ static int xt_rateest_mt_checkentry(const struct xt_mtchk_param *par)
 	return 0;
 
 err2:
-	xt_rateest_put(est1);
+	xt_rateest_put(par->net, est1);
 err1:
 	return ret;
 }
@@ -120,9 +120,9 @@ static void xt_rateest_mt_destroy(const struct xt_mtdtor_param *par)
 {
 	struct xt_rateest_match_info *info = par->matchinfo;
 
-	xt_rateest_put(info->est1);
+	xt_rateest_put(par->net, info->est1);
 	if (info->est2)
-		xt_rateest_put(info->est2);
+		xt_rateest_put(par->net, info->est2);
 }
 
 static struct xt_match xt_rateest_mt_reg __read_mostly = {
Signature · 1 line
2.13.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Cong Wang

As suggested by Eric, we need to make the xt_rateest hash table and its lock per netns to reduce lock contentions.

Cc Florian Westphal <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Pablo Neira Ayuso <[email protected]>
Quoted 5 lines
---
 include/net/netfilter/xt_rateest.h |  4 +-
 net/netfilter/xt_RATEEST.c         | 91 +++++++++++++++++++++++++++-----------
 net/netfilter/xt_rateest.c         | 10 ++---
 3 files changed, 72 insertions(+), 33 deletions(-)

Very nice, thanks !

Although the main reason was to avoid name collisions between different netns.

Hash table is small enough that it can be allocated for each netns.

maintainer Applied
#2 lore raw
Quoted 15 lines · Eric Dumazet
Quoted 8 lines · Cong Wang

As suggested by Eric, we need to make the xt_rateest hash table and its lock per netns to reduce lock contentions.

Cc Florian Westphal <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Pablo Neira Ayuso <[email protected]>
Quoted 5 lines
---
 include/net/netfilter/xt_rateest.h |  4 +-
 net/netfilter/xt_RATEEST.c         | 91 +++++++++++++++++++++++++++-----------
 net/netfilter/xt_rateest.c         | 10 ++---
 3 files changed, 72 insertions(+), 33 deletions(-)
Quoted 3 lines

Very nice, thanks !

Applied, thanks!