From nobody Tue Sep 9 13:05:17 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ECACC001B0 for ; Wed, 9 Aug 2023 16:48:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230411AbjHIQsD (ORCPT ); Wed, 9 Aug 2023 12:48:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbjHIQsC (ORCPT ); Wed, 9 Aug 2023 12:48:02 -0400 Received: from smtp-fw-52003.amazon.com (smtp-fw-52003.amazon.com [52.119.213.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 618AF1FCC; Wed, 9 Aug 2023 09:48:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1691599682; x=1723135682; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RZ0TDIAWVWjKzQG/fNH2WZoDHlB8BqVrxrTKmYL0yWg=; b=i4YqLRU+bm0mYYtMw0nAxEroCu+WZB/RppLKwPI7QaW9/bA61fBX/058 dxGrFD5vYwtPiNxF3WjU98p8tdahTc0S/QRO9B65FHRW6qd6Gv5/asp5U ByQ3LTOOczDMYUUtxGBqMJAgvFBToxWBelkGm9p6Y/MxT7DoWNOcNhCv7 Q=; X-IronPort-AV: E=Sophos;i="6.01,159,1684800000"; d="scan'208";a="601118400" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2a-m6i4x-1197e3af.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-52003.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2023 16:48:00 +0000 Received: from EX19MTAUWC001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-pdx-2a-m6i4x-1197e3af.us-west-2.amazon.com (Postfix) with ESMTPS id BEB0D1040B3; Wed, 9 Aug 2023 16:47:58 +0000 (UTC) Received: from EX19D019UWB001.ant.amazon.com (10.13.139.189) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 9 Aug 2023 16:47:57 +0000 Received: from EX19MTAUEA001.ant.amazon.com (10.252.134.203) by EX19D019UWB001.ant.amazon.com (10.13.139.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 9 Aug 2023 16:47:56 +0000 Received: from u7187ce7291cc57.ant.amazon.com (10.135.199.88) by mail-relay.amazon.com (10.252.134.102) with Microsoft SMTP Server id 15.2.1118.30 via Frontend Transport; Wed, 9 Aug 2023 16:47:55 +0000 From: Tahsin Erdogan To: Willem de Bruijn , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Herbert Xu CC: Tahsin Erdogan , , Subject: [PATCH v4] tun: avoid high-order page allocation for packet header Date: Wed, 9 Aug 2023 09:47:52 -0700 Message-ID: <20230809164753.2247594-1-trdgn@amazon.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Acked-by: Jason Wang Reviewed-by: Eric Dumazet Reviewed-by: Willem de Bruijn --- v4: updated commit message address comments from Willem v3: rebase to latest net-next v2: replace linear =3D=3D 0 with !linear v1: https://lore.kernel.org/all/20230726030936.1587269-1-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 973b2fc74de3..62106464f1b9 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; =20 /* Under a page? Don't bother with paged skb. */ - if (prepad + len < PAGE_SIZE || !linear) + if (prepad + len < PAGE_SIZE) linear =3D len; =20 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, s= truct tun_file *tfile, */ zerocopy =3D false; } else { + if (!linear) + linear =3D min_t(size_t, good_linear, copylen); + skb =3D tun_alloc_skb(tfile, align, copylen, linear, noblock); } --=20 2.41.0