Skip to content
Permalink
Browse files
netfilter: conntrack: configurable conntrack gc scan interval
In Commit 4608fdf ("netfilter: conntrack: collect all entries in one cycle")
conntrack gc was changed to run periodically every 2 minutes.

On systems handling many UDP connections, this leads to bursts of session
termination handling.

As suggested in the original commit, provide the ability to control the gc
interval using a sysctl knob.

Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
  • Loading branch information
ebirger authored and intel-lab-lkp committed Nov 20, 2021
1 parent 3b1abcf commit 2e10f30e82a92d09c72cfcd3e659cd2395bf3e3e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
@@ -207,3 +207,7 @@ nf_flowtable_udp_timeout - INTEGER (seconds)
Control offload timeout for udp connections.
UDP connections may be offloaded from nf conntrack to nf flow table.
Once aged, the connection is returned to nf conntrack with udp pickup timeout.

nf_conntrack_gc_scan_intervaL - INTEGER (seconds)
default 120
minimum 1
@@ -314,6 +314,7 @@ extern struct hlist_nulls_head *nf_conntrack_hash;
extern unsigned int nf_conntrack_htable_size;
extern seqcount_spinlock_t nf_conntrack_generation;
extern unsigned int nf_conntrack_max;
extern unsigned int nf_conntrack_gc_scan_interval;

/* must be called with rcu read lock held */
static inline void
@@ -83,6 +83,8 @@ static DEFINE_MUTEX(nf_conntrack_mutex);
#define MIN_CHAINLEN 8u
#define MAX_CHAINLEN (32u - MIN_CHAINLEN)

__read_mostly unsigned int nf_conntrack_gc_scan_interval = GC_SCAN_INTERVAL;
EXPORT_SYMBOL_GPL(nf_conntrack_gc_scan_interval);
static struct conntrack_gc_work conntrack_gc_work;

void nf_conntrack_lock(spinlock_t *lock) __acquires(lock)
@@ -1422,7 +1424,7 @@ static void gc_worker(struct work_struct *work)
{
unsigned long end_time = jiffies + GC_SCAN_MAX_DURATION;
unsigned int i, hashsz, nf_conntrack_max95 = 0;
unsigned long next_run = GC_SCAN_INTERVAL;
unsigned long next_run = max(nf_conntrack_gc_scan_interval, HZ);
struct conntrack_gc_work *gc_work;
gc_work = container_of(work, struct conntrack_gc_work, dwork.work);

@@ -565,6 +565,7 @@ enum nf_ct_sysctl_index {
#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
NF_SYSCTL_CT_TIMESTAMP,
#endif
NF_SYSCTL_CT_GC_SCAN_INTERVAL,
NF_SYSCTL_CT_PROTO_TIMEOUT_GENERIC,
NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_SYN_SENT,
NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_SYN_RECV,
@@ -707,6 +708,13 @@ static struct ctl_table nf_ct_sysctl_table[] = {
.extra2 = SYSCTL_ONE,
},
#endif
[NF_SYSCTL_CT_GC_SCAN_INTERVAL] = {
.procname = "nf_conntrack_gc_scan_interval",
.data = &nf_conntrack_gc_scan_interval,
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_dointvec_jiffies,
},
[NF_SYSCTL_CT_PROTO_TIMEOUT_GENERIC] = {
.procname = "nf_conntrack_generic_timeout",
.maxlen = sizeof(unsigned int),
@@ -1123,6 +1131,7 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)
table[NF_SYSCTL_CT_MAX].mode = 0444;
table[NF_SYSCTL_CT_EXPECT_MAX].mode = 0444;
table[NF_SYSCTL_CT_BUCKETS].mode = 0444;
table[NF_SYSCTL_CT_GC_SCAN_INTERVAL].mode = 0444;
}

cnet->sysctl_header = register_net_sysctl(net, "net/netfilter", table);

0 comments on commit 2e10f30

Please sign in to comment.