From: Eric Dumazet <dada1@cosmosbay.com>
To: Stephen Hemminger <shemminger@vyatta.com>
Cc: David Miller <davem@davemloft.net>,
Patrick McHardy <kaber@trash.net>,
netdev@vger.kernel.org, netfilter-devel@vger.kernel.org
Subject: Re: [RFT 3/4] netfilter: use sequence number synchronization for counters
Date: Wed, 28 Jan 2009 07:17:04 +0100 [thread overview]
Message-ID: <497FF860.9080406@cosmosbay.com> (raw)
In-Reply-To: <20090127235508.952787501@vyatta.com>
Stephen Hemminger a écrit :
> Change how synchronization is done on the iptables counters. Use seqcount
> wrapper instead of depending on reader/writer lock.
>
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
>
>
>
> --- a/net/ipv4/netfilter/ip_tables.c 2009-01-27 14:48:41.567879095 -0800
> +++ b/net/ipv4/netfilter/ip_tables.c 2009-01-27 15:45:05.766673246 -0800
> @@ -366,7 +366,9 @@ ipt_do_table(struct sk_buff *skb,
> if (IPT_MATCH_ITERATE(e, do_match, skb, &mtpar) != 0)
> goto no_match;
>
> + write_seqcount_begin(&e->seq);
> ADD_COUNTER(e->counters, ntohs(ip->tot_len), 1);
> + write_seqcount_end(&e->seq);
>
Its not very good to do it like this, (one seqcount_t per rule per cpu)
>
> t = ipt_get_target(e);
> IP_NF_ASSERT(t->u.kernel.target);
> @@ -758,6 +760,7 @@ check_entry_size_and_hooks(struct ipt_en
> < 0 (not IPT_RETURN). --RR */
>
> /* Clear counters and comefrom */
> + seqcount_init(&e->seq);
> e->counters = ((struct xt_counters) { 0, 0 });
> e->comefrom = 0;
>
> @@ -915,14 +918,17 @@ get_counters(const struct xt_table_info
> &i);
>
> for_each_possible_cpu(cpu) {
> + struct ipt_entry *e = t->entries[cpu];
> + unsigned int start;
> +
> if (cpu == curcpu)
> continue;
> i = 0;
> - IPT_ENTRY_ITERATE(t->entries[cpu],
> - t->size,
> - add_entry_to_counter,
> - counters,
> - &i);
> + do {
> + start = read_seqcount_begin(&e->seq);
> + IPT_ENTRY_ITERATE(e, t->size,
> + add_entry_to_counter, counters, &i);
> + } while (read_seqcount_retry(&e->seq, start));
>
This will never complete on a loaded machine and a big set of rules.
When we reach the end of IPT_ENTRY_ITERATE, we notice many packets came
while doing the iteration and restart,
with wrong accumulated values (no rollback of what was done to accumulator)
You want to do the seqcount_begin/end in the leaf function
(add_entry_to_counter()), and make accumulate a value pair (bytes/counter)
only once you are sure they are correct.
Using one seqcount_t per rule (struct ipt_entry) is very expensive.
(This is 4 bytes per rule X num_possible_cpus())
You need one seqcount_t per cpu
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2009-01-28 6:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-27 23:53 [RFT 0/4] Iptables rwlock elimination Stephen Hemminger
2009-01-27 23:53 ` [RFT 1/4] netfilter: change elements in x_tables Stephen Hemminger
2009-01-27 23:53 ` [RFT 2/4] netfilter: remove unneeded initializations Stephen Hemminger
2009-01-28 0:10 ` Alexey Dobriyan
2009-01-27 23:53 ` [RFT 3/4] netfilter: use sequence number synchronization for counters Stephen Hemminger
2009-01-28 6:17 ` Eric Dumazet [this message]
2009-01-28 6:28 ` Stephen Hemminger
2009-01-28 6:35 ` Eric Dumazet
2009-01-28 16:15 ` Patrick McHardy
2009-01-27 23:53 ` [RFT 4/4] netfilter: convert x_tables to use RCU Stephen Hemminger
2009-01-28 7:37 ` Paul E. McKenney
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=497FF860.9080406@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=davem@davemloft.net \
--cc=kaber@trash.net \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=shemminger@vyatta.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).