[PATCH][v2] netfilter: ensure that CONNTRACK_LOCKS is power of 2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



CONNTRACK_LOCKS is divisor when computer array index,
if it is power of 2, compiler will optimize modulo
operation as bitwise AND, or else modulo will lower
performance

Suggested-by: Florian Westphal <fw@xxxxxxxxx>
Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx>
---
v1-->v2: do not replace modulo operation with AND, only ensure that CONNTRACK_LOCKS is power of 2

 net/netfilter/nf_conntrack_core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index e139c256e269..f708c376f225 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -2482,6 +2482,7 @@ int nf_conntrack_init_net(struct net *net)
 	int cpu;
 
 	BUILD_BUG_ON(IP_CT_UNTRACKED == IP_CT_NUMBER);
+	BUILD_BUG_ON_NOT_POWER_OF_2(CONNTRACK_LOCKS);
 	atomic_set(&net->ct.count, 0);
 
 	net->ct.pcpu_lists = alloc_percpu(struct ct_pcpu);
-- 
2.16.2




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux