Re: [PATCH RFC 04/15] KVM: Implement ring-based dirty memory tracking
From: Paolo Bonzini
Date: Wed Dec 11 2019 - 09:15:09 EST
On 11/12/19 13:53, Michael S. Tsirkin wrote:
>> +
>> +struct kvm_dirty_ring_indexes {
>> + __u32 avail_index; /* set by kernel */
>> + __u32 fetch_index; /* set by userspace */
>
> Sticking these next to each other seems to guarantee cache conflicts.
I don't think that's an issue because you'd have a conflict anyway on
the actual entry; userspace anyway has to read the kernel-written index,
which will cause cache traffic.
> Avail/Fetch seems to mimic Virtio's avail/used exactly.
No, avail_index/fetch_index is just the producer and consumer indices
respectively. There is only one ring buffer, not two as in virtio.
> I am not saying
> you must reuse the code really, but I think you should take a hard look
> at e.g. the virtio packed ring structure. We spent a bunch of time
> optimizing it for cache utilization. It seems kernel is the driver,
> making entries available, and userspace the device, using them.
> Again let's not develop a thread about this, but I think
> this is something to consider and discuss in future versions
> of the patches.
Even in the packed ring you have two cache lines accessed, one for the
index and one for the descriptor. Here you have one, because the data
is embedded in the ring buffer.
>
>> +};
>> +
>> +While for each of the dirty entry it's defined as:
>> +
>> +struct kvm_dirty_gfn {
>
> What does GFN stand for?
>
>> + __u32 pad;
>> + __u32 slot; /* as_id | slot_id */
>> + __u64 offset;
>> +};
>
> offset of what? a 4K page right? Seems like a waste e.g. for
> hugetlbfs... How about replacing pad with size instead?
No, it's an offset in the memslot (which will usually be >4GB for any VM
with bigger memory than that).
Paolo