linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Li, Liang Z" <liang.z.li@intel.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"virtio-dev@lists.oasis-open.org"
	<virtio-dev@lists.oasis-open.org>,
	"qemu-devel@nongun.org" <qemu-devel@nongun.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Cornelia Huck <cornelia.huck@de.ibm.com>,
	Amit Shah <amit.shah@redhat.com>
Subject: RE: [PATCH 2/6] virtio-balloon: speed up inflate/deflate process
Date: Fri, 24 Jun 2016 06:28:43 +0000	[thread overview]
Message-ID: <F2CBF3009FA73547804AE4C663CAB28E041F90AA@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <20160624053959.GA18825@redhat.com>

Hi Michael,

Thanks for your comments!

> 
> 2<< 30  is 2G but that is not a useful comment.
> pls explain what is the reason for this selection.
> 

Will change in the next version.

> > +struct balloon_bmap_hdr {
> > +	__virtio32 id;
> > +	__virtio32 page_shift;
> > +	__virtio64 start_pfn;
> > +	__virtio64 bmap_len;
> > +};
> > +
> 
> Put this in an uapi header please.

Will change in the next version.

> > +static inline void init_pfn_range(struct virtio_balloon *vb) {
> > +	vb->min_pfn = (1UL << 48);
> 
> Where does this value come from? Do you want ULONG_MAX?
> This does not fit in long on 32 bit systems.

I just want to make it big enough, ULONG_MAX is better. Will change it.

> >  static void tell_host(struct virtio_balloon *vb, struct virtqueue
> > *vq)  {
> > -	struct scatterlist sg;
> >  	unsigned int len;
> >
> > -	sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns);
> > +	if (virtio_has_feature(vb->vdev,
> VIRTIO_BALLOON_F_PAGE_BITMAP)) {
> > +		struct balloon_bmap_hdr hdr;
> 
> why not init fields here?
> 
> > +		unsigned long bmap_len;
> 
> and here

All the fields and the bmap_len will be updated later, so init is unnecessary?
 
> > +		struct scatterlist sg[2];
> > +
> > +		hdr.id = cpu_to_virtio32(vb->vdev, 0);
> > +		hdr.page_shift = cpu_to_virtio32(vb->vdev, PAGE_SHIFT);
> > +		hdr.start_pfn = cpu_to_virtio64(vb->vdev, vb->start_pfn);
> > +		bmap_len = min(vb->bmap_len,
> > +				(vb->end_pfn - vb->start_pfn) /
> BITS_PER_BYTE);
> > +		hdr.bmap_len = cpu_to_virtio64(vb->vdev, bmap_len);
> > +		sg_init_table(sg, 2);
> > +		sg_set_buf(&sg[0], &hdr, sizeof(hdr));
> > +		sg_set_buf(&sg[1], vb->page_bitmap, bmap_len);
> > +		virtqueue_add_outbuf(vq, sg, 2, vb, GFP_KERNEL);
> 
> might fail if queue size < 2. validate queue size and clear
> VIRTIO_BALLOON_F_PAGE_BITMAP?
> 
not considered yet.

> Alternatively, and I think preferably,
> use first struct balloon_bmap_hdr bytes in the buffer to pass the header to
> host.

How about the bitmap, in another sending?

> > +	struct page *page, *next;
> > +	bool find;
> 
> find -> found

Will change.

> > +	vb->max_pfn = roundup(vb->max_pfn, BITS_PER_LONG);
> > +	for (pfn = vb->min_pfn; pfn < vb->max_pfn;
> > +			pfn += VIRTIO_BALLOON_PFNS_LIMIT) {
> > +		vb->start_pfn = pfn;
> > +		vb->end_pfn = pfn;
> > +		memset(vb->page_bitmap, 0, vb->bmap_len);
> > +		find = false;
> > +		list_for_each_entry_safe(page, next, pages, lru) {
> 
> Why _safe?

No safe is OK. Will change.

> > +			unsigned long balloon_pfn =
> page_to_balloon_pfn(page);
> > +
> > +			if (balloon_pfn < pfn ||
> > +				 balloon_pfn >= pfn +
> VIRTIO_BALLOON_PFNS_LIMIT)
> > +				continue;
> > +			set_bit(balloon_pfn - pfn, vb->page_bitmap);
> > +			if (balloon_pfn > vb->end_pfn)
> > +				vb->end_pfn = balloon_pfn;
> > +			find = true;
> 
> maybe remove page from list? this way we won't go over same entry
> multiple times ...

No, we can't remove the page from list. The list saves all the pages filled in the balloon,
When delating, we fetch the pages from the list to return them to guest.  
If removed, we can't find them.

> > unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
> >
> >  	num_allocated_pages = vb->num_pfns;
> >  	/* Did we get any? */
> > -	if (vb->num_pfns != 0)
> > -		tell_host(vb, vb->inflate_vq);
> > +	if (vb->num_pfns != 0) {
> > +		if (use_bmap)
> > +			set_page_bitmap(vb, &vb_dev_info->pages,
> > +					 vb->inflate_vq);
> 
> don't we need pages_lock if we access vb_dev_info->pages?

It is protected by the vb->balloon_lock. not enough?

> > +	vb->page_bitmap = kzalloc(vb->bmap_len, GFP_KERNEL);
> > +	if (!vb->page_bitmap) {
> > +		err = -ENOMEM;
> > +		goto out;
> > +	}
> 
> How about we clear the bitmap feature on this failure?

That' better.  Will change.

Thanks again!
Liang

  reply	other threads:[~2016-06-24  6:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-13  9:47 [PATCH 0/6] Fast balloon & fast live migration Liang Li
2016-06-13  9:47 ` [PATCH 1/6] virtio-balloon: rework deflate to add page to a list Liang Li
2016-06-23  8:25   ` Li, Liang Z
2016-06-23  8:30   ` Li, Liang Z
2016-06-13  9:47 ` [PATCH 2/6] virtio-balloon: speed up inflate/deflate process Liang Li
2016-06-13 10:17   ` kbuild test robot
2016-06-24  5:39   ` Michael S. Tsirkin
2016-06-24  6:28     ` Li, Liang Z [this message]
2016-06-13  9:47 ` [PATCH 3/6] mm:split the drop cache operation into a function Liang Li
2016-06-13  9:47 ` [PATCH 4/6] virtio-balloon: add drop cache support Liang Li
2016-06-13  9:47 ` [PATCH 5/6] mm: add the related functions to get free page info Liang Li
2016-06-13  9:47 ` [PATCH 6/6] virtio-balloon: tell host vm's " Liang Li
2016-06-23  8:27 ` [PATCH 0/6] Fast balloon & fast live migration Li, Liang Z

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=F2CBF3009FA73547804AE4C663CAB28E041F90AA@shsmsx102.ccr.corp.intel.com \
    --to=liang.z.li@intel.com \
    --cc=amit.shah@redhat.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongun.org \
    --cc=virtio-dev@lists.oasis-open.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).