Skip to content

Commit 6231e47

Browse files
Tahsin Erdogankuba-moo
authored andcommitted
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. Signed-off-by: Tahsin Erdogan <[email protected]> Acked-by: Jason Wang <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5604ac3 commit 6231e47

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/net/tun.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ static struct sk_buff *tun_alloc_skb(struct tun_file *tfile,
15231523
int err;
15241524

15251525
/* Under a page? Don't bother with paged skb. */
1526-
if (prepad + len < PAGE_SIZE || !linear)
1526+
if (prepad + len < PAGE_SIZE)
15271527
linear = len;
15281528

15291529
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,
18401840
*/
18411841
zerocopy = false;
18421842
} else {
1843+
if (!linear)
1844+
linear = min_t(size_t, good_linear, copylen);
1845+
18431846
skb = tun_alloc_skb(tfile, align, copylen, linear,
18441847
noblock);
18451848
}

0 commit comments

Comments
 (0)