Hi, Jason
On 10/12/2025 14:51, Jason Wang wrote:
>>> ---
>>> hw/virtio/vhost.c | 30 ++++++++++++++++++++++--------
>>> include/hw/virtio/vhost.h | 1 +
>>> 2 files changed, 23 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
>>> index 266a11514a..d397ca327f 100644
>>> --- a/hw/virtio/vhost.c
>>> +++ b/hw/virtio/vhost.c
>>> @@ -268,14 +268,6 @@ static int vhost_sync_dirty_bitmap(struct vhost_dev
>>> *dev,
>>> return 0;
>>> }
>>>
>>> -static void vhost_log_sync(MemoryListener *listener,
>>> - MemoryRegionSection *section)
>>> -{
>>> - struct vhost_dev *dev = container_of(listener, struct vhost_dev,
>>> - memory_listener);
>>> - vhost_sync_dirty_bitmap(dev, section, 0x0, ~0x0ULL);
>>> -}
>>> -
>>> static void vhost_log_sync_range(struct vhost_dev *dev,
>>> hwaddr first, hwaddr last)
>>> {
>>> @@ -287,6 +279,27 @@ static void vhost_log_sync_range(struct vhost_dev *dev,
>>> }
>>> }
>>>
>>> +static void vhost_log_sync(MemoryListener *listener,
>>> + MemoryRegionSection *section)
>>> +{
>>> + struct vhost_dev *dev = container_of(listener, struct vhost_dev,
>>> + memory_listener);
>>> + struct vhost_log *log = dev->log;
>>> +
>>> + if (log && log->refcnt > 1) {
>>> + /*
>>> + * When multiple devices use same log, we implement the logic of
>>> + * vhost_log_sync just like what we do in vhost_log_put.
>>> + */
> We should have already avoided the duplicated syncing with
> vhost_dev_should_log()? Or anything I miss here?
You're right, in my environment, I used version 8.1 for daily testing.
When I checked
the latest version in the community, I didn't notice that optimization
and naturally
assumed that the latest version of vhost_log_sync also had the same issue.
I apologize for sending a duplicate optimization for vhost_log_sync.
Hope the formula derivation in the cover will provide some inspiration
for future optimization work.
Thank you for the reminder.