netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][v2] netfilter: ensure that CONNTRACK_LOCKS is power of 2
@ 2019-02-26  9:20 Li RongQing
  2019-03-01 13:36 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Li RongQing @ 2019-02-26  9:20 UTC (permalink / raw)
  To: netfilter-devel, fw

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@strlen.de>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH][v2] netfilter: ensure that CONNTRACK_LOCKS is power of 2
  2019-02-26  9:20 [PATCH][v2] netfilter: ensure that CONNTRACK_LOCKS is power of 2 Li RongQing
@ 2019-03-01 13:36 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2019-03-01 13:36 UTC (permalink / raw)
  To: Li RongQing; +Cc: netfilter-devel, fw

On Tue, Feb 26, 2019 at 05:20:52PM +0800, Li RongQing wrote:
> 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

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-03-01 13:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-26  9:20 [PATCH][v2] netfilter: ensure that CONNTRACK_LOCKS is power of 2 Li RongQing
2019-03-01 13:36 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).