diff mbox series

tun: avoid high-order page allocation for packet header

Message ID 20230726030936.1587269-1-trdgn@amazon.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series tun: avoid high-order page allocation for packet header | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1342 this patch: 1342
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 1365 this patch: 1365
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1365 this patch: 1365
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Tahsin Erdogan July 26, 2023, 3:09 a.m. UTC
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(-)

Comments

Jakub Kicinski July 31, 2023, 8:58 p.m. UTC | #1
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.
Tahsin Erdogan July 31, 2023, 11:03 p.m. UTC | #2
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);
        }
diff mbox series

Patch

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);
 		}