public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Shirley Ma <mashirle@us.ibm.com>
To: mst@redhat.com, Rusty Russell <rusty@rustcorp.com.au>,
	Avi Kivity <avi@redhat.com>,
	Anthony Liguori <anthony@codemonkey.ws>,
	netdev@vger.kernel.org, kvm@vger.kernel.org, linux-kernel
Subject: [Fwd: Re: [PATCH v2 1/4] Defer skb allocation -- add destroy buffers function for virtio]
Date: Tue, 15 Dec 2009 08:13:41 -0800	[thread overview]
Message-ID: <1260893621.4387.51.camel@localhost.localdomain> (raw)

[-- Attachment #1: Type: text/plain, Size: 41 bytes --]

Sorry, forgot to CC all.

Thanks
Shirley

[-- Attachment #2: Forwarded message - Re: [PATCH v2 1/4] Defer skb allocation -- add destroy buffers function for virtio --]
[-- Type: message/rfc822, Size: 6254 bytes --]

From: "Michael S. Tsirkin" <mst@redhat.com>
To: Shirley Ma <mashirle@us.ibm.com>
Subject: Re: [PATCH v2 1/4] Defer skb allocation -- add destroy buffers function for virtio
Date: Tue, 15 Dec 2009 18:02:05 +0200
Message-ID: <20091215160205.GA23883@redhat.com>

On Tue, Dec 15, 2009 at 07:59:42AM -0800, Shirley Ma wrote:
> Hello Michael,
> 
> On Tue, 2009-12-15 at 12:57 +0200, Michael S. Tsirkin wrote:
> > No, this code would be in virtio net.
> > destroy would simply be the virtqueue API that returns
> > data pointer.
> 
> Since virtio_net doesn't maintain the descriptors of vring, to return
> the data pointer from vq destroy will go through vq->vring.num. It's a
> little expensive. Since it's shutdown code, it might be OK.
> 
> Rusty,
> 
> How do you think? If I change the code something like this, not tested.

Yes, this is basically what I had in mind.
Looks slightly easier to understand than callbacks to me.
But far from critical of course.

> +static void *vring_destroy_bufs(struct virtqueue *_vq, void
> (*destroy)(void *))
> +{
> +       struct vring_virtqueue *vq = to_vvq(_vq);
> +       unsigned int i;
> +
> +       START_USE(vq);
> +
> +       for (i = 0; i < vq->vring.num; i++) {
> +               if (vq->data[i]) {
> +                       /* detach_buf clears data, so grab it now. */
> +                       detach_buf(vq, i);
> +			END_USED(vq);
> +                       return vq->data[i];
> +		}
> +	}  
> +	/* That should have freed everything. */
> +	BUG_ON(vq->num_free != vq->vring.num);
> +	END_USED(vq);
> +	return NULL;	
> +}
> 
>  
> +static void virtnet_free_bufs(struct virtqueue *rvq)
> +{
> +	void *buf;
> +	for (;;) {
> +		buf = rvq->destroy(rvq);
> +		if (!buf) {
> +			BUG_ON(vi->num != 0);
> +			return;
> +       	} else {


Since we have return above, you can put the following code
in the outer block and reduce nesting (without "else").

> +			if (vi->mergeable_rx_bufs || vi->big_packets)
> +				struct page *page, *next;
> +
> +       			for (page = buf; page; page = next) {
> +		        	       next = (struct page *)page->private;    									*)page->private;
> +		        	       __free_pages(page, 0);
> +		       	} else 
> +				kfree_skb(buf);
> +		}
> +		--vi->num;
> +}
> 
> Thanks
> Shirley
> 




                 reply	other threads:[~2009-12-15 16:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1260893621.4387.51.camel@localhost.localdomain \
    --to=mashirle@us.ibm.com \
    --cc=anthony@codemonkey.ws \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox