tun: avoid high-order page allocation for packet header
Subsystems (3)
PATCH v2 1/1 tun: avoid high-order page allocation for packet header
When GSO is not enabled and a packet is transmitted via writev(), all payload is treated as header which requires a contiguous memory allocation. This allocation request is harder to satisfy, and may even fail if there is enough fragmentation.
Note that sendmsg() code path limits the linear copy length, so this change makes writev() and sendmsg() more consistent.
---
v2: replace linear == 0 with !linear
v1: https://lore.kernel.org/all/[email protected]/
drivers/net/tun.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/tun.c +4 -1
@@ -1523,7 +1523,7 @@ static struct sk_buff *tun_alloc_skb(struct tun_file *tfile,int err;/* Under a page? Don't bother with paged skb. */ -if (prepad + len <PAGE_SIZE || !linear) +if (prepad + len <PAGE_SIZE ) linear = len; skb = sock_alloc_send_pskb(sk, prepad + linear, len - linear, noblock,
@@ -1838,6 +1838,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,*/ zerocopy = false; }else { +if (!linear) + linear =min_t (size_t, good_linear, copylen); + skb =tun_alloc_skb (tfile, align, copylen, linear, noblock); }
Signature · 1 line
2.41.0
Quoted 11 lines · Tahsin Erdogan
When GSO is not enabled and a packet is transmitted via
writev(), all payload is treated as header which requires a contiguous memory allocation. This allocation request is harder to satisfy, and may even fail if there is enough fragmentation.Note that
sendmsg()code path limits the linear copy length, so this change makeswritev()andsendmsg()more consistent.Signed-off-by Tahsin Erdogan <[email protected]>---
I will have to tweak one existing packetdrill test, nothing major.
Thanks.
Quoted 11 lines · Eric Dumazet
Quoted 9 lines · Tahsin Erdogan
When GSO is not enabled and a packet is transmitted via
writev(), all payload is treated as header which requires a contiguous memory allocation. This allocation request is harder to satisfy, and may even fail if there is enough fragmentation.Note that
sendmsg()code path limits the linear copy length, so this change makeswritev()andsendmsg()more consistent.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Tahsin Erdogan <[email protected]>---
I will have to tweak one existing packetdrill test, nothing major.
Tested-by Eric Dumazet <[email protected]>Reviewed-by Eric Dumazet <[email protected]>
I have to take this back, sorry.
We need to change alloc_skb_with_frags() and tun.c to attempt high-order allocations,
otherwise tun users sending very large buffers will regress. (Even if this _could_ fail as you pointed out if memory is tight/fragmented)
I am working to make the change in alloc_skb_with_frags() and in tun, we can apply your patch after this prereq.
Willem de Bruijn
maintainerQuoted 22 lines · Eric Dumazet
Quoted 11 lines · Eric Dumazet
Quoted 9 lines · Tahsin Erdogan
When GSO is not enabled and a packet is transmitted via
writev(), all payload is treated as header which requires a contiguous memory allocation. This allocation request is harder to satisfy, and may even fail if there is enough fragmentation.Note that
sendmsg()code path limits the linear copy length, so this change makeswritev()andsendmsg()more consistent.Quoted 7 lines
Quoted 2 lines
Signed-off-by Tahsin Erdogan <[email protected]>---
I will have to tweak one existing packetdrill test, nothing major.
Tested-by Eric Dumazet <[email protected]>Reviewed-by Eric Dumazet <[email protected]>I have to take this back, sorry.
Quoted 7 lines
We need to change
alloc_skb_with_frags()andtun.cto attempt high-order allocations,
otherwise tun users sending very large buffers will regress. (Even if this _could_ fail as you pointed out if memory is tight/fragmented)I am working to make the change in
alloc_skb_with_frags()and in tun, we can apply your patch after this prereq.
This exactly same allocation logic also exists in packet_alloc_skb and tap_alloc_skb. If changing one of them, perhaps should address convert all at the same time, to keep behavior consistent.
Quoted 4 lines · Willem de Bruijn
Quoted 2 lines
This exactly same allocation logic also exists in
packet_alloc_skband
tap_alloc_skb. If changing one of them, perhaps should address convert all at the same time, to keep behavior consistent.
Sure, I can take care of them as well.
Quoted 26 lines · Eric Dumazet
Quoted 14 lines · Eric Dumazet
Quoted 12 lines · Tahsin Erdogan
When GSO is not enabled and a packet is transmitted via
writev(), all
payload is treated as header which requires a contiguous memory allocation.
This allocation request is harder to satisfy, and may even fail if there is
enough fragmentation.Note that
sendmsg()code path limits the linear copy length, so this change
makeswritev()andsendmsg()more consistent.Quoted 7 lines
Quoted 2 lines
Signed-off-by Tahsin Erdogan <[email protected]>---
I will have to tweak one existing packetdrill test, nothing major.
Tested-by Eric Dumazet <[email protected]>Reviewed-by Eric Dumazet <[email protected]>I have to take this back, sorry.
Quoted 8 lines
We need to change
alloc_skb_with_frags()andtun.cto attempt high-order allocations,
otherwise tun users sending very large buffers will regress. (Even if this _could_ fail as you pointed out if memory is tight/fragmented)I am working to make the change in
alloc_skb_with_frags()and in tun, we can apply your patch after this prereq.
Hi Eric, I believe your changes are merged. Are we good to apply my patch next?
Quoted 2 lines · Tahsin
Hi Eric, I believe your changes are merged. Are we good to apply my patch next?
Sure thing, please rebase and resend.
Thanks.