On Fri, 2017-01-27 at 17:24 +0000, David Laight wrote:
> From: Eric Dumazet
> > Sent: 27 January 2017 14:44
> ...
> > > I'm also guessing that extra headroom can be generated by stealing unused 
> > > tailroom.
> > 
> > This is already done.
> > 
> > Quoting
> > https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=87fb4b7b533073eeeaed0b6bf7c
> > 2328995f6c075
> > 
> >     At skb alloc phase, we put skb_shared_info struct at the exact end of
> >     skb head, to allow a better use of memory (lowering number of
> >     reallocations), since kmalloc() gives us power-of-two memory blocks.
> 
> Does that actually have the expected effect?
> 
> Allocate an skb for 512 bytes, copy in some data with 64 bytes of headroom.
> This is (probably) a 1k memory block with skb_shared_info at the end.
> 
> Some code needs to add a header that doesn't fit, calls pskb_expand_head()
> to get another 4 bytes.
> Since the existing amount of 'tailroom' must be kept kmalloc(1024+4) is 
> called.
> This allocates a 2k memory block, again skb_shared_info is put at the end.
> So the headroom has been increased by 4 bytes and the tailroom by 1020.
> 
> Another layer needs to add another header.
> The memory block becomes 4k large.
> 
> What have I missed?

We try hard to pre-allocate enough headroom.

Because copies are expensive.

Look for MAX_HEADER, MAX_TCP_HEADER, and things like that.

For the tail, we add 128 bytes of extra tail when __pskb_pull_tail()
wants to expand skb->head.

If you believe you found a use case where we do stupid reallocations,
please fix the caller.

pskb_expand_head() should never be called, really.

Only for some pathological/malicious traffic we have to, eventually.





Reply via email to