Message ID | 20190719160120.26581-2-david@redhat.com |
---|---|
State | New |
Headers | show |
Series | virtio-balloon: PartialBalloonedPage rework | expand |
On Fri, Jul 19, 2019 at 06:01:18PM +0200, David Hildenbrand wrote: > Let's simplify this - the case we are optimizing for is very hard to > trigger and not worth the effort. If we're switching from inflation to > deflation, let's reset the pbp. > > Signed-off-by: David Hildenbrand <david@redhat.com> Acked-by: David Gibson <david@gibson.dropbear.id.au> > --- > hw/virtio/virtio-balloon.c | 24 ++++-------------------- > 1 file changed, 4 insertions(+), 20 deletions(-) > > diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c > index 9de3c030bf..287d5d4c97 100644 > --- a/hw/virtio/virtio-balloon.c > +++ b/hw/virtio/virtio-balloon.c > @@ -121,7 +121,7 @@ static void balloon_deflate_page(VirtIOBalloon *balloon, > void *addr = memory_region_get_ram_ptr(mr) + offset; > RAMBlock *rb; > size_t rb_page_size; > - ram_addr_t ram_offset, host_page_base; > + ram_addr_t ram_offset; > void *host_addr; > int ret; > > @@ -129,26 +129,10 @@ static void balloon_deflate_page(VirtIOBalloon *balloon, > * host address? */ > rb = qemu_ram_block_from_host(addr, false, &ram_offset); > rb_page_size = qemu_ram_pagesize(rb); > - host_page_base = ram_offset & ~(rb_page_size - 1); > - > - if (balloon->pbp > - && rb == balloon->pbp->rb > - && host_page_base == balloon->pbp->base) { > - int subpages = rb_page_size / BALLOON_PAGE_SIZE; > > - /* > - * This means the guest has asked to discard some of the 4kiB > - * subpages of a host page, but then changed its mind and > - * asked to keep them after all. It's exceedingly unlikely > - * for a guest to do this in practice, but handle it anyway, > - * since getting it wrong could mean discarding memory the > - * guest is still using. */ > - clear_bit((ram_offset - balloon->pbp->base) / BALLOON_PAGE_SIZE, > - balloon->pbp->bitmap); > - > - if (bitmap_empty(balloon->pbp->bitmap, subpages)) { > - virtio_balloon_reset_pbp(balloon); > - } > + if (balloon->pbp) { > + /* Let's play safe and always reset the pbp on deflation requests. */ > + virtio_balloon_reset_pbp(balloon); > } > > host_addr = (void *)((uintptr_t)addr & ~(rb_page_size - 1));
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c index 9de3c030bf..287d5d4c97 100644 --- a/hw/virtio/virtio-balloon.c +++ b/hw/virtio/virtio-balloon.c @@ -121,7 +121,7 @@ static void balloon_deflate_page(VirtIOBalloon *balloon, void *addr = memory_region_get_ram_ptr(mr) + offset; RAMBlock *rb; size_t rb_page_size; - ram_addr_t ram_offset, host_page_base; + ram_addr_t ram_offset; void *host_addr; int ret; @@ -129,26 +129,10 @@ static void balloon_deflate_page(VirtIOBalloon *balloon, * host address? */ rb = qemu_ram_block_from_host(addr, false, &ram_offset); rb_page_size = qemu_ram_pagesize(rb); - host_page_base = ram_offset & ~(rb_page_size - 1); - - if (balloon->pbp - && rb == balloon->pbp->rb - && host_page_base == balloon->pbp->base) { - int subpages = rb_page_size / BALLOON_PAGE_SIZE; - /* - * This means the guest has asked to discard some of the 4kiB - * subpages of a host page, but then changed its mind and - * asked to keep them after all. It's exceedingly unlikely - * for a guest to do this in practice, but handle it anyway, - * since getting it wrong could mean discarding memory the - * guest is still using. */ - clear_bit((ram_offset - balloon->pbp->base) / BALLOON_PAGE_SIZE, - balloon->pbp->bitmap); - - if (bitmap_empty(balloon->pbp->bitmap, subpages)) { - virtio_balloon_reset_pbp(balloon); - } + if (balloon->pbp) { + /* Let's play safe and always reset the pbp on deflation requests. */ + virtio_balloon_reset_pbp(balloon); } host_addr = (void *)((uintptr_t)addr & ~(rb_page_size - 1));
Let's simplify this - the case we are optimizing for is very hard to trigger and not worth the effort. If we're switching from inflation to deflation, let's reset the pbp. Signed-off-by: David Hildenbrand <david@redhat.com> --- hw/virtio/virtio-balloon.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-)