Re: [PATCH net-next] netfilter: conntrack: Reduce cond_resched frequency in gc_worker

From: Florian Westphal

Date: Tue Oct 14 2025 - 09:06:44 EST


lirongqing <lirongqing@xxxxxxxxx> wrote:
> From: Li RongQing <lirongqing@xxxxxxxxx>
>
> The current implementation calls cond_resched() in every iteration
> of the garbage collection loop. This creates some overhead when
> processing large conntrack tables with billions of entries,
> as each cond_resched() invocation involves scheduler operations.
>
> To reduce this overhead, implement a time-based throttling mechanism
> that calls cond_resched() at most once per millisecond. This maintains
> system responsiveness while minimizing scheduler contention.
>
> gc_worker() with hashsize=10000 shows measurable improvement:
>
> Before: 7114.274us
> After: 5993.518us (15.8% reduction)

I dislike this, I have never seen this pattern.

Whole point of cond_resched() is to let scheduler decide.

Maybe it would be better to move gc_worker off to its own
work queue (create_workqueue()) instead of reusing system wq
so one can tune the priority instead?