From: Nicolas Dichtel <hidden> Date: 2016-10-10 10:18:58
The first patch is a small documentation fix.
The second patch adds more flexibility to configure the conntrack gc. I target
it specifically to net and not net-next because the removal of the conntrack
timer has just land into net.
Documentation/networking/nf_conntrack-sysctl.txt | 35 +++++++++++------------
include/net/netfilter/nf_conntrack_core.h | 5 ++++
net/netfilter/nf_conntrack_core.c | 17 +++++------
net/netfilter/nf_conntrack_standalone.c | 36 ++++++++++++++++++++++++
4 files changed, 67 insertions(+), 26 deletions(-)
Comments are welcomed,
Regards,
Nicolas
@@ -33,24 +33,6 @@ nf_conntrack_events - BOOLEAN If this option is enabled, the connection tracking code will provide userspace with connection tracking events via ctnetlink.-nf_conntrack_events_retry_timeout - INTEGER (seconds)- default 15-- This option is only relevant when "reliable connection tracking- events" are used. Normally, ctnetlink is "lossy", that is,- events are normally dropped when userspace listeners can't keep up.-- Userspace can request "reliable event mode". When this mode is- active, the conntrack will only be destroyed after the event was- delivered. If event delivery fails, the kernel periodically- re-tries to send the event to userspace.-- This is the maximum interval the kernel should use when re-trying- to deliver the destroy event.-- A higher number means there will be fewer delivery retries and it- will take longer for a backlog to be processed.- nf_conntrack_expect_max - INTEGER Maximum size of expectation table. Default value is nf_conntrack_buckets / 256. Minimum is 1.
From: Nicolas Dichtel <hidden> Date: 2016-10-10 10:18:58
After commit b87a2f9199ea ("netfilter: conntrack: add gc worker to remove
timed-out entries"), netlink conntrack deletion events may be sent with a
huge delay. It could be interesting to let the user tweak gc parameters
depending on its use case.
CC: Florian Westphal <fw@strlen.de>
Signed-off-by: Nicolas Dichtel <redacted>
---
Documentation/networking/nf_conntrack-sysctl.txt | 17 +++++++++++
include/net/netfilter/nf_conntrack_core.h | 5 ++++
net/netfilter/nf_conntrack_core.c | 17 +++++------
net/netfilter/nf_conntrack_standalone.c | 36 ++++++++++++++++++++++++
4 files changed, 67 insertions(+), 8 deletions(-)
@@ -37,6 +37,23 @@ nf_conntrack_expect_max - INTEGER Maximum size of expectation table. Default value is nf_conntrack_buckets / 256. Minimum is 1.+nf_conntrack_gc_interval - INTEGER+ Maximum interval in second between two run of the conntrack gc. This+ gc is in charge of removing stale entries. It also impacts the delay+ before notifying the userland a conntrack deletion.+ This sysctl is only writeable in the initial net namespace.++nf_conntrack_gc_max_buckets - INTEGER+nf_conntrack_gc_max_buckets_div - INTEGER+ During a run, the conntrack gc processes at maximum+ nf_conntrack_buckets/nf_conntrack_gc_max_buckets_div (and never more+ than nf_conntrack_gc_max_buckets) entries.+ These sysctl are only writeable in the initial net namespace.++nf_conntrack_gc_max_evicts - INTEGER+ The maximum number of entries to be evicted during a run of gc.+ This sysctl is only writeable in the initial net namespace.+ nf_conntrack_frag6_high_thresh - INTEGER default 262144
@@ -936,13 +936,14 @@ static noinline int early_drop(struct net *net, unsigned int _hash)staticvoidgc_worker(structwork_struct*work){unsignedinti,goal,buckets=0,expired_count=0;-unsignedlongnext_run=GC_INTERVAL;+unsignedlongnext_run=nf_ct_gc_interval;unsignedintratio,scanned=0;structconntrack_gc_work*gc_work;gc_work=container_of(work,structconntrack_gc_work,dwork.work);-goal=min(nf_conntrack_htable_size/GC_MAX_BUCKETS_DIV,GC_MAX_BUCKETS);+goal=min(nf_conntrack_htable_size/nf_ct_gc_max_buckets_div,+nf_ct_gc_max_buckets);i=gc_work->last_bucket;do{
@@ -445,6 +445,8 @@ static void nf_conntrack_standalone_fini_proc(struct net *net)/* Sysctl support */#ifdef CONFIG_SYSCTL+staticintone=1;+staticintint_max=INT_MAX;/* Log invalid packets of a given protocol */staticintlog_invalid_proto_min__read_mostly;staticintlog_invalid_proto_max__read_mostly=255;
This entry has been removed in commit 9500507c6138.
Fixes: 9500507c6138 ("netfilter: conntrack: remove timer from ecache extension")
Signed-off-by: Nicolas Dichtel <redacted>
After commit b87a2f9199ea ("netfilter: conntrack: add gc worker to remove
timed-out entries"), netlink conntrack deletion events may be sent with a
huge delay. It could be interesting to let the user tweak gc parameters
depending on its use case.
Hmm, care to elaborate?
I am not against doing this but I'd like to hear/read your use case.
The expectation is that in almot all cases eviction will happen from
packet path. The gc worker is jusdt there for case where a busy system
goes idle.
quoted hunk
+nf_conntrack_gc_max_evicts - INTEGER+ The maximum number of entries to be evicted during a run of gc.+ This sysctl is only writeable in the initial net namespace.
Hmmm, do you have any advice on sizing this one?
I think a better change might be (instead of adding htis knob) to
resched the gc worker for immediate re-executaion in case the entire
"budget" was used. What do you think?
From: Nicolas Dichtel <hidden> Date: 2016-10-10 15:24:25
Le 10/10/2016 à 16:04, Florian Westphal a écrit :
Nicolas Dichtel [off-list ref] wrote:
quoted
After commit b87a2f9199ea ("netfilter: conntrack: add gc worker to remove
timed-out entries"), netlink conntrack deletion events may be sent with a
huge delay. It could be interesting to let the user tweak gc parameters
depending on its use case.
Hmm, care to elaborate?
I am not against doing this but I'd like to hear/read your use case.
The expectation is that in almot all cases eviction will happen from
packet path. The gc worker is jusdt there for case where a busy system
goes idle.
It was precisely that case. After a period of activity, the event is sent a long
time after the timeout. If the router does not manage a lot of flows, why not
trying to parse more entries instead of the default 1/64 of the table?
In fact, I don't understand why using GC_MAX_BUCKETS_DIV instead of using always
GC_MAX_BUCKETS whatever the size of the table is.
quoted
+nf_conntrack_gc_max_evicts - INTEGER+ The maximum number of entries to be evicted during a run of gc.+ This sysctl is only writeable in the initial net namespace.
Hmmm, do you have any advice on sizing this one?
In fact, no ;-)
I really hesitate to expose the four values or just a subset. My goal was also
to get feedback. I can remove this one.
I think a better change might be (instead of adding htis knob) to
resched the gc worker for immediate re-executaion in case the entire
"budget" was used. What do you think?
Even if it's not directly related to my problem, I think it's a good idea.
After commit b87a2f9199ea ("netfilter: conntrack: add gc worker to remove
timed-out entries"), netlink conntrack deletion events may be sent with a
huge delay. It could be interesting to let the user tweak gc parameters
depending on its use case.
Hmm, care to elaborate?
I am not against doing this but I'd like to hear/read your use case.
The expectation is that in almot all cases eviction will happen from
packet path. The gc worker is jusdt there for case where a busy system
goes idle.
It was precisely that case. After a period of activity, the event is sent a long
time after the timeout. If the router does not manage a lot of flows, why not
trying to parse more entries instead of the default 1/64 of the table?
In fact, I don't understand why using GC_MAX_BUCKETS_DIV instead of using always
GC_MAX_BUCKETS whatever the size of the table is.
I wanted to make sure that we have a known upper bound on the number of
buckets we process so that we do not block other pending kworker items
for too long.
(Or cause too many useless scans)
Another idea worth trying might be to get rid of the max cap and
instead break early in case too many jiffies expired.
I don't want to add sysctl knobs for this unless absolutely needed; its already
possible to 'force' eviction cycle by running 'conntrack -L'.
From: Nicolas Dichtel <hidden> Date: 2016-10-14 10:12:29
Le 13/10/2016 à 22:43, Florian Westphal a écrit :
Nicolas Dichtel [off-list ref] wrote:
quoted
Le 10/10/2016 à 16:04, Florian Westphal a écrit :
quoted
Nicolas Dichtel [off-list ref] wrote:
quoted
After commit b87a2f9199ea ("netfilter: conntrack: add gc worker to remove
timed-out entries"), netlink conntrack deletion events may be sent with a
huge delay. It could be interesting to let the user tweak gc parameters
depending on its use case.
Hmm, care to elaborate?
I am not against doing this but I'd like to hear/read your use case.
The expectation is that in almot all cases eviction will happen from
packet path. The gc worker is jusdt there for case where a busy system
goes idle.
It was precisely that case. After a period of activity, the event is sent a long
time after the timeout. If the router does not manage a lot of flows, why not
trying to parse more entries instead of the default 1/64 of the table?
In fact, I don't understand why using GC_MAX_BUCKETS_DIV instead of using always
GC_MAX_BUCKETS whatever the size of the table is.
I wanted to make sure that we have a known upper bound on the number of
buckets we process so that we do not block other pending kworker items
for too long.
I don't understand. GC_MAX_BUCKETS is the upper bound and I agree that it is
needed. But why GC_MAX_BUCKETS_DIV (ie 1/64)?
In other words, why this line:
goal = min(nf_conntrack_htable_size / GC_MAX_BUCKETS_DIV, GC_MAX_BUCKETS);
instead of:
goal = GC_MAX_BUCKETS;
?
(Or cause too many useless scans)
Another idea worth trying might be to get rid of the max cap and
instead break early in case too many jiffies expired.
I don't want to add sysctl knobs for this unless absolutely needed; its already
possible to 'force' eviction cycle by running 'conntrack -L'.
Sure, but this is not a "real" solution, just a workaround.
We need to find a way to deliver conntrack deletion events in a reasonable
delay, whatever the traffic on the machine is.
After commit b87a2f9199ea ("netfilter: conntrack: add gc worker to remove
timed-out entries"), netlink conntrack deletion events may be sent with a
huge delay. It could be interesting to let the user tweak gc parameters
depending on its use case.
Hmm, care to elaborate?
I am not against doing this but I'd like to hear/read your use case.
The expectation is that in almot all cases eviction will happen from
packet path. The gc worker is jusdt there for case where a busy system
goes idle.
It was precisely that case. After a period of activity, the event is sent a long
time after the timeout. If the router does not manage a lot of flows, why not
trying to parse more entries instead of the default 1/64 of the table?
In fact, I don't understand why using GC_MAX_BUCKETS_DIV instead of using always
GC_MAX_BUCKETS whatever the size of the table is.
I wanted to make sure that we have a known upper bound on the number of
buckets we process so that we do not block other pending kworker items
for too long.
I don't understand. GC_MAX_BUCKETS is the upper bound and I agree that it is
needed. But why GC_MAX_BUCKETS_DIV (ie 1/64)?
In other words, why this line:
goal = min(nf_conntrack_htable_size / GC_MAX_BUCKETS_DIV, GC_MAX_BUCKETS);
instead of:
goal = GC_MAX_BUCKETS;
Sure, we can do that. But why is a fixed size better than a fraction?
E.g. with 8k buckets and simple goal = GC_MAX_BUCKETS we scan entire
table on every run, currently we only scan 128.
I wanted to keep too many destroy notifications from firing at once
but maybe i was too paranoid...
quoted
(Or cause too many useless scans)
Another idea worth trying might be to get rid of the max cap and
instead break early in case too many jiffies expired.
I don't want to add sysctl knobs for this unless absolutely needed; its already
possible to 'force' eviction cycle by running 'conntrack -L'.
Sure, but this is not a "real" solution, just a workaround.
We need to find a way to deliver conntrack deletion events in a reasonable
delay, whatever the traffic on the machine is.
Agree, but that depends on what 'reasonable' means and what kind of
uneeded cpu churn we're willing to add.
We can add a sysctl for this but we should use a low default to not do
too much unneeded work.
So what about your original patch, but only add
nf_conntrack_gc_interval
(and also add instant-resched in case entire budget was consumed)?
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2016-10-14 10:53:34
On Fri, Oct 14, 2016 at 12:37:26PM +0200, Florian Westphal wrote:
Nicolas Dichtel [off-list ref] wrote:
quoted
Le 13/10/2016 à 22:43, Florian Westphal a écrit :
[...]
quoted
quoted
(Or cause too many useless scans)
Another idea worth trying might be to get rid of the max cap and
instead break early in case too many jiffies expired.
I don't want to add sysctl knobs for this unless absolutely needed; its already
possible to 'force' eviction cycle by running 'conntrack -L'.
Sure, but this is not a "real" solution, just a workaround.
We need to find a way to deliver conntrack deletion events in a reasonable
delay, whatever the traffic on the machine is.
Agree, but that depends on what 'reasonable' means and what kind of
uneeded cpu churn we're willing to add.
We can add a sysctl for this but we should use a low default to not do
too much unneeded work.
So what about your original patch, but only add
nf_conntrack_gc_interval
(and also add instant-resched in case entire budget was consumed)?
I would prefer not to expose sysctl knobs, if we don't really know
what good default values are good, then we cannot expect our users to
know this for us.
I would go tune this in a way that this resembles to the previous
behaviour.
I would prefer not to expose sysctl knobs, if we don't really know
what good default values are good, then we cannot expect our users to
know this for us.
I would go tune this in a way that this resembles to the previous
behaviour.
I do not see how this is possible without reverting to old per-conntrack
timer scheme.
With per-ct timer userspace gets notified the moment the timer
fires, without it notification comes 'when kernel detects the timeout'
which in worst case, as Nicholas describes, is when gc worker comes
along.
You can run the gc worker every jiffie of course, but thats just
wasting cpu cycles (and you still get a small delay).
I don't see a way to do run-time tuning except faster restarts when
old entries start accumulating. This is what the code tries to do,
perhaps you have a better idea for the 'next gc run' computation.
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2016-10-17 15:39:07
On Mon, Oct 10, 2016 at 03:57:37PM +0200, Florian Westphal wrote:
Nicolas Dichtel [off-list ref] wrote:
quoted
This entry has been removed in commit 9500507c6138.
Fixes: 9500507c6138 ("netfilter: conntrack: remove timer from ecache extension")
Signed-off-by: Nicolas Dichtel <redacted>
From: Nicolas Dichtel <hidden> Date: 2016-10-18 08:30:55
After commit b87a2f9199ea ("netfilter: conntrack: add gc worker to remove
timed-out entries"), netlink conntrack deletion events may be sent with a
huge delay (5 minutes).
There is two ways to evict conntrack:
- during a conntrack lookup;
- during a conntrack dump.
Let's do a full scan of conntrack entries after a period of inactivity
(no conntrack lookup).
CC: Florian Westphal <fw@strlen.de>
Signed-off-by: Nicolas Dichtel <redacted>
---
Here is another proposal to try to fix the problem.
Comments are welcomed,
Nicolas
net/netfilter/nf_conntrack_core.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
After commit b87a2f9199ea ("netfilter: conntrack: add gc worker to remove
timed-out entries"), netlink conntrack deletion events may be sent with a
huge delay (5 minutes).
There is two ways to evict conntrack:
- during a conntrack lookup;
- during a conntrack dump.
Let's do a full scan of conntrack entries after a period of inactivity
(no conntrack lookup).
CC: Florian Westphal <fw@strlen.de>
Signed-off-by: Nicolas Dichtel <redacted>
---
Here is another proposal to try to fix the problem.
Comments are welcomed,
Nicolas
Hmm, I don't think its good idea in practice.
If goal is to avoid starving arbitrary 'dead' ct for too long,
then simple ping will defeat the logic here, because...
... we do periodic lookup (but always in same slot), so no full scan is
triggered.
If you think its useful, consider sending patch that rescheds worker
instantly in case budget expired, otherwise I will do this later this
week.
[ I am aware doing instant restart might be too late, but at least we
would then reap more entries once we stumble upon large number of
expired ones ].
From: Nicolas Dichtel <hidden> Date: 2016-10-18 10:06:23
Le 18/10/2016 à 10:47, Florian Westphal a écrit :
Nicolas Dichtel [off-list ref] wrote:
quoted
After commit b87a2f9199ea ("netfilter: conntrack: add gc worker to remove
timed-out entries"), netlink conntrack deletion events may be sent with a
huge delay (5 minutes).
There is two ways to evict conntrack:
- during a conntrack lookup;
- during a conntrack dump.
Let's do a full scan of conntrack entries after a period of inactivity
(no conntrack lookup).
CC: Florian Westphal <fw@strlen.de>
Signed-off-by: Nicolas Dichtel <redacted>
---
Here is another proposal to try to fix the problem.
Comments are welcomed,
Nicolas
Hmm, I don't think its good idea in practice.
If goal is to avoid starving arbitrary 'dead' ct for too long,
then simple ping will defeat the logic here, because...
... we do periodic lookup (but always in same slot), so no full scan is
triggered.
Yes, I was wondering about that. My first idea was to have that bool per bucket
and force a scan of the bucket instead of the whole table.
If you think its useful, consider sending patch that rescheds worker
instantly in case budget expired, otherwise I will do this later this
week.
Ok, I will send it, but it does not address the "inactivity" problem.
[ I am aware doing instant restart might be too late, but at least we
would then reap more entries once we stumble upon large number of
expired ones ].
From: Nicolas Dichtel <hidden> Date: 2016-10-18 12:37:32
When the maximum evictions number is reached, do not wait 5 seconds before
the next run.
CC: Florian Westphal <fw@strlen.de>
Signed-off-by: Nicolas Dichtel <redacted>
---
net/netfilter/nf_conntrack_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Nicolas Dichtel <hidden> Date: 2016-10-20 08:50:28
Le 18/10/2016 à 12:06, Nicolas Dichtel a écrit :
Le 18/10/2016 à 10:47, Florian Westphal a écrit :
quoted
Nicolas Dichtel [off-list ref] wrote:
quoted
After commit b87a2f9199ea ("netfilter: conntrack: add gc worker to remove
timed-out entries"), netlink conntrack deletion events may be sent with a
huge delay (5 minutes).
There is two ways to evict conntrack:
- during a conntrack lookup;
- during a conntrack dump.
Let's do a full scan of conntrack entries after a period of inactivity
(no conntrack lookup).
CC: Florian Westphal <fw@strlen.de>
Signed-off-by: Nicolas Dichtel <redacted>
---
Here is another proposal to try to fix the problem.
Comments are welcomed,
Nicolas
Hmm, I don't think its good idea in practice.
If goal is to avoid starving arbitrary 'dead' ct for too long,
then simple ping will defeat the logic here, because...