* [PATCH] tun: avoid high-order page allocation for packet header
@ 2023-07-26 3:09 Tahsin Erdogan
2023-07-31 20:58 ` Jakub Kicinski
0 siblings, 1 reply; 3+ messages in thread
From: Tahsin Erdogan @ 2023-07-26 3:09 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Herbert Xu
Cc: Tahsin Erdogan, netdev, linux-kernel
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.
Signed-off-by: Tahsin Erdogan <trdgn@amazon.com>
---
drivers/net/tun.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index d75456adc62a..b9d111fbea63 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -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 == 0)
+ linear = min_t(size_t, good_linear, copylen);
+
skb = tun_alloc_skb(tfile, align, copylen, linear,
noblock);
}
--
2.41.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tun: avoid high-order page allocation for packet header
2023-07-26 3:09 [PATCH] tun: avoid high-order page allocation for packet header Tahsin Erdogan
@ 2023-07-31 20:58 ` Jakub Kicinski
2023-07-31 23:03 ` Erdogan, Tahsin
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2023-07-31 20:58 UTC (permalink / raw)
To: Tahsin Erdogan
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Herbert Xu, netdev,
linux-kernel
On Tue, 25 Jul 2023 20:09:36 -0700 Tahsin Erdogan wrote:
> @@ -1838,6 +1838,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
> */
> zerocopy = false;
> } else {
> + if (linear == 0)
> + linear = min_t(size_t, good_linear, copylen);
nit: would you mind changing to !linear instead of linear == 0 ?
Also - I don't see linear explicitly getting set to 0. What guarantees
that? What's the story there?
Otherwise seems reasonable. One more allocation but hopefully nobody
will notice.
--
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tun: avoid high-order page allocation for packet header
2023-07-31 20:58 ` Jakub Kicinski
@ 2023-07-31 23:03 ` Erdogan, Tahsin
0 siblings, 0 replies; 3+ messages in thread
From: Erdogan, Tahsin @ 2023-07-31 23:03 UTC (permalink / raw)
To: kuba@kernel.org
Cc: herbert@gondor.apana.org.au, edumazet@google.com,
davem@davemloft.net, netdev@vger.kernel.org, pabeni@redhat.com,
linux-kernel@vger.kernel.org
Thanks Jakub for considering this patch.
On Mon, 2023-07-31 at 13:58 -0700, Jakub Kicinski wrote:
> On Tue, 25 Jul 2023 20:09:36 -0700 Tahsin Erdogan wrote:
> > @@ -1838,6 +1838,9 @@ static ssize_t tun_get_user(struct tun_struct
> > *tun, struct tun_file *tfile,
> > */
> > zerocopy = false;
> > } else {
> > + if (linear == 0)
> > + linear = min_t(size_t, good_linear,
> > copylen);
>
> nit: would you mind changing to !linear instead of linear == 0 ?
Yes, I will fix this in v2.
> Also - I don't see linear explicitly getting set to 0. What
> guarantees
> that? What's the story there?
linear is set to 0 in the earlier if block. When gso.hdr_len is 0,
linear also becomes 0:
if (!zerocopy) {
copylen = len;
if (tun16_to_cpu(tun, gso.hdr_len) > good_linear)
linear = good_linear;
else
linear = tun16_to_cpu(tun, gso.hdr_len);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-31 23:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-26 3:09 [PATCH] tun: avoid high-order page allocation for packet header Tahsin Erdogan
2023-07-31 20:58 ` Jakub Kicinski
2023-07-31 23:03 ` Erdogan, Tahsin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox