From: Patrick McHardy <kaber@trash.net>
To: Martin Josefsson <gandalf@wlug.westbo.se>
Cc: netfilter-devel <netfilter-devel@lists.netfilter.org>
Subject: Re: [PATCH 11/11] Reduce timer updates in __nf_ct_refresh_acct()
Date: Fri, 03 Nov 2006 13:39:03 +0100 [thread overview]
Message-ID: <454B3867.5070004@trash.net> (raw)
In-Reply-To: <20061101210914.886519886@wlug.westbo.se>
Martin Josefsson wrote:
> Only update the conntrack timer if there's been at least HZ jiffies since the
> last update. Reduces the number of del_timer/add_timer cycles from one per
> packet to one per connection per second (plus once for each state change of a
> connection)
> Should handle timer wraparounds and connection timeout changes.
>
> Signed-off-by: Martin Josefsson <gandalf@wlug.westbo.se>
>
> ---
> net/netfilter/nf_conntrack_core.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> Index: linux-2.6.19-rc3-git4.quilt/net/netfilter/nf_conntrack_core.c
> ===================================================================
> --- linux-2.6.19-rc3-git4.quilt.orig/net/netfilter/nf_conntrack_core.c 2006-11-01 21:40:13.000000000 +0100
> +++ linux-2.6.19-rc3-git4.quilt/net/netfilter/nf_conntrack_core.c 2006-11-01 21:40:21.000000000 +0100
> @@ -865,9 +865,14 @@ void __nf_ct_refresh_acct(struct nf_conn
> ct->timeout.expires = extra_jiffies;
> event = IPCT_REFRESH;
> } else {
> - /* Need del_timer for race avoidance (may already be dying). */
> - if (del_timer(&ct->timeout)) {
> - ct->timeout.expires = jiffies + extra_jiffies;
> + unsigned long newtime = jiffies + extra_jiffies;
> +
> + /* Only update the timeout if the new timeout is at least
> + HZ jiffies from the old timeout. Need del_timer for race
> + avoidance (may already be dying). */
> + if (newtime - ct->timeout.expires >= HZ
> + && del_timer(&ct->timeout)) {
> + ct->timeout.expires = newtime;
> add_timer(&ct->timeout);
> event = IPCT_REFRESH;
> }
Applied, thanks. BTW, the "race avoidance" strikes me as racy,
there are multiple locations where we simply do
if (del_timer(...))
ct->timeout.function(...)
and expect the conntrack to be either destroyed by the
ct->timeout.function call or by the expiring timer.
But without taking ip_conntrack_lock we could have:
CPU1 (refresh) CPU2
if (del_timer) [success]
if (del_timer) [no success]
add_timer()
which means the conntrack won't be destroyed. Did I miss
something?
next prev parent reply other threads:[~2006-11-03 12:39 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-01 21:08 [PATCH 00/11] Minor Cleanups Martin Josefsson
2006-11-01 21:08 ` [PATCH 01/11] Split out expectation handling Martin Josefsson
2006-11-03 11:49 ` Patrick McHardy
2006-11-01 21:08 ` [PATCH 02/11] Split out helper handling Martin Josefsson
2006-11-03 11:50 ` Patrick McHardy
2006-11-01 21:08 ` [PATCH 03/11] Split out the event cache Martin Josefsson
2006-11-03 11:52 ` Patrick McHardy
2006-11-03 11:57 ` Patrick McHardy
2006-11-03 12:03 ` Martin Josefsson
2006-11-03 12:47 ` Yasuyuki KOZAKAI
[not found] ` <200611031247.kA3CleEl011459@toshiba.co.jp>
2006-11-03 12:51 ` Patrick McHardy
2006-11-03 12:57 ` Yasuyuki KOZAKAI
2006-11-03 13:31 ` Martin Josefsson
2006-11-03 13:45 ` Patrick McHardy
2006-11-01 21:08 ` [PATCH 04/11] Split out protocol handling Martin Josefsson
2006-11-03 11:59 ` Patrick McHardy
2006-11-01 21:08 ` [PATCH 05/11] More __read_mostly Martin Josefsson
2006-11-03 12:04 ` Patrick McHardy
2006-11-03 12:05 ` Martin Josefsson
2006-11-03 12:13 ` Patrick McHardy
2006-11-03 12:16 ` Martin Josefsson
2006-11-01 21:08 ` [PATCH 06/11] Rename struct nf_conntrack_protocol Martin Josefsson
2006-11-03 12:07 ` Patrick McHardy
2006-11-03 12:10 ` Martin Josefsson
2006-11-03 12:11 ` Jozsef Kadlecsik
2006-11-03 12:39 ` Patrick McHardy
2006-11-03 12:51 ` Yasuyuki KOZAKAI
[not found] ` <200611031251.kA3Cpao9010791@toshiba.co.jp>
2006-11-03 13:53 ` Patrick McHardy
2006-11-01 21:08 ` [PATCH 07/11] More sanity checks in protocol registration/unregistration Martin Josefsson
2006-11-03 12:21 ` Patrick McHardy
2006-11-01 21:08 ` [PATCH 08/11] Remove ASSERT_{READ,WRITE}_LOCK Martin Josefsson
2006-11-03 12:25 ` Patrick McHardy
2006-11-03 12:32 ` Martin Josefsson
2006-11-03 12:42 ` Patrick McHardy
2006-11-01 21:08 ` [PATCH 09/11] Minor __nf_ct_refresh_acct() whitespace cleanup Martin Josefsson
2006-11-01 21:08 ` [PATCH 10/11] Remove unused struct list_head from protocols Martin Josefsson
2006-11-03 12:27 ` Patrick McHardy
2006-11-01 21:08 ` [PATCH 11/11] Reduce timer updates in __nf_ct_refresh_acct() Martin Josefsson
2006-11-03 12:39 ` Patrick McHardy [this message]
2006-11-03 13:27 ` Martin Josefsson
2006-11-03 13:40 ` Patrick McHardy
2006-11-03 13:48 ` Martin Josefsson
2006-11-03 13:54 ` Patrick McHardy
2006-11-03 14:02 ` Martin Josefsson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=454B3867.5070004@trash.net \
--to=kaber@trash.net \
--cc=gandalf@wlug.westbo.se \
--cc=netfilter-devel@lists.netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.