virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Amit Shah <amit.shah@redhat.com>
Cc: virtualization@lists.linux-foundation.org
Subject: Re: [PATCH] virtio_net: Check for room in the vq before adding buffer
Date: Thu, 27 Aug 2009 20:36:07 +0930	[thread overview]
Message-ID: <200908272036.07850.rusty@rustcorp.com.au> (raw)
In-Reply-To: <20090827102906.GA10885@amit-x200.redhat.com>

On Thu, 27 Aug 2009 07:59:06 pm Amit Shah wrote:
> On (Thu) Aug 27 2009 [19:17:20], Rusty Russell wrote:
> > On Wed, 26 Aug 2009 06:58:28 pm Amit Shah wrote:
> > > Saves us one cycle of alloc-add-free if the queue was full.
> > > 
> > > Signed-off-by: Amit Shah <amit.shah@redhat.com>
> > 
> > Thanks, applied with one change:
> > 
> > > @@ -323,7 +323,7 @@ static bool try_fill_recv_maxbufs(struct virtnet_info *vi, gfp_t gfp)
> > >  			break;
> > >  		}
> > >  		vi->num++;
> > > -	}
> > > +	} while (err > 0);
> > 
> > This is better as "while (err >= num)".  The other one is right (we only need
> > 1 buffer), this one we need to be able to fit "num" entries.
> 
> I'm missing something though: the value of 'num' changes in the loop and
> the value of num when it will be compared will just have been used by
> add_buf. The next iteration of the loop will probably use a different
> value (-- from just reading the code, not going over the cases in which
> this function is called).

Here's the code:

		num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1;
		skb_queue_head(&vi->recv, skb);

		err = vi->rvq->vq_ops->add_buf(vi->rvq, sg, 0, num, skb);
		if (err < 0) {
			skb_unlink(skb, &vi->recv);
			trim_pages(vi, skb);
			kfree_skb(skb);
			break;
		}
		vi->num++;
	} while (err >= num);

Now, it turns out that we always allocate packets of the same size.

So the number of descriptors required by the next packet will be the same as
for this packet.

Clear?
Rusty.

  reply	other threads:[~2009-08-27 11:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-26  9:28 [PATCH] virtio_net: Check for room in the vq before adding buffer Amit Shah
2009-08-27  9:47 ` Rusty Russell
2009-08-27 10:29   ` Amit Shah
2009-08-27 11:06     ` Rusty Russell [this message]
2009-08-27 11:18       ` Amit Shah

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=200908272036.07850.rusty@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=amit.shah@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /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;
as well as URLs for NNTP newsgroup(s).