Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3647398imw; Thu, 7 Jul 2022 05:28:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ug/OIoE1ndjS6+/8MIKXUF5pD3TFj3HOlpQJByGUuq1FFFGhs3ZvJ7cFy0vrROOP4kMCQy X-Received: by 2002:a17:906:b048:b0:6fe:be4a:3ecf with SMTP id bj8-20020a170906b04800b006febe4a3ecfmr45708227ejb.104.1657196915472; Thu, 07 Jul 2022 05:28:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657196915; cv=none; d=google.com; s=arc-20160816; b=uo71tw23B+1lwhnFrpuJMG5JdsdeB7BBMR/f/J3nvW4TVnYosswbEtlwhK8ZCiwjVk a6dqb+d35bhb8LXULE7X+NJiPpT6xPz64x7hRyjesRkhKA/CgYs/sjkzCpbK8Brr6Zup nOd+G7/771mFwyl/kEQFPYBLnVxS25ySkmC13VoqIV4bA4WZ6yA8ENbHJ+JllxF8e6Kx BHZ2ElEoMSaPADxtxtJiS/6nVl/hNFYD7hpjKY+d+becg2bbGJ4YwSVgrTgZII5yd3Qb UVeKcD33IGSQue0ksHTLN8rObk8e28X9Mn9Dqt5DJ8Yi9uIkNtN+crE2dlhtN3aF9o7O zM8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dYMbDXosaDJGTx1SMZg80SJyMd9PTOfSaObug9b0vzk=; b=kzVoNgW3X9w46IKPQbFF1AuJGW9B14XF0wU5+DZ+YsSG5Exu17HGe4Ud8NqSdVG9U9 mT13fHws8pba8vnP7zUTjSz+4ZyBHxcK1Bt9yhlbXD8AcjmodklpOU6CfsBq2oEHyPkr EuCYmlpCiToc0zgw+0tMx46VMJb968AQQV+Z4LtI0SCkj5JVJ3eGY4xOK9uyC9OCIe41 EpSJyH1OtL2b9DN0ne+TCFnr7EELou5QT8nk+uT/yRVNSSd516SIMgFttGYjX5MBCb3K nsolrZYg+5c0qHf/8KAVBzTxNWrLNptO5FfWVEtel1ugnqx4HA5S7lxbfPdTjIifbrJ7 h/TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oJVIkX7+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q18-20020a056402041200b0043a9ff27c64si647402edv.530.2022.07.07.05.28.10; Thu, 07 Jul 2022 05:28:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oJVIkX7+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235458AbiGGLwD (ORCPT + 99 others); Thu, 7 Jul 2022 07:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234847AbiGGLvv (ORCPT ); Thu, 7 Jul 2022 07:51:51 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 037D153D0E; Thu, 7 Jul 2022 04:51:51 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id bk26so10878971wrb.11; Thu, 07 Jul 2022 04:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dYMbDXosaDJGTx1SMZg80SJyMd9PTOfSaObug9b0vzk=; b=oJVIkX7+2mHbvLuNu/u98vd92tZ0pCmSw7ZvJvTU9TV8S6d0b9S/g6p0Hr00d8LSJO xTpNllKVbC7MX6MbuQMH22+lwJnJuULFSgEyW2NCw1sfB37xvvlzt0DUPtGV6o6sAxpy +41wY3VkiUbDZwk+zqZZIyBHNVjSsOI66Ad3b+F1kP90AyawnhxxyniaquEKCKqvpI1G 8J5wreGKmpG7LTYH4vbFzkiG0JNmSkvL0w0q8alKNEqxBH0kvXyAhrQ+Nk6Qc5tF36qY 9HlNHoe/ACqJ1gVbYmLFngSjQSI0j9kUtcHjoH6d8PilwoeFJG4nx+Mv20fvfcEIvpbP oTCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dYMbDXosaDJGTx1SMZg80SJyMd9PTOfSaObug9b0vzk=; b=comJHATdJBpL69hdyJ+Edti2MXL4iN607EZeSSaWcAV5b/wknYYkTWQKEQTLsFV/ub +76LsqJGM2Xis3FdiKq32hXu+sauAe6ZodNHeAuKuGEycLosNIUaOOnRPNNbz+PRnjfX GSql0bBEaytsugvMxa+1rXGbg+eA41qjWR2dRo3i8wcXscCKt4X1n1U+Kgeb+XyaA5Ns iP95b4fVL3CMF9B5LEst+q5RKT55kz4tcYCG0CaFNYOAYZLpDa81DhfGLKl/J8aAoSPw 2FCYwfHZy9qOx0M0RYVM5JwBX1hKBXurttEE0dIMxxh6GY9OxQIbeczp/fnI13wYSZdk 9wLw== X-Gm-Message-State: AJIora9c6cyvgz6g4Oj8dlJcSxkr6jT8deoGnvb2Ra4wZsOvqe1Lqzoj sOHqENlkglnWK1d27RHwKga/mXDJwX7/vo8fP0g= X-Received: by 2002:a05:6000:2cb:b0:21d:7760:778c with SMTP id o11-20020a05600002cb00b0021d7760778cmr11450539wry.329.1657194709350; Thu, 07 Jul 2022 04:51:49 -0700 (PDT) Received: from 127.0.0.1localhost (188.28.125.106.threembb.co.uk. [188.28.125.106]) by smtp.gmail.com with ESMTPSA id u2-20020a5d5142000000b0021b966abc19sm37982131wrt.19.2022.07.07.04.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 04:51:48 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Jonathan Lemon , Willem de Bruijn , Jens Axboe , David Ahern , kernel-team@fb.com, Pavel Begunkov Subject: [PATCH net-next v4 02/27] ipv6: avoid partial copy for zc Date: Thu, 7 Jul 2022 12:49:33 +0100 Message-Id: <899f19034c94ce4ce75464df132edf1b3a192ebd.1657194434.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Even when zerocopy transmission is requested and possible, __ip_append_data() will still copy a small chunk of data just because it allocated some extra linear space (e.g. 128 bytes). It wastes CPU cycles on copy and iter manipulations and also misalignes potentially aligned data. Avoid such coies. And as a bonus we can allocate smaller skb. Signed-off-by: Pavel Begunkov --- net/ipv6/ip6_output.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 77e3f5970ce4..fc74ce3ed8cc 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1464,6 +1464,7 @@ static int __ip6_append_data(struct sock *sk, int copy; int err; int offset = 0; + bool zc = false; u32 tskey = 0; struct rt6_info *rt = (struct rt6_info *)cork->dst; struct ipv6_txoptions *opt = v6_cork->opt; @@ -1549,6 +1550,7 @@ static int __ip6_append_data(struct sock *sk, if (rt->dst.dev->features & NETIF_F_SG && csummode == CHECKSUM_PARTIAL) { paged = true; + zc = true; } else { uarg->zerocopy = 0; skb_zcopy_set(skb, uarg, &extra_uref); @@ -1630,9 +1632,12 @@ static int __ip6_append_data(struct sock *sk, (fraglen + alloc_extra < SKB_MAX_ALLOC || !(rt->dst.dev->features & NETIF_F_SG))) alloclen = fraglen; - else { + else if (!zc) { alloclen = min_t(int, fraglen, MAX_HEADER); pagedlen = fraglen - alloclen; + } else { + alloclen = fragheaderlen + transhdrlen; + pagedlen = datalen - transhdrlen; } alloclen += alloc_extra; -- 2.36.1