Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp39886pxb; Wed, 20 Jan 2021 00:14:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJz600z90GhlEWclkSPKxtEwFeVvkhP9jToimAXjEi90I7uY8ekL00X7DOPHYqWdcZkMqEC7 X-Received: by 2002:a17:906:97c5:: with SMTP id ef5mr5507055ejb.347.1611130441931; Wed, 20 Jan 2021 00:14:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611130441; cv=none; d=google.com; s=arc-20160816; b=dwXUawtU8I+X8Pf9gIwNYlbMmg9j8GFUJpu2KoHoAZ0aeKbOXXyqo4YaO/nfUtoHL4 oHP3RNTH9TGc803hqvx02aHMZCPKoURAVmoywLtLr3q1NtkeRA+Z3fJ8fofRtqZ/nt9I ANkGui9DtoLdpVOGV1W5tqf01oKCa4PLDOGl29LUCdmtqdUlsWtvLiEie6sJGKAGO8rs NMhRWWIRFwDcr+Ty0YxZhuyObMMAFzfYHR6O2BoJrUfkvjWut1GmiXY2jQ3UwxJIVwl2 MGPqnCE1VwOcDMyEjoOyCNyWWPX/WbDIZlVhH86kHbIraHYdV30d5IivUI/AKeQTjiN+ t5rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WYlBb00a1Y6CTzqOK72/0+v2yGyDzKaR7ND9mWSLlUg=; b=UBxS0rY/WhxVX1zVc3r76nw0y698QFE3t4A52P8EassuCROX0aIcimVGFWlTEX94Zh n6tz0N2pWYTjkQ4rs1haPaaUQhnvSb09ueeH5EpkNkggiXLEnscIjPMxfy25wcFBYmq+ yRK/qopZFLKpnNx4C3I0Xu7wfpqwkOKwnP75j29oXZafn1BaJfmI1ipOhhGqERSLeGJJ Q3+081mh3bqLD0L6sBGEO2RboMC8PyMD/7b38RkaSJ2ufW+Y7oCoxEtEp8GAPLCbiUJP gJbP0XdDoX1GhCcSNch5PMdn5/lm4oMr1t29k1GR8LCnHSnsm0d+RPOT4GGbFAIqCHUP D+Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QbgljwxR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gb19si463558ejc.338.2021.01.20.00.13.38; Wed, 20 Jan 2021 00:14:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QbgljwxR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730499AbhATINK (ORCPT + 99 others); Wed, 20 Jan 2021 03:13:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21368 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730336AbhATIMf (ORCPT ); Wed, 20 Jan 2021 03:12:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611130268; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WYlBb00a1Y6CTzqOK72/0+v2yGyDzKaR7ND9mWSLlUg=; b=QbgljwxRGaISt7lRdc4GVMNp66ntUirPu9hYkqUcvtOqW6d5XuUrKYTQX0MSVDgd6Hpyj4 7/8AB3gvqWuTbreHWUYhaIuKOMn1a0uX0WQesyzXdvzpmmILv3ufwoRFV1lh+S4XaemEwZ g6sHQ0hjaUAU64py5Y+QKBZLqOgl7es= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-252-2JDFj4r_Pa-ZDlvDim9z3w-1; Wed, 20 Jan 2021 03:11:06 -0500 X-MC-Unique: 2JDFj4r_Pa-ZDlvDim9z3w-1 Received: by mail-wr1-f72.google.com with SMTP id z8so11088706wrh.5 for ; Wed, 20 Jan 2021 00:11:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WYlBb00a1Y6CTzqOK72/0+v2yGyDzKaR7ND9mWSLlUg=; b=ifzvQuo/jtG6H4l42SfOTq9uiLm0rS3bgjIB82UU29IbdSyTeCXD88mAY8w1Yy1QHE fMdvEm3TRWov+23LZMBJ/Zl8GwXiL3FVmyPnhLKy39dS/7ljeZUzbSda5oiTJbZnW1Jl RN99xat9Txpr707ymhGilJfclbqgT21MfjS/iX1rTBfX6/kwxEYrqu4Ce12o0ds9WcKE DEMpvX4vSYO7/1xP2H8SmUbPQOQOUErnRG9KMkfqU0TSNqqSxX5uhOuzV1/L7Zp7n0OH Q4f+sFHRdsqQFDm4NMikTEEk/bNpTjMpwoXOPDz4OhwI1FvCHtn62pX2Yrz6pn085yc2 eOkw== X-Gm-Message-State: AOAM5303DWSoZj/lh+gWBjkRRGPCBUVKcDghIBDpbFwC+2H7Esi7O3wg 5ROjXzSlgzdTxKABsuy1QM7rBfaYk6CA2e8mTF7JFmxR032br1czXfSSMQznn+0uhweHsmTjVSA o4dR5ZWAzfuCdacUZ5QFUvKYA X-Received: by 2002:a05:6000:108b:: with SMTP id y11mr7802692wrw.379.1611130264807; Wed, 20 Jan 2021 00:11:04 -0800 (PST) X-Received: by 2002:a05:6000:108b:: with SMTP id y11mr7802669wrw.379.1611130264602; Wed, 20 Jan 2021 00:11:04 -0800 (PST) Received: from redhat.com (bzq-79-177-39-148.red.bezeqint.net. [79.177.39.148]) by smtp.gmail.com with ESMTPSA id u26sm2380200wmm.24.2021.01.20.00.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 00:11:03 -0800 (PST) Date: Wed, 20 Jan 2021 03:10:59 -0500 From: "Michael S. Tsirkin" To: Xuan Zhuo Cc: Alexander Lobakin , Jason Wang , "David S. Miller" , Jakub Kicinski , bjorn.topel@intel.com, Magnus Karlsson , Jonathan Lemon , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , virtualization@lists.linux-foundation.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v2 3/3] xsk: build skb by page Message-ID: <20210120030418-mutt-send-email-mst@kernel.org> References: <6787e9a100eba47efbff81939e21e97fef492d07.1611128806.git.xuanzhuo@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6787e9a100eba47efbff81939e21e97fef492d07.1611128806.git.xuanzhuo@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 03:50:01PM +0800, Xuan Zhuo wrote: > This patch is used to construct skb based on page to save memory copy > overhead. > > This function is implemented based on IFF_TX_SKB_NO_LINEAR. Only the > network card priv_flags supports IFF_TX_SKB_NO_LINEAR will use page to > directly construct skb. If this feature is not supported, it is still > necessary to copy data to construct skb. > > ---------------- Performance Testing ------------ > > The test environment is Aliyun ECS server. > Test cmd: > ``` > xdpsock -i eth0 -t -S -s > ``` > > Test result data: > > size 64 512 1024 1500 > copy 1916747 1775988 1600203 1440054 > page 1974058 1953655 1945463 1904478 > percent 3.0% 10.0% 21.58% 32.3% > > Signed-off-by: Xuan Zhuo > Reviewed-by: Dust Li I can't see the cover letter or 1/3 in this series - was probably threaded incorrectly? > --- > net/xdp/xsk.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++---------- > 1 file changed, 86 insertions(+), 18 deletions(-) > > diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c > index 8037b04..817a3a5 100644 > --- a/net/xdp/xsk.c > +++ b/net/xdp/xsk.c > @@ -430,6 +430,87 @@ static void xsk_destruct_skb(struct sk_buff *skb) > sock_wfree(skb); > } > > +static struct sk_buff *xsk_build_skb_zerocopy(struct xdp_sock *xs, > + struct xdp_desc *desc) > +{ > + u32 len, offset, copy, copied; > + struct sk_buff *skb; > + struct page *page; > + char *buffer; Actually, make this void *, this way you will not need casts down the road. I know this is from xsk_generic_xmit - I don't know why it's char * there, either. > + int err, i; > + u64 addr; > + > + skb = sock_alloc_send_skb(&xs->sk, 0, 1, &err); > + if (unlikely(!skb)) > + return ERR_PTR(err); > + > + addr = desc->addr; > + len = desc->len; > + > + buffer = xsk_buff_raw_get_data(xs->pool, addr); > + offset = offset_in_page(buffer); > + addr = buffer - (char *)xs->pool->addrs; > + > + for (copied = 0, i = 0; copied < len; i++) { > + page = xs->pool->umem->pgs[addr >> PAGE_SHIFT]; > + > + get_page(page); > + > + copy = min_t(u32, PAGE_SIZE - offset, len - copied); > + > + skb_fill_page_desc(skb, i, page, offset, copy); > + > + copied += copy; > + addr += copy; > + offset = 0; > + } > + > + skb->len += len; > + skb->data_len += len; > + skb->truesize += len; > + > + refcount_add(len, &xs->sk.sk_wmem_alloc); > + > + return skb; > +} > + > +static struct sk_buff *xsk_build_skb(struct xdp_sock *xs, > + struct xdp_desc *desc) > +{ > + struct sk_buff *skb = NULL; > + > + if (xs->dev->priv_flags & IFF_TX_SKB_NO_LINEAR) { > + skb = xsk_build_skb_zerocopy(xs, desc); > + if (IS_ERR(skb)) > + return skb; > + } else { > + char *buffer; > + u32 len; > + int err; > + > + len = desc->len; > + skb = sock_alloc_send_skb(&xs->sk, len, 1, &err); > + if (unlikely(!skb)) > + return ERR_PTR(err); > + > + skb_put(skb, len); > + buffer = xsk_buff_raw_get_data(xs->pool, desc->addr); > + err = skb_store_bits(skb, 0, buffer, len); > + if (unlikely(err)) { > + kfree_skb(skb); > + return ERR_PTR(err); > + } > + } > + > + skb->dev = xs->dev; > + skb->priority = xs->sk.sk_priority; > + skb->mark = xs->sk.sk_mark; > + skb_shinfo(skb)->destructor_arg = (void *)(long)desc->addr; > + skb->destructor = xsk_destruct_skb; > + > + return skb; > +} > + > static int xsk_generic_xmit(struct sock *sk) > { > struct xdp_sock *xs = xdp_sk(sk); > @@ -446,43 +527,30 @@ static int xsk_generic_xmit(struct sock *sk) > goto out; > > while (xskq_cons_peek_desc(xs->tx, &desc, xs->pool)) { > - char *buffer; > - u64 addr; > - u32 len; > - > if (max_batch-- == 0) { > err = -EAGAIN; > goto out; > } > > - len = desc.len; > - skb = sock_alloc_send_skb(sk, len, 1, &err); > - if (unlikely(!skb)) > + skb = xsk_build_skb(xs, &desc); > + if (IS_ERR(skb)) { > + err = PTR_ERR(skb); > goto out; > + } > > - skb_put(skb, len); > - addr = desc.addr; > - buffer = xsk_buff_raw_get_data(xs->pool, addr); > - err = skb_store_bits(skb, 0, buffer, len); > /* This is the backpressure mechanism for the Tx path. > * Reserve space in the completion queue and only proceed > * if there is space in it. This avoids having to implement > * any buffering in the Tx path. > */ > spin_lock_irqsave(&xs->pool->cq_lock, flags); > - if (unlikely(err) || xskq_prod_reserve(xs->pool->cq)) { > + if (xskq_prod_reserve(xs->pool->cq)) { > spin_unlock_irqrestore(&xs->pool->cq_lock, flags); > kfree_skb(skb); > goto out; > } > spin_unlock_irqrestore(&xs->pool->cq_lock, flags); > > - skb->dev = xs->dev; > - skb->priority = sk->sk_priority; > - skb->mark = sk->sk_mark; > - skb_shinfo(skb)->destructor_arg = (void *)(long)desc.addr; > - skb->destructor = xsk_destruct_skb; > - > err = __dev_direct_xmit(skb, xs->queue_id); > if (err == NETDEV_TX_BUSY) { > /* Tell user-space to retry the send */ > -- > 1.8.3.1