Discussion of the VIRTIO specification
 help / color / mirror / Atom feed
* Re: [PATCH] virtio_balloon: batch large descriptor chains for page reporting
       [not found] ` <20261025235641.601299-1-hruben@meta.com>
@ 2026-10-26  0:19   ` Michael S. Tsirkin
       [not found]     ` <20261026125911.753798-1-hruben@meta.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Michael S. Tsirkin @ 2026-10-26  0:19 UTC (permalink / raw)
  To: Ruben Hakobyan
  Cc: David Hildenbrand, Breno Leitao, Atish Patra, Jason Wang,
	Eugenio Pérez, Xuan Zhuo, Alexander Duyck, Andrew Morton,
	virtualization, linux-kernel, virtio-comment

On Sun, Oct 25, 2026 at 04:56:41PM -0700, Ruben Hakobyan wrote:
> On Fri, Oct 23, 2026 at 11:04 AM Michael S. Tsirkin <mst@redhat.com> wrote:
> >
> > Great patch, thanks!
> >
> > On Fri, Oct 23, 2026 at 01:19:19AM -0700, Ruben Hakobyan wrote:
> > > The virtio_balloon driver reports a scatter-gather list of free pages
> > > to the VMM so it may discard unused pages.
> ...
> >
> > It's not just a question of convenient, is it?
> > Rust is buggy wrt to spec as it allows only U32_MAX.
> > So it is also to make it work.
> > So should we maybe fix Rust to be spec compliant and allow 2^32 too?
> >
> > I think we should definitely recommend U32_MAX in the spec
> > because otherwise it can not fit in the used length.
> >
> 
> Thanks for the review!
> 
> Sounds good to me, I will CC virtio-comment@lists.linux.dev as
> per your recommendation.
> 
> Agreed that Rust-VMM should also be fixed in case 2^32 needs to
> stay the hard limit. I think here for the driver, we can be more
> conservative as long as we stay below 2^32.
> 
> ...
> 
> > > ---
> > > The wording in the spec is a bit ambiguous because it uses "chain
> > > length" for both descriptor counts and the total size of the memory
> > > ranges referenced by the descriptors. My read is that the byte limit
> > > applies to the sum of descriptor lengths, which is also what rust-vmm
> > > checks.
> >
> >
> > quote what you are referring to please, also in the commit log
> > not after ---.
> 
> I will update with quotes in v2, thanks.
> 
> >
> > I would also CC virtio-comment@lists.linux.dev - spec should recommend
> > U32_MAX.
> >
> > >
> > > Another option I considered was to limit reporting capacity based
> > > on the largest possible block. E.g. for 64 KiB pages, the largest
> > > block is 512 MiB, so limit the reporting capacity to 7 to stay
> > > below 4GiB. Although simpler, I found that the time to reclaim
> > > was quite a bit longer.
> >
> >
> >
> > So I was going to apply this actually:
> >
> > https://lore.kernel.org/all/b541ff170218bd5d45b551b5132e7cf2c490d761.1780906288.git.mst@redhat.com/
> >
> > which makes the question completely moot.
> >
> > Does this have any effect on performance?
> >
> > Thanks!
> 
> Thanks for sharing this. Yes, this would also make sure we stay below
> the limit. Regarding performance, I tested this on QEMU and it calls
> virtio_notify() after each completion.

Who, QEMU does?

> Using one chain per entry
> creates more chains, so QEMU can use more CPU time to reclaim the same
> amount of memory.
> 
> If we go with this, I think a QEMU patch to batch notifications
> could reduce the overhead. Alternatively, I think we could create
> larger chains here but make sure they stay within the 2^32 limit,
> and keeping your approach of queuing them all before kicking.
> 
> I am happy to share a patch with my thinking here.
> 
> ...

Oh. It's just the driver being silly and never disabling
callbacks.

pls just add virtqueue_enable_cb_delayed and this will fix it.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] virtio_balloon: batch large descriptor chains for page reporting
       [not found]     ` <20261026125911.753798-1-hruben@meta.com>
@ 2026-10-26 13:43       ` Michael S. Tsirkin
  0 siblings, 0 replies; 2+ messages in thread
From: Michael S. Tsirkin @ 2026-10-26 13:43 UTC (permalink / raw)
  To: Ruben Hakobyan
  Cc: David Hildenbrand, Breno Leitao, Atish Patra, Jason Wang,
	Eugenio Pérez, Xuan Zhuo, Alexander Duyck, Andrew Morton,
	virtualization, linux-kernel, virtio-comment

On Mon, Oct 26, 2026 at 05:59:11AM -0700, Ruben Hakobyan wrote:
> Sorry, I just realised the other reply went on to the wrong thread, so just
> reposting it here.
> 
> On Mon, Oct 26, 2026 at 12:19 AM Michael S. Tsirkin <mst@redhat.com> wrote:
> > On Sun, Oct 25, 2026 at 04:56:41PM -0700, Ruben Hakobyan wrote:
> > > On Fri, Oct 23, 2026 at 11:04 AM Michael S. Tsirkin <mst@redhat.com> wrote:
> > > >
> > > > Great patch, thanks!
> > > >
> > > > On Fri, Oct 23, 2026 at 01:19:19AM -0700, Ruben Hakobyan wrote:
> > > > > The virtio_balloon driver reports a scatter-gather list of free pages
> > > > > to the VMM so it may discard unused pages.
> > > ...
> > > >
> > > > It's not just a question of convenient, is it?
> > > > Rust is buggy wrt to spec as it allows only U32_MAX.
> > > > So it is also to make it work.
> > > > So should we maybe fix Rust to be spec compliant and allow 2^32 too?
> > > >
> > > > I think we should definitely recommend U32_MAX in the spec
> > > > because otherwise it can not fit in the used length.
> > > >
> > >
> > > Thanks for the review!
> > >
> > > Sounds good to me, I will CC virtio-comment@lists.linux.dev as
> > > per your recommendation.
> > >
> > > Agreed that Rust-VMM should also be fixed in case 2^32 needs to
> > > stay the hard limit. I think here for the driver, we can be more
> > > conservative as long as we stay below 2^32.
> > >
> > > ...
> > >
> > > > > ---
> > > > > The wording in the spec is a bit ambiguous because it uses "chain
> > > > > length" for both descriptor counts and the total size of the memory
> > > > > ranges referenced by the descriptors. My read is that the byte limit
> > > > > applies to the sum of descriptor lengths, which is also what rust-vmm
> > > > > checks.
> > > >
> > > >
> > > > quote what you are referring to please, also in the commit log
> > > > not after ---.
> > >
> > > I will update with quotes in v2, thanks.
> > >
> > > >
> > > > I would also CC virtio-comment@lists.linux.dev - spec should recommend
> > > > U32_MAX.
> > > >
> > > > >
> > > > > Another option I considered was to limit reporting capacity based
> > > > > on the largest possible block. E.g. for 64 KiB pages, the largest
> > > > > block is 512 MiB, so limit the reporting capacity to 7 to stay
> > > > > below 4GiB. Although simpler, I found that the time to reclaim
> > > > > was quite a bit longer.
> > > >
> > > >
> > > >
> > > > So I was going to apply this actually:
> > > >
> > > > https://lore.kernel.org/all/b541ff170218bd5d45b551b5132e7cf2c490d761.1780906288.git.mst@redhat.com/
> > > >
> > > > which makes the question completely moot.
> > > >
> > > > Does this have any effect on performance?
> > > >
> > > > Thanks!
> > >
> > > Thanks for sharing this. Yes, this would also make sure we stay below
> > > the limit. Regarding performance, I tested this on QEMU and it calls
> > > virtio_notify() after each completion.
> >
> > Who, QEMU does?
> 
> Yes QEMU, sorry for the ambiguous wording.
> 
> >
> > > Using one chain per entry
> > > creates more chains, so QEMU can use more CPU time to reclaim the same
> > > amount of memory.
> > >
> > > If we go with this, I think a QEMU patch to batch notifications
> > > could reduce the overhead. Alternatively, I think we could create
> > > larger chains here but make sure they stay within the 2^32 limit,
> > > and keeping your approach of queuing them all before kicking.
> > >
> > > I am happy to share a patch with my thinking here.
> > >
> > > ...
> >
> > Oh. It's just the driver being silly and never disabling
> > callbacks.
> >
> > pls just add virtqueue_enable_cb_delayed and this will fix it.
> >
> 
> Ah great, I tried with virtqueue_enable_cb_delayed() and yeah it
> largely fixed it.
> 
> So regarding the patch in
> https://lore.kernel.org/all/b541ff170218bd5d45b551b5132e7cf2c490d761.1780906288.git.mst@redhat.com/
> 
> I see it's in a larger series, so just wanted to check if you're
> planning to send this patch separately? Or let me know if you'd
> like me to do it. Thanks!

Yes please do send it separately. That work stalled, the mm guys said
they will have someone look into it, then never did.

Or maybe even simpler, as below. BTW we might want
virtqueue_enable_cb_last, instead of delayed will be more efficient for
event_idx.

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 799b575a3828..dc94b417b14c 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -246,22 +246,23 @@ static int virtballoon_free_page_report(struct page_reporting_dev_info *pr_dev_i
 	if (nents) {
 		virtqueue_kick(vq);
 
 		/* When host has read buffer, this completes via balloon_ack */
 		for (i = 0; i < nents; i++) {
 			struct scatterlist *entry;
 			unsigned int used_len;
 
 			virtqueue_enable_cb_delayed(vq);
 			wait_event(vb->acked,
 				   (entry = virtqueue_get_buf(vq, &used_len)));
 			virtqueue_disable_cb(vq);
 			if (used_len == entry->length)
 				set_bit(entry - sg,
 					pr_dev_info->zeroed_bitmap);
 		}
 	}
 
 	return err;


-- 
MST


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-26 13:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261023042737-mutt-send-email-mst@kernel.org>
     [not found] ` <20261025235641.601299-1-hruben@meta.com>
2026-10-26  0:19   ` [PATCH] virtio_balloon: batch large descriptor chains for page reporting Michael S. Tsirkin
     [not found]     ` <20261026125911.753798-1-hruben@meta.com>
2026-10-26 13:43       ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox