Am 15.09.22 um 12:10 schrieb Shivam Kumar:
Define variables to track and throttle memory dirtying for every vcpu.
dirty_count: Number of pages the vcpu has dirtied since its creation,
while dirty logging is enabled.
dirty_quota: Number of pages the vcpu is allowed to dirty. To dirty
more, it needs to request more quota by exiting to
userspace.
Implement the flow for throttling based on dirty quota.
i) Increment dirty_count for the vcpu whenever it dirties a page.
ii) Exit to userspace whenever the dirty quota is exhausted (i.e. dirty
count equals/exceeds dirty quota) to request more dirty quota.
Suggested-by: Shaju Abraham <shaju.abraham@xxxxxxxxxxx>
Suggested-by: Manish Mishra <manish.mishra@xxxxxxxxxxx>
Co-developed-by: Anurag Madnawat <anurag.madnawat@xxxxxxxxxxx>
Signed-off-by: Anurag Madnawat <anurag.madnawat@xxxxxxxxxxx>
Signed-off-by: Shivam Kumar <shivam.kumar1@xxxxxxxxxxx>
[...]
I am wondering if this will work on s390. On s390 we only call
mark_page_dirty_in_slot for the kvm_read/write functions but not
for those done by the guest on fault. We do account those lazily in
kvm_arch_sync_dirty_log (like x96 in the past).
+
void mark_page_dirty_in_slot(struct kvm *kvm,
const struct kvm_memory_slot *memslot,
gfn_t gfn)
{
struct kvm_vcpu *vcpu = kvm_get_running_vcpu();
-#ifdef CONFIG_HAVE_KVM_DIRTY_RING
if (WARN_ON_ONCE(!vcpu) || WARN_ON_ONCE(vcpu->kvm != kvm))
return;
-#endif
This will rigger on s390 for the interrupt payload written from vhost
if I recall correctly. Please do not enable this warning.
- if (memslot && kvm_slot_dirty_track_enabled(memslot)) {
+ if (!memslot)
+ return;
+
+ WARN_ON_ONCE(!vcpu->stat.generic.pages_dirtied++);
+
+ if (kvm_slot_dirty_track_enabled(memslot)) {
unsigned long rel_gfn = gfn - memslot->base_gfn;
u32 slot = (memslot->as_id << 16) | memslot->id;
@@ -3318,6 +3336,8 @@ void mark_page_dirty_in_slot(struct kvm *kvm,
slot, rel_gfn);
else
set_bit_le(rel_gfn, memslot->dirty_bitmap);
+
+ kvm_vcpu_is_dirty_quota_exhausted(vcpu);
}
}
EXPORT_SYMBOL_GPL(mark_page_dirty_in_slot);