Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp41026pxb; Wed, 20 Jan 2021 00:16:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnr8HIdyL8XcVXD0JCV1m09l7OIoFSqwGSk32sasjdEGvjwIRuw9Etf+P1v0WJhGasr9sq X-Received: by 2002:a17:906:60c3:: with SMTP id f3mr5288539ejk.65.1611130564915; Wed, 20 Jan 2021 00:16:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611130564; cv=none; d=google.com; s=arc-20160816; b=oLoFOKQ1vBv4QDUghNx1QVCyQ+uDRE1nIQuTrYfsDNFR+EZf67zLbgFWYlqt4Ss7N0 1qi+JEJb79glXttezm4nfk5/a3dSo1dgiQKa3EzOq6tkMerI3e6GEixKPXPWOgElAgjI PlQXB6Fd4x/oGYTBa1jorBcibovB9vH6uyo5xXOlYW7U9M5hyzzo/LUYUIKPY0lLdCYc Ims8KMjga5arr75s6qWsNY7hllsM8V1yg3/vue7+Kpr/KlI0F4ovh1amursG2xRNRFNx DCPCcm3jH+uok4RtKbj4qEkiUDQfu6yWPRw6jK+xJcfqXEjDf7n1Kee1o+HTgsOelyOV 2JQA== 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=SgoON6JCbiRoEe3MsxmL7+i8CTj6HRhH96NwSvSwXcc=; b=AhT3LUuAMInXqWAtyciFH9Eb2G8I8Nr9k++R13Mex3w9r7yzyfW0KKrrSMnCmZvRoG VFDpp0oEz1cerVtB8f9eT4Pc7BG0X7h/SuUyx04hRBT687+Nrx8kliX+UUkTOj4Ul1bF kqpePV1V1IYelGeM9OMkT7qQ1IgWPGqt3RjNVMaC5ee+CUJR6dvHeLHbEeEpHy+ZNZNE P3X64hc/s9KCr/3r+ym6hFu5By7/0HhUUrWlhu4IJ9vYfwqfGqFDigtXgyTb42qy3Xv+ hKNtkHCbtS3jxoKnaJUV5sWWawksZnsGHaSJidRTS8dFCback1py/75m9UyDAgds91mo VZnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=W5VvnZPP; 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 gs8si441218ejc.79.2021.01.20.00.15.41; Wed, 20 Jan 2021 00:16:04 -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=W5VvnZPP; 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 S1730430AbhATIOh (ORCPT + 99 others); Wed, 20 Jan 2021 03:14:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40006 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730530AbhATIN1 (ORCPT ); Wed, 20 Jan 2021 03:13:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611130320; 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=SgoON6JCbiRoEe3MsxmL7+i8CTj6HRhH96NwSvSwXcc=; b=W5VvnZPPTNXyseReGbsJiWrDLKquynG3QR4UJPJ4UCVoUaxmXSdj+m0gYBCuvVUp1N82fb khotffMened5jjWTsy/D+1NjoK786QFF2BBvdJKiJ1SEekOqVMcEImmYp81dVmiYzXFCJ8 hnobXFIZvHGwQpSJRx75OBC9vDVH9c8= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-543-NQdwpMPiOceo0UdUUwpcCQ-1; Wed, 20 Jan 2021 03:11:58 -0500 X-MC-Unique: NQdwpMPiOceo0UdUUwpcCQ-1 Received: by mail-wr1-f71.google.com with SMTP id n11so11044961wro.7 for ; Wed, 20 Jan 2021 00:11:58 -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=SgoON6JCbiRoEe3MsxmL7+i8CTj6HRhH96NwSvSwXcc=; b=CNoDkUABAC0EN0g6cLuUQfyDTpSqzdBL4SHhU01cnkLzhzYPrfjMONmQNqcwn6YTR9 KQlr/r0ldJ0IUFI+V3YBA0YBR9NFe58nC4z146gTui9LAnZEIWlT3H4wzLUpE5Gkf/g0 /j0xtn+YB2gYQO5cHXXxzaHo7hTLHu4EyM6NV38yzdbXUvr2lS6lGmMEKYH6zPvv6M7b GQ4PA1WP9F5/yLIvhEeuHYXMqIBNiK0YzKChUO3UllgbxckQ7GxdZgYKaROyXABNvcc5 bOrSjrCI/37gy1boEM1sPksUY/t08nA1VeIa5oVjaxTDV1Es+/NbGyJ4dZxzf0e30Fgv M/0A== X-Gm-Message-State: AOAM531yH8tWqy4IX400juSd0APTnGWmEtTiyy7sxJNX5gppP5vtQluS fyjZ8jUfudeEC3qcHXOstM20/tGB9XK8Y7IxzxyYqlVpCzYT6Ugwmg5RJofD6zuxrr8iVwy5Von NCIs+Q1PgYqWVyYc5GIz5cWKn X-Received: by 2002:a05:6000:11c1:: with SMTP id i1mr8130835wrx.16.1611130317170; Wed, 20 Jan 2021 00:11:57 -0800 (PST) X-Received: by 2002:a05:6000:11c1:: with SMTP id i1mr8130807wrx.16.1611130316948; Wed, 20 Jan 2021 00:11:56 -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 h9sm2367974wre.24.2021.01.20.00.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 00:11:56 -0800 (PST) Date: Wed, 20 Jan 2021 03:11:52 -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: <20210120031130-mutt-send-email-mst@kernel.org> References: <6787e9a100eba47efbff81939e21e97fef492d07.1611128806.git.xuanzhuo@linux.alibaba.com> <20210120030418-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210120030418-mutt-send-email-mst@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 03:11:04AM -0500, Michael S. Tsirkin wrote: > 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? Hmm looked again and now I do see them. My mistake pls ignore. > > > --- > > 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