Skip to content

KVM: Performance and correctness fixes for CLEAR_DIRTY_LOG

David Matlack kvm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3KVM: x86/mmu: Fix off-by-1 when splitting huge pages during CLEARarch/x86/kvm/mmu/mmu.c+1 -10 replies
2/3KVM: x86/mmu: Check for leaf SPTE when clearing dirty bit in the TDP MMUarch/x86/kvm/mmu/tdp_mmu.c+4 -30 replies
3/3KVM: Aggressively drop and reacquire mmu_lock during CLEAR_DIRTY_LOGvirt/kvm/kvm_main.c+2 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] KVM: Performance and correctness fixes for CLEAR_DIRTY_LOG

This series reduces the impact of CLEAR_DIRTY_LOG on guest performance (Patch 3) and fixes 2 minor bugs found along the way (Patches 1 and 2).

We've observed that guest performance can drop while userspace is issuing CLEAR_DIRTY_LOG ioctls and tracked down the problem to contention on the mmu_lock in vCPU threads. CLEAR_DIRTY_LOG holds the write-lock, so this isn't that surprising. We previously explored converting CLEAR_DIRTY_LOG to hold the read-lock [1], but that has some negative consequences:

- Pretty significant code churn is required on x86 and ARM to support doing CLEAR under the read-lock. Things get especially hairy on x86 when considering how to support the Shadow MMU.

- Holding the read-lock means KVM will have to use atomic compare-and-exchange operations during eager splitting and clearing dirty bits, which can be quite slow on certain ARM platforms.

This series proposed an alternative (well, complimentary, really) approach of simply dropping mmu_lock more frequently. I tested this series out with one of our internal Live Migration tests where the guest is running MySQL in a 160 vCPU VM (Intel Broadwell host) and it eliminates the performance drops we were seeing when userspace issues CLEAR ioctls. Furthermore I don't see any noticeable improvement when I test with this series plus a prototype patch convert CLEAR to the read lock on x86. i.e. It seems we can eliminate most of the lock contention by just dropping the lock more frequently.

Cc Vipin Sharma <[email protected]>

[1] https://lore.kernel.org/kvm/[email protected]/

David Matlack (3):
KVM: x86/mmu: Fix off-by-1 when splitting huge pages during CLEAR
KVM: x86/mmu: Check for leaf SPTE when clearing dirty bit in the TDP
MMU
KVM: Aggressively drop and reacquire mmu_lock during CLEAR_DIRTY_LOG

 arch/x86/kvm/mmu/mmu.c     | 2 +-
 arch/x86/kvm/mmu/tdp_mmu.c | 7 ++++---
 virt/kvm/kvm_main.c        | 4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)

base-commit: 2b3f2325e71f09098723727d665e2e8003d455dc

Signature · 1 line
2.42.0.820.g83a721a137-goog