public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] netfilter: conntrack: remove __read_mostly from nf_conntrack_generation
@ 2026-01-30  4:43 lirongqing
  2026-01-30 10:32 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: lirongqing @ 2026-01-30  4:43 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	Phil Sutter, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, netfilter-devel, coreteam, netdev
  Cc: Li RongQing

From: Li RongQing <lirongqing@baidu.com>

The nf_conntrack_generation sequence counter is updated whenever
conntrack table generations are bumped (e.g., during netns exit or
heavy garbage collection). Under certain workloads, these updates
can be frequent enough that the variable no longer fits the
"read-mostly" criteria.

Applying __read_mostly to a variable that is updated regularly can
lead to cache line bouncing and performance degradation for other
variables residing in the same section. Remove the annotation to
let the variable reside in the standard data section.

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 net/netfilter/nf_conntrack_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index d1f8eb7..233a281 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -204,7 +204,7 @@ EXPORT_SYMBOL_GPL(nf_conntrack_htable_size);
 
 unsigned int nf_conntrack_max __read_mostly;
 EXPORT_SYMBOL_GPL(nf_conntrack_max);
-seqcount_spinlock_t nf_conntrack_generation __read_mostly;
+seqcount_spinlock_t nf_conntrack_generation;
 static siphash_aligned_key_t nf_conntrack_hash_rnd;
 
 static u32 hash_conntrack_raw(const struct nf_conntrack_tuple *tuple,
-- 
2.9.4


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

* Re: [PATCH] netfilter: conntrack: remove __read_mostly from nf_conntrack_generation
  2026-01-30  4:43 [PATCH] netfilter: conntrack: remove __read_mostly from nf_conntrack_generation lirongqing
@ 2026-01-30 10:32 ` Eric Dumazet
  2026-01-30 11:23   ` 答复: [外部邮件] " Li,Rongqing
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2026-01-30 10:32 UTC (permalink / raw)
  To: lirongqing
  Cc: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	Phil Sutter, David S . Miller, Jakub Kicinski, Paolo Abeni,
	Simon Horman, netfilter-devel, coreteam, netdev

On Fri, Jan 30, 2026 at 6:02 AM lirongqing <lirongqing@baidu.com> wrote:
>
> From: Li RongQing <lirongqing@baidu.com>
>
> The nf_conntrack_generation sequence counter is updated whenever
> conntrack table generations are bumped (e.g., during netns exit or
> heavy garbage collection). Under certain workloads, these updates
> can be frequent enough that the variable no longer fits the
> "read-mostly" criteria.
>
> Applying __read_mostly to a variable that is updated regularly can
> lead to cache line bouncing and performance degradation for other
> variables residing in the same section. Remove the annotation to
> let the variable reside in the standard data section.
>


> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
>  net/netfilter/nf_conntrack_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
> index d1f8eb7..233a281 100644
> --- a/net/netfilter/nf_conntrack_core.c
> +++ b/net/netfilter/nf_conntrack_core.c
> @@ -204,7 +204,7 @@ EXPORT_SYMBOL_GPL(nf_conntrack_htable_size);
>
>  unsigned int nf_conntrack_max __read_mostly;
>  EXPORT_SYMBOL_GPL(nf_conntrack_max);
> -seqcount_spinlock_t nf_conntrack_generation __read_mostly;
> +seqcount_spinlock_t nf_conntrack_generation;
>  static siphash_aligned_key_t nf_conntrack_hash_rnd;
>

What about nf_conntrack_hash_rnd ?

I _think_ this needs to be __read_mostly, regardless of its current
location (it might by accident share a mostly read cache line),
especially if your patch puts nf_conntrack_generation in the same
cache line than nf_conntrack_hash_rnd.

Same remark for nf_ct_expect_hashrnd

diff --git a/net/netfilter/nf_conntrack_core.c
b/net/netfilter/nf_conntrack_core.c
index d1f8eb725d4223e042b02ab86ba89b9b7caf75f5..0a705fab2bb73f7590647ff06d7066395e6eea66
100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -204,8 +204,8 @@ EXPORT_SYMBOL_GPL(nf_conntrack_htable_size);

 unsigned int nf_conntrack_max __read_mostly;
 EXPORT_SYMBOL_GPL(nf_conntrack_max);
-seqcount_spinlock_t nf_conntrack_generation __read_mostly;
-static siphash_aligned_key_t nf_conntrack_hash_rnd;
+seqcount_spinlock_t nf_conntrack_generation;
+static siphash_aligned_key_t nf_conntrack_hash_rnd __read_mostly;

 static u32 hash_conntrack_raw(const struct nf_conntrack_tuple *tuple,
                              unsigned int zoneid,
diff --git a/net/netfilter/nf_conntrack_expect.c
b/net/netfilter/nf_conntrack_expect.c
index cfc2daa3fc7f340937898b4bef0769fd31f801b5..4dae405527febf913af43c49ddb2961a8f05e0e4
100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -41,7 +41,7 @@ EXPORT_SYMBOL_GPL(nf_ct_expect_hash);
 unsigned int nf_ct_expect_max __read_mostly;

 static struct kmem_cache *nf_ct_expect_cachep __read_mostly;
-static siphash_aligned_key_t nf_ct_expect_hashrnd;
+static siphash_aligned_key_t nf_ct_expect_hashrnd __read_mostly;

 /* nf_conntrack_expect helper functions */
 void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,

Thanks.

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

* 答复: [外部邮件] Re: [PATCH] netfilter: conntrack: remove __read_mostly from nf_conntrack_generation
  2026-01-30 10:32 ` Eric Dumazet
@ 2026-01-30 11:23   ` Li,Rongqing
  0 siblings, 0 replies; 3+ messages in thread
From: Li,Rongqing @ 2026-01-30 11:23 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	Phil Sutter, David S . Miller, Jakub Kicinski, Paolo Abeni,
	Simon Horman, netfilter-devel@vger.kernel.org,
	coreteam@netfilter.org, netdev@vger.kernel.org

> What about nf_conntrack_hash_rnd ?
> 
> I _think_ this needs to be __read_mostly, regardless of its current location (it
> might by accident share a mostly read cache line), especially if your patch puts
> nf_conntrack_generation in the same cache line than nf_conntrack_hash_rnd.
> 
> Same remark for nf_ct_expect_hashrnd
> 

You are right, nf_conntrack_hash_rnd and nf_ct_expect_hashrnd should be marked as __read_mostly

Thanks

-Li

> diff --git a/net/netfilter/nf_conntrack_core.c
> b/net/netfilter/nf_conntrack_core.c
> index
> d1f8eb725d4223e042b02ab86ba89b9b7caf75f5..0a705fab2bb73f7590647ff06d
> 7066395e6eea66
> 100644
> --- a/net/netfilter/nf_conntrack_core.c
> +++ b/net/netfilter/nf_conntrack_core.c
> @@ -204,8 +204,8 @@ EXPORT_SYMBOL_GPL(nf_conntrack_htable_size);
> 
>  unsigned int nf_conntrack_max __read_mostly;
> EXPORT_SYMBOL_GPL(nf_conntrack_max);
> -seqcount_spinlock_t nf_conntrack_generation __read_mostly; -static
> siphash_aligned_key_t nf_conntrack_hash_rnd;
> +seqcount_spinlock_t nf_conntrack_generation; static
> +siphash_aligned_key_t nf_conntrack_hash_rnd __read_mostly;
> 
>  static u32 hash_conntrack_raw(const struct nf_conntrack_tuple *tuple,
>                               unsigned int zoneid, diff --git
> a/net/netfilter/nf_conntrack_expect.c
> b/net/netfilter/nf_conntrack_expect.c
> index
> cfc2daa3fc7f340937898b4bef0769fd31f801b5..4dae405527febf913af43c49ddb
> 2961a8f05e0e4
> 100644
> --- a/net/netfilter/nf_conntrack_expect.c
> +++ b/net/netfilter/nf_conntrack_expect.c
> @@ -41,7 +41,7 @@ EXPORT_SYMBOL_GPL(nf_ct_expect_hash);
>  unsigned int nf_ct_expect_max __read_mostly;
> 
>  static struct kmem_cache *nf_ct_expect_cachep __read_mostly; -static
> siphash_aligned_key_t nf_ct_expect_hashrnd;
> +static siphash_aligned_key_t nf_ct_expect_hashrnd __read_mostly;
> 
>  /* nf_conntrack_expect helper functions */  void
> nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
> 
> Thanks.


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

end of thread, other threads:[~2026-01-30 11:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-30  4:43 [PATCH] netfilter: conntrack: remove __read_mostly from nf_conntrack_generation lirongqing
2026-01-30 10:32 ` Eric Dumazet
2026-01-30 11:23   ` 答复: [外部邮件] " Li,Rongqing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox