netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <dborkman@redhat.com>
To: Tom Gundersen <teg@jklm.no>
Cc: netdev <netdev@vger.kernel.org>, Kay Sievers <kay@vrfy.org>
Subject: Re: [BUG?] the first bind() of an AF_PACKET socket to an interface is slow
Date: Mon, 31 Mar 2014 22:16:27 +0200	[thread overview]
Message-ID: <5339CD1B.7040708@redhat.com> (raw)
In-Reply-To: <CAG-2HqXW+ULp_K-873+DG3T_4FxcxaSy5aGQ+wf6P9m=015zgQ@mail.gmail.com>

On 03/31/2014 08:43 PM, Tom Gundersen wrote:
> Hi,
>
> I'm observing some strange behavior using bind().
>
> For any given process, and any given interface, the first time I bind
> a socket to the interface it takes a very long time. Subsequent binds
> to the same interface in the same process are instantaneous.
>
> The time it takes seems independent of the interface, so also affects
> the loopback interface, but binding to all interfaces (ifindex=0) is
> instantaneous.
>
> It is also peculiar to note that the time it takes to bind is
> seemingly randomly chosen on my machine from 9ms, 19ms, 29ms, 39ms,
> 49ms and 59 ms, but I never observed any other values.
>
> The attached test program illustrates the problem, binding to
> ifindex=0 (all) and ifindex=1 (loopback).
>
> Sample run:
> # strace -f -T -ebind ./bind
> bind(3, {sa_family=AF_PACKET, proto=0x800, if0, pkttype=0x40 /* ? */,
> addr(6)={1328, ffffffffffff}, 20) = 0 <0.000036>
> bind(3, {sa_family=AF_PACKET, proto=0x800, if0, pkttype=0x40 /* ? */,
> addr(6)={1328, ffffffffffff}, 20) = 0 <0.000033>
> bind(3, {sa_family=AF_PACKET, proto=0x800, if1, pkttype=0x40 /* ? */,
> addr(6)={1328, ffffffffffff}, 20) = 0 <0.059706>
> bind(3, {sa_family=AF_PACKET, proto=0x800, if1, pkttype=0x40 /* ? */,
> addr(6)={1328, ffffffffffff}, 20) = 0 <0.000111>
>
>
> Can anyone enlighten me to what is going on? Is this expected behavior
> or a bug? Any suggestions for a work-around?

Expected behaviour as you can save in some cases a synchronize_net() call:

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=902fefb82ef72a50c78cb4a20cc954b037a98d1c

> Cheers,
>
> Tom
>

  reply	other threads:[~2014-03-31 20:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-31 18:43 [BUG?] the first bind() of an AF_PACKET socket to an interface is slow Tom Gundersen
2014-03-31 20:16 ` Daniel Borkmann [this message]
2014-03-31 21:24   ` Tom Gundersen

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=5339CD1B.7040708@redhat.com \
    --to=dborkman@redhat.com \
    --cc=kay@vrfy.org \
    --cc=netdev@vger.kernel.org \
    --cc=teg@jklm.no \
    /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).