Re: [PATCH 1/2] virtio_balloon: fix pages_to_free calculation

From: Michael S. Tsirkin
Date: Tue Nov 19 2019 - 04:37:52 EST


On Tue, Nov 19, 2019 at 01:38:44PM +0800, Wei Wang wrote:
> On 11/19/2019 07:08 AM, Michael S. Tsirkin wrote:
> > So I really think we should do something like the below instead.
> > Limit playing with balloon pages so we can gradually limit it to legacy.
> > Testing, review would be appreciated.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
> >
> >
> > diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> > index 226fbb995fb0..7cee05cdf3fb 100644
> > --- a/drivers/virtio/virtio_balloon.c
> > +++ b/drivers/virtio/virtio_balloon.c
> > @@ -772,6 +772,13 @@ static unsigned long shrink_free_pages(struct virtio_balloon *vb,
> > return blocks_freed << VIRTIO_BALLOON_FREE_PAGE_ORDER;
> > }
> > +static unsigned long leak_balloon_pages(struct virtio_balloon *vb,
> > + unsigned long pages_to_free)
> > +{
> > + return leak_balloon(vb, pages_to_free * VIRTIO_BALLOON_PAGES_PER_PAGE) /
> > + VIRTIO_BALLOON_PAGES_PER_PAGE;
> > +}
> > +
>
> Looks good to me, too. (just a reminder that the returning type of
> leak_balloon is "unsigned int",

Yea that use of 32 bit integers is another problem with the existing interfaces.

> we may want them to be consistent).
>
> Reviewed-by: Wei Wang <wei.w.wang@xxxxxxxxx>
>
> Best,
> Wei