From: Daniel Borkmann <dborkman@redhat.com>
To: Cong Wang <cwang@twopensource.com>
Cc: David Miller <davem@davemloft.net>, netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next 3/3] packet: use percpu mmap tx frame pending refcount
Date: Mon, 13 Jan 2014 12:19:01 +0100 [thread overview]
Message-ID: <52D3CBA5.4080301@redhat.com> (raw)
In-Reply-To: <CAHA+R7NnaxXgOGW=jTEGkeMByO7wXVr9bGR-J9rLzwL4ne52bA@mail.gmail.com>
On 01/13/2014 06:51 AM, Cong Wang wrote:
> On Sun, Jan 12, 2014 at 8:22 AM, Daniel Borkmann <dborkman@redhat.com> wrote:
>> +static void packet_inc_pending(struct packet_ring_buffer *rb)
>> +{
>> + this_cpu_inc(*rb->pending_refcnt);
>> +}
>> +
>> +static void packet_dec_pending(struct packet_ring_buffer *rb)
>> +{
>> + this_cpu_dec(*rb->pending_refcnt);
>> +}
>> +
>> +static int packet_read_pending(const struct packet_ring_buffer *rb)
>> +{
>> + int i, refcnt = 0;
>> +
>> + /* We don't use pending refcount in rx_ring. */
>> + if (rb->pending_refcnt == NULL)
>> + return 0;
>> +
>> + for_each_possible_cpu(i)
>> + refcnt += *per_cpu_ptr(rb->pending_refcnt, i);
>> +
>> + return refcnt;
>> +}
>
> How is this supposed to work? Since there is no lock,
> you can't read accurate refcnt. Take a look at lib/percpu_counter.c.
>
> I guess for some reason you don't care the accuracy?
Yep, not per se. Look at how we do net device reference counting.
The reason is that we call packet_read_pending() *only* after we
finished processing all frames in TX_RING and we wait for
completion in case MSG_DONTWAIT is *not set*, when that happens
we're back to 0.
But I think I found a different problem with this idea. It could
happen with net devices as well, but probably less likely as there
might be a better distribution of hold/puts among CPUs. However,
for TX_RING, if we pin the process to a particular CPU, and since
the destructor is invoked through ksoftirqd, we could end up with
a misbalance and if the process runs long enough eventually
overflow for one particular CPU. We could work around that, but I
think it's not worth the effort.
Dave, please drop the 3rd patch of the series, thanks.
> Then at least you need to comment in the code.
>
> Thanks.
>
next prev parent reply other threads:[~2014-01-13 11:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-12 16:22 [PATCH net-next 0/3] pf_packet updates Daniel Borkmann
2014-01-12 16:22 ` [PATCH net-next 1/3] packet: improve socket create/bind latency in some cases Daniel Borkmann
2014-01-12 16:22 ` [PATCH net-next 2/3] packet: don't unconditionally schedule() in case of MSG_DONTWAIT Daniel Borkmann
2014-01-12 16:22 ` [PATCH net-next 3/3] packet: use percpu mmap tx frame pending refcount Daniel Borkmann
2014-01-13 5:51 ` Cong Wang
2014-01-13 9:55 ` David Laight
2014-01-13 11:19 ` Daniel Borkmann [this message]
2014-01-13 11:58 ` David Laight
2014-01-13 12:57 ` Daniel Borkmann
2014-01-15 1:16 ` David Miller
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=52D3CBA5.4080301@redhat.com \
--to=dborkman@redhat.com \
--cc=cwang@twopensource.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.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.