From nobody Tue Sep 9 12:45:36 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 943FEEB64DD for ; Wed, 26 Jul 2023 03:10:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229550AbjGZDKI (ORCPT ); Tue, 25 Jul 2023 23:10:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231262AbjGZDJ7 (ORCPT ); Tue, 25 Jul 2023 23:09:59 -0400 Received: from smtp-fw-9105.amazon.com (smtp-fw-9105.amazon.com [207.171.188.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AA1F2717; Tue, 25 Jul 2023 20:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1690340991; x=1721876991; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=OO5DgnVYIF6etA+A5spa7likYOAXNBzPyYRVt7m4VLg=; b=F0t10OTrbbqChGuLBNRlRKFX6xx9iNoD/L+gln42Zo9Ozuhfo8BCIZfg wTmetSEeaIf7oKtkGXNNXv19+xwTbnz6idLYcYInbIEaOLh1GVvHieDJ3 U181QphxiynKTTBu2s6/3813LmsY31B+6X0Z9VR1vTIGrH9cZ85TRFPEA 0=; X-IronPort-AV: E=Sophos;i="6.01,231,1684800000"; d="scan'208";a="662694391" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-3554bfcf.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-9105.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2023 03:09:50 +0000 Received: from EX19MTAUWC001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1e-m6i4x-3554bfcf.us-east-1.amazon.com (Postfix) with ESMTPS id EE921806AA; Wed, 26 Jul 2023 03:09:46 +0000 (UTC) Received: from EX19D019UWB002.ant.amazon.com (10.13.139.149) 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, 26 Jul 2023 03:09:40 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D019UWB002.ant.amazon.com (10.13.139.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 26 Jul 2023 03:09:40 +0000 Received: from u7187ce7291cc57.ant.amazon.com (10.187.170.17) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server id 15.2.1118.30 via Frontend Transport; Wed, 26 Jul 2023 03:09:39 +0000 From: Tahsin Erdogan To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Herbert Xu CC: Tahsin Erdogan , , Subject: [PATCH] tun: avoid high-order page allocation for packet header Date: Tue, 25 Jul 2023 20:09:36 -0700 Message-ID: <20230726030936.1587269-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 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 --- 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; =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 skb =3D sock_alloc_send_pskb(sk, prepad + linear, len - linear, noblock, @@ -1838,6 +1838,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, s= truct tun_file *tfile, */ zerocopy =3D false; } else { + if (linear =3D=3D 0) + linear =3D min_t(size_t, good_linear, copylen); + skb =3D tun_alloc_skb(tfile, align, copylen, linear, noblock); } --=20 2.41.0