From: Grant Edwards <grant.b.edwards@gmail.com>
To: netdev@vger.kernel.org
Subject: Re: Change in alloc_skb() behavior in 3.2+ kernels?
Date: Wed, 6 Jun 2012 18:59:19 +0000 (UTC) [thread overview]
Message-ID: <jqo9a6$ah6$1@dough.gmane.org> (raw)
In-Reply-To: 1339008142.26966.40.camel@edumazet-glaptop
On 2012-06-06, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> On Wed, 2012-06-06 at 18:32 +0000, Grant Edwards wrote:
>
>> I'm tracking down a problem that appears to be caused by a change in
>> the behavior of alloc_skb() introduced in kernel version 3.2. In
>> kernel versions prior to 3.2, calling alloc_skb(1350), returned an
>> sk_buff with a tailroom of around 1400 bytes (safely below the
>> default Ethernet frame size limit of 1500).
>>
>> In 3.2 and later, calling alloc_skb(1350) returns an sk_buff with a
>> tailroom of about 1850.
>>
>> Why has the "extra" space increased from 60 bytes to 500 bytes?
>
> Because of kmalloc-2048 being used. Previous kernels were losing this
> space. We are now able to expand some packets without extra
> re-allocation/copy.
>
>> [It's always possible that I've unintentionally changed something in
>> the kernel configs that causes this, but I've tried to build the
>> kernels as identically as possible.]
>>
>> The kernel module that's started failing fills the allocated sk_buff
>> until tailroom() indicates it is full and then sends it. The problem
>> is that sending a packet with a length of 1850 won't work (it's a
>> MAC-layer Ethernet packet).
>
> This code seems buggy.
It is with today's alloc_skb().
At the time it was written (probably 10+ years ago) it was relying on
the documented API for alloc_skb() that stated alloc_skb() either
returned an sk_buff of the requested size or it failed.
>> I've found man pages for alloc_skb() from a few years ago that state
>> explicitly that alloc_skb(_size_) will allocate a new sk_buff with no
>> headroom and a tail room of _size_ bytes. This doesn't seem to be the
>> case for recent kernels. Is there any documentation stating what the
>> current behavior is supposed to be?
>>
>> Are callers to alloc_skb() supposed to check the tailroom and
>> reserve() an appropriate number of bytes such that the tailroom is
>> correct?
>
> If you allocate skbs with 1500 bytes, you probably should check skb->len
> more than tailroom...
I can do that -- assuming it's backwards compatible with older kernels
as well (let's say as far back as 2.6 -- we stopped trying to support
2.4 kernels last year).
>> Is the tailroom of the allocated sk_buff guaranteed to be at least as
>> large as the requested size, or does application code also have to
>> check for tailroom less than the requested size?
>>
>> The ultimate question I'm trying to answer is what is the "right" way
>> to allocate an sk_buff that has a size appropriate for an Ethernet
>> frame assuming an MTU of 1500?
>
> I dont know what to answer. Could you point the code in question?
Sure:
alloc_skb(dev->hard_header_len + 1340)
The intent was to allocate a frame that we can guarantee we can send
out via the Ethernet device 'dev'. Sometime 12-14 years ago, somebody
pulled the number "1340" out of the air under the assumption that the
resulting sk_buff would always be safely under the Ethernet limit of
1500 bytes.
That worked until kernel 3.2 came out, at which time we started ending
up with 1800 byte frames.
--
Grant Edwards grant.b.edwards Yow! I've read SEVEN
at MILLION books!!
gmail.com
next prev parent reply other threads:[~2012-06-06 18:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-06 18:32 Change in alloc_skb() behavior in 3.2+ kernels? Grant Edwards
2012-06-06 18:42 ` Eric Dumazet
2012-06-06 18:59 ` Grant Edwards [this message]
2012-06-06 19:02 ` David Miller
2012-06-06 20:22 ` Grant Edwards
2012-06-07 1:23 ` [PATCH net-next] net: Update kernel-doc for __alloc_skb() Ben Hutchings
2012-06-07 20:19 ` David Miller
2012-06-07 13:23 ` Change in alloc_skb() behavior in 3.2+ kernels? Grant Edwards
2012-06-07 14:01 ` Eric Dumazet
2012-06-07 14:16 ` Grant Edwards
2012-06-07 14:25 ` Eric Dumazet
2012-06-06 18:51 ` David Miller
2012-06-06 19:01 ` Grant Edwards
2012-06-06 20:17 ` David Miller
2012-06-06 20:24 ` Grant Edwards
2012-06-06 20:31 ` Eric Dumazet
2012-06-06 20:35 ` Grant Edwards
2012-06-06 19:42 ` Eric Dumazet
2012-06-06 20:26 ` Grant Edwards
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='jqo9a6$ah6$1@dough.gmane.org' \
--to=grant.b.edwards@gmail.com \
--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.