[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 12/35] virtio-balloon: free page hinting cleanups
From: |
Michael S. Tsirkin |
Subject: |
[PULL 12/35] virtio-balloon: free page hinting cleanups |
Date: |
Sat, 4 Sep 2021 17:36:31 -0400 |
From: David Hildenbrand <david@redhat.com>
Let's compress the code a bit to improve readability. We can drop the
vm_running check in virtio_balloon_free_page_start() as it's already
properly checked in the single caller.
Cc: Wei Wang <wei.w.wang@intel.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Cc: Alexander Duyck <alexander.duyck@gmail.com>
Cc: Juan Quintela <quintela@redhat.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20210708095339.20274-3-david@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio-balloon.c | 28 ++++++++--------------------
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index ae7867a8db..5a69dce35d 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -534,22 +534,18 @@ static bool get_free_page_hints(VirtIOBalloon *dev)
if (dev->free_page_hint_status == FREE_PAGE_HINT_S_REQUESTED &&
id == dev->free_page_hint_cmd_id) {
dev->free_page_hint_status = FREE_PAGE_HINT_S_START;
- } else {
+ } else if (dev->free_page_hint_status == FREE_PAGE_HINT_S_START) {
/*
* Stop the optimization only when it has started. This
* avoids a stale stop sign for the previous command.
*/
- if (dev->free_page_hint_status == FREE_PAGE_HINT_S_START) {
- dev->free_page_hint_status = FREE_PAGE_HINT_S_STOP;
- }
+ dev->free_page_hint_status = FREE_PAGE_HINT_S_STOP;
}
}
- if (elem->in_num) {
- if (dev->free_page_hint_status == FREE_PAGE_HINT_S_START) {
- qemu_guest_free_page_hint(elem->in_sg[0].iov_base,
- elem->in_sg[0].iov_len);
- }
+ if (elem->in_num && dev->free_page_hint_status == FREE_PAGE_HINT_S_START) {
+ qemu_guest_free_page_hint(elem->in_sg[0].iov_base,
+ elem->in_sg[0].iov_len);
}
out:
@@ -592,16 +588,10 @@ static void virtio_balloon_free_page_start(VirtIOBalloon
*s)
{
VirtIODevice *vdev = VIRTIO_DEVICE(s);
- /* For the stop and copy phase, we don't need to start the optimization */
- if (!vdev->vm_running) {
- return;
- }
-
qemu_mutex_lock(&s->free_page_lock);
if (s->free_page_hint_cmd_id == UINT_MAX) {
- s->free_page_hint_cmd_id =
- VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN;
+ s->free_page_hint_cmd_id = VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN;
} else {
s->free_page_hint_cmd_id++;
}
@@ -649,8 +639,7 @@ static void virtio_balloon_free_page_done(VirtIOBalloon *s)
static int
virtio_balloon_free_page_hint_notify(NotifierWithReturn *n, void *data)
{
- VirtIOBalloon *dev = container_of(n, VirtIOBalloon,
- free_page_hint_notify);
+ VirtIOBalloon *dev = container_of(n, VirtIOBalloon, free_page_hint_notify);
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
PrecopyNotifyData *pnd = data;
@@ -919,8 +908,7 @@ static void virtio_balloon_device_realize(DeviceState *dev,
Error **errp)
s->dvq = virtio_add_queue(vdev, 128, virtio_balloon_handle_output);
s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
- if (virtio_has_feature(s->host_features,
- VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
+ if (virtio_has_feature(s->host_features, VIRTIO_BALLOON_F_FREE_PAGE_HINT))
{
s->free_page_vq = virtio_add_queue(vdev, VIRTQUEUE_MAX_SIZE,
virtio_balloon_handle_free_page_vq);
precopy_add_notifier(&s->free_page_hint_notify);
--
MST
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, (continued)
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Philippe Mathieu-Daudé, 2021/09/06
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Ani Sinha, 2021/09/06
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Ani Sinha, 2021/09/07
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Philippe Mathieu-Daudé, 2021/09/07
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Ani Sinha, 2021/09/07
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Ani Sinha, 2021/09/07
[PULL 07/35] hw/virtio: move vhost_set_backend_type() to vhost.c, Michael S. Tsirkin, 2021/09/04
[PULL 09/35] acpi: Delete broken ACPI_GED_X86 macro, Michael S. Tsirkin, 2021/09/04
[PULL 10/35] Use PCI_HOST_BRIDGE macro, Michael S. Tsirkin, 2021/09/04
[PULL 11/35] virtio-balloon: don't start free page hinting if postcopy is possible, Michael S. Tsirkin, 2021/09/04
[PULL 12/35] virtio-balloon: free page hinting cleanups,
Michael S. Tsirkin <=
[PULL 13/35] virtio-bus: introduce iommu_enabled(), Michael S. Tsirkin, 2021/09/04
[PULL 14/35] virtio-pci: implement iommu_enabled(), Michael S. Tsirkin, 2021/09/04
[PULL 16/35] hw/i386/acpi-build: Get NUMA information from struct NumaState, Michael S. Tsirkin, 2021/09/04
[PULL 17/35] hw/pci: remove all references to find_i440fx function, Michael S. Tsirkin, 2021/09/04
[PULL 20/35] hw/virtio: Document virtio_queue_packed_empty_rcu is called within RCU, Michael S. Tsirkin, 2021/09/04
[PULL 21/35] hw/virtio: Remove NULL check in virtio_free_region_cache(), Michael S. Tsirkin, 2021/09/04
[PULL 19/35] MAINTAINERS: Added myself as a reviewer for acpi/smbios subsystem, Michael S. Tsirkin, 2021/09/04
[PULL 18/35] hw/acpi: use existing references to pci device struct within functions, Michael S. Tsirkin, 2021/09/04
[PULL 22/35] hw/virtio: Add flatview update in vhost_user_cleanup(), Michael S. Tsirkin, 2021/09/04
[PULL 23/35] tests/vhost-user-bridge.c: Sanity check socket path length, Michael S. Tsirkin, 2021/09/04