Skip to contentSkip to conversation

reasons for dev_alloc_skb +16?

DISCUSSION Jeff Garzik 3 participants 5 messages Jul 9, 2003 – Jul 10, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

I knew this at one time, but have forgotten it :)

What is the reason for adding 16 to the dev_alloc_skb length? (and skb_reserve of the same length)

Jeff

#1 lore raw
Quoted 4 lines · On Wed, 9 Jul 2003 11:25:53 -0400 Jeff Garzik <[email protected]> wrote:

I knew this at one time, but have forgotten it :)

What is the reason for adding 16 to the dev_alloc_skb length? (and skb_reserve of the same length)

For the skb_reserve alignment to align the IP header.

But it's not clear it is still a good idea because it leads to cache line misalignment of the beginning of the packet, forcing the card to do a costly Read-Modify-Write cycle.

-Andi

#2 lore raw
Quoted 5 lines · Andi Kleen
Quoted 2 lines · On Wed, 9 Jul 2003 11:25:53 -0400 Jeff Garzik <[email protected]> wrote:

I knew this at one time, but have forgotten it :)

Quoted 8 lines
Quoted 2 lines

What is the reason for adding 16 to the dev_alloc_skb length? (and skb_reserve of the same length)

For the skb_reserve alignment to align the IP header.

But it's not clear it is still a good idea because it leads to cache line misalignment of the beginning of the packet, forcing the card to do a costly Read-Modify-Write cycle.

Exactly. Ben H is running into this, and pondering direct use of alloc_skb for precisely this reason.

Jeff

#3 lore raw
Quoted 9 lines · On Wed, 9 Jul 2003 12:06:57 -0400 Jeff Garzik <[email protected]> wrote:
Quoted 8 lines · Andi Kleen
Quoted 4 lines · On Wed, 9 Jul 2003 11:25:53 -0400 Jeff Garzik <[email protected]> wrote:

I knew this at one time, but have forgotten it :)

What is the reason for adding 16 to the dev_alloc_skb length? (and skb_reserve of the same length)

Quoted 8 lines
Quoted 5 lines

For the skb_reserve alignment to align the IP header.

But it's not clear it is still a good idea because it leads to cache line misalignment of the beginning of the packet, forcing the card to do a costly Read-Modify-Write cycle.

Exactly. Ben H is running into this, and pondering direct use of alloc_skb for precisely this reason.

Problem with changing it is that the payload ends up misaligned. And user space usually aligns the buffer passed to recvmsg. This means csum_copy_to_user has to csum-copy unaligned->aligned, which will be likely very slow.

Related problem is that the TCP/IP headers are unaligned, but if your CPU has fast enough misalignment handling it shouldn't be too bad.

-Andi

#4 lore raw
In reply to Andi Kleen

From: Andi Kleen <[email protected]>
Date: Wed, 9 Jul 2003 17:53:55 +0200

But it's not clear it is still a good idea because it leads to cache line misalignment of the beginning of the packet, forcing the card to do a costly Read-Modify-Write cycle.

Only "dumb cards" do that, smart ones rewind to the beginning of the current cache line and ask for the whole thing instead of pieces.

The +16 is actually needed to align the first hunk of the outgoing packet so we can do a 16-byte aligned memcpy of the hard-header cache as we build the packet.

Jeff, look at LL_RESERVED_SPACE() and the comment above it in include/linux/netdevice.h