[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8da41980-e306-c0ae-03e2-83c20e2e84f0@redhat.com>
Date: Wed, 16 Jun 2021 10:45:40 +0800
From: Jason Wang <jasowang@...hat.com>
To: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>, netdev@...r.kernel.org
Cc: "David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
"Michael S. Tsirkin" <mst@...hat.com>,
Björn Töpel <bjorn@...nel.org>,
Magnus Karlsson <magnus.karlsson@...el.com>,
Jonathan Lemon <jonathan.lemon@...il.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Jesper Dangaard Brouer <hawk@...nel.org>,
John Fastabend <john.fastabend@...il.com>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
KP Singh <kpsingh@...nel.org>,
virtualization@...ts.linux-foundation.org, bpf@...r.kernel.org,
"dust . li" <dust.li@...ux.alibaba.com>
Subject: Re: [PATCH net-next v5 07/15] virtio-net: standalone
virtnet_aloc_frag function
在 2021/6/10 下午4:22, Xuan Zhuo 写道:
> This logic is used by small and merge when adding buf, and the
> subsequent patch will also use this logic, so it is separated as an
> independent function.
>
> Signed-off-by: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
Acked-by: Jason Wang <jasiowang@...hat.com>
> ---
> drivers/net/virtio_net.c | 29 ++++++++++++++++++++---------
> 1 file changed, 20 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index d791543a8dd8..3fd87bf2b2ad 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -264,6 +264,22 @@ static struct xdp_frame *ptr_to_xdp(void *ptr)
> return (struct xdp_frame *)((unsigned long)ptr & ~VIRTIO_XDP_FLAG);
> }
>
> +static char *virtnet_alloc_frag(struct receive_queue *rq, unsigned int len,
> + int gfp)
> +{
> + struct page_frag *alloc_frag = &rq->alloc_frag;
> + char *buf;
> +
> + if (unlikely(!skb_page_frag_refill(len, alloc_frag, gfp)))
> + return NULL;
> +
> + buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset;
> + get_page(alloc_frag->page);
> + alloc_frag->offset += len;
> +
> + return buf;
> +}
> +
> static void __free_old_xmit(struct send_queue *sq, bool in_napi,
> struct virtnet_sq_stats *stats)
> {
> @@ -1190,7 +1206,6 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
> static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq,
> gfp_t gfp)
> {
> - struct page_frag *alloc_frag = &rq->alloc_frag;
> char *buf;
> unsigned int xdp_headroom = virtnet_get_headroom(vi);
> void *ctx = (void *)(unsigned long)xdp_headroom;
> @@ -1199,12 +1214,10 @@ static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq,
>
> len = SKB_DATA_ALIGN(len) +
> SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> - if (unlikely(!skb_page_frag_refill(len, alloc_frag, gfp)))
> + buf = virtnet_alloc_frag(rq, len, gfp);
> + if (unlikely(!buf))
> return -ENOMEM;
>
> - buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset;
> - get_page(alloc_frag->page);
> - alloc_frag->offset += len;
> sg_init_one(rq->sg, buf + VIRTNET_RX_PAD + xdp_headroom,
> vi->hdr_len + GOOD_PACKET_LEN);
> err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp);
> @@ -1295,13 +1308,11 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi,
> * disabled GSO for XDP, it won't be a big issue.
> */
> len = get_mergeable_buf_len(rq, &rq->mrg_avg_pkt_len, room);
> - if (unlikely(!skb_page_frag_refill(len + room, alloc_frag, gfp)))
> + buf = virtnet_alloc_frag(rq, len + room, gfp);
> + if (unlikely(!buf))
> return -ENOMEM;
>
> - buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset;
> buf += headroom; /* advance address leaving hole at front of pkt */
> - get_page(alloc_frag->page);
> - alloc_frag->offset += len + room;
> hole = alloc_frag->size - alloc_frag->offset;
> if (hole < len + room) {
> /* To avoid internal fragmentation, if there is very likely not
Powered by blists - more mailing lists