Skip to contentSkip to conversation

tun: avoid high-order page allocation for packet header

PATCH Applied Tahsin Erdogan 5 participants 5 messages Aug 9, 2023 – Aug 11, 2023

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

PATCH v4 1/1 tun: avoid high-order page allocation for packet header

When gso.hdr_len is zero and a packet is transmitted via write() or 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 write()/writev() and sendmsg() paths more consistent.

---
v4: updated commit message address comments from Willem
v3: rebase to latest net-next
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
index 973b2fc74de3..62106464f1b9 100644
@@ -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;
 
 	if (len - linear > MAX_SKB_FRAGS * (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER))
@@ -1840,6 +1840,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
Acked-by on v4 1/1
#1 lore raw
Quoted 9 lines · Tahsin Erdogan

When gso.hdr_len is zero and a packet is transmitted via write() or 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 write()/writev() and sendmsg() paths more consistent.

Quoted 6 lines

---
v4: updated commit message address comments from Willem
v3: rebase to latest net-next
v2: replace linear == 0 with !linear
v1: https://lore.kernel.org/all/[email protected]/

Thanks

Reviewed-by on v4 1/1
#2 lore raw
In reply to Tahsin Erdogan
Quoted 10 lines · Tahsin Erdogan

When gso.hdr_len is zero and a packet is transmitted via write() or 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 write()/writev() and sendmsg() paths more consistent.

Thanks.

maintainer Reviewed-by on v4 1/1
#3 lore raw
In reply to Tahsin Erdogan
Quoted 9 lines · Tahsin Erdogan

When gso.hdr_len is zero and a packet is transmitted via write() or 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 write()/writev() and sendmsg() paths more consistent.

#4 lore raw
In reply to Tahsin Erdogan
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Wed, 9 Aug 2023 09:47:52 -0700 you wrote:

When gso.hdr_len is zero and a packet is transmitted via write() or 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 write()/writev() and sendmsg() paths more consistent.

[...]

Here is the summary with links:
- [v4] tun: avoid high-order page allocation for packet header

    https://git.kernel.org/netdev/net-next/c/6231e47b6fad

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html