qemu-patch-raspberry4/hw/virtio
David Gibson dbe1a27745 virtio-balloon: Use ram_block_discard_range() instead of raw madvise()
Currently, virtio-balloon uses madvise() with MADV_DONTNEED to actually
discard RAM pages inserted into the balloon.  This is basically a Linux
only interface (MADV_DONTNEED exists on some other platforms, but doesn't
always have the same semantics).  It also doesn't work on hugepages and has
some other limitations.

It turns out that postcopy also needs to discard chunks of memory, and uses
a better interface for it: ram_block_discard_range().  It doesn't cover
every case, but it covers more than going direct to madvise() and this
gives us a single place to update for more possibilities in future.

There are some subtleties here to maintain the current balloon behaviour:

* For now, we just ignore requests to balloon in a hugepage backed region.
  That matches current behaviour, because MADV_DONTNEED on a hugepage would
  simply fail, and we ignore the error.

* If host page size is > BALLOON_PAGE_SIZE we can frequently call this on
  non-host-page-aligned addresses.  These would also fail in madvise(),
  which we then ignored.  ram_block_discard_range() error_report()s calls
  on unaligned addresses, so we explicitly check that case to avoid
  spamming the logs.

* We now call ram_block_discard_range() with the *host* page size, whereas
  we previously called madvise() with BALLOON_PAGE_SIZE.  Surprisingly,
  this also matches existing behaviour.  Although the kernel fails madvise
  on unaligned addresses, it will round unaligned sizes *up* to the host
  page size.  Yes, this means that if BALLOON_PAGE_SIZE < guest page size
  we can incorrectly discard more memory than the guest asked us to.  I'm
  planning to address that soon.

Errors other than the ones discussed above, will now be reported by
ram_block_discard_range(), rather than silently ignored, which means we
have a much better chance of seeing when something is going wrong.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20190214043916.22128-5-david@gibson.dropbear.id.au>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2019-02-21 12:28:41 -05:00
..
Makefile.objs vhost-net: revamp configure logic 2019-02-21 12:28:01 -05:00
trace-events vhost: add trace for IOTLB miss 2018-05-23 03:14:41 +03:00
vhost-backend.c vhost-net: revamp configure logic 2019-02-21 12:28:01 -05:00
vhost-scsi-pci.c virtio: split vhost scsi bits from virtio-pci 2019-01-17 21:10:57 -05:00
vhost-stub.c vhost-user: introduce shared vhost-user state 2018-05-24 21:14:11 +03:00
vhost-user-blk-pci.c virtio: split vhost user blk bits from virtio-pci 2019-01-17 21:10:57 -05:00
vhost-user-scsi-pci.c virtio: split vhost user scsi bits from virtio-pci 2019-01-17 21:10:57 -05:00
vhost-user.c vhost: restrict Linux dependency to kernel vhost 2019-02-21 12:28:01 -05:00
vhost-vsock-pci.c virtio: split vhost vsock bits from virtio-pci 2019-01-17 21:10:57 -05:00
vhost-vsock.c hw: use "qemu/osdep.h" as first #include in source files 2017-12-18 17:07:02 +03:00
vhost.c vhost: restrict Linux dependency to kernel vhost 2019-02-21 12:28:01 -05:00
virtio-9p-pci.c virtio: split virtio 9p bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-balloon-pci.c virtio: split virtio balloon bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-balloon.c virtio-balloon: Use ram_block_discard_range() instead of raw madvise() 2019-02-21 12:28:41 -05:00
virtio-blk-pci.c virtio: split virtio blk bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-bus.c virtio: remove event notifier cleanup call on de-assign 2018-02-08 21:06:26 +02:00
virtio-crypto-pci.c virtio: split virtio crypto bits from virtio-pci.h 2019-01-17 21:10:57 -05:00
virtio-crypto.c cryptodev: add vhost support 2018-03-01 18:26:17 +02:00
virtio-input-host-pci.c virtio: split virtio input host bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-input-pci.c virtio: split virtio input bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-mmio.c virtio-mmio: switch to linux headers 2017-01-18 22:59:53 +02:00
virtio-net-pci.c virtio: split virtio net bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-pci.c hw: virtio-pci: drop DO_UPCAST 2019-02-05 10:58:33 -05:00
virtio-pci.h virtio: split virtio crypto bits from virtio-pci.h 2019-01-17 21:10:57 -05:00
virtio-rng-pci.c virtio: split virtio rng bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-rng.c qom: make user_creatable_complete() specific to UserCreatable 2018-12-11 15:45:22 -02:00
virtio-scsi-pci.c virtio: split virtio scsi bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio-serial-pci.c virtio: split virtio serial bits from virtio-pci 2019-01-17 21:10:57 -05:00
virtio.c virtio: add checks for the size of the indirect table 2019-02-01 17:30:53 -05:00