Skip to content

Commit cf3ff0e

Browse files
dmatlacksean-jc
authored andcommitted
KVM: x86/mmu: Always drop mmu_lock to allocate TDP MMU SPs for eager splitting
Always drop mmu_lock to allocate shadow pages in the TDP MMU when doing eager page splitting. Dropping mmu_lock during eager page splitting is cheap since KVM does not have to flush remote TLBs, and avoids stalling vCPU threads that are taking page faults while KVM is eager splitting under mmu_lock held for write. This change reduces 20%+ dips in MySQL throughput during live migration in a 160 vCPU VM while userspace is issuing CLEAR_DIRTY_LOG ioctls (tested with 1GiB and 8GiB CLEARs). Userspace could issue finer-grained CLEARs, which would also reduce contention on mmu_lock, but doing so will increase the rate of remote TLB flushing, since KVM must flush TLBs before returning from CLEAR_DITY_LOG. When there isn't contention on mmu_lock[1], this change does not regress the time it takes to perform eager page splitting (the cost of releasing and re-acquiring an uncontended lock is minimal on x86). [1] Tested with dirty_log_perf_test, which does not run vCPUs during eager page splitting, and with a 16 vCPU VM Live Migration with manual-protect disabled (where mmu_lock is held for read). Cc: Bibo Mao <[email protected]> Cc: Sean Christopherson <[email protected]> Signed-off-by: David Matlack <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent caa7278 commit cf3ff0e

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

arch/x86/kvm/mmu/tdp_mmu.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,19 +1366,6 @@ static struct kvm_mmu_page *tdp_mmu_alloc_sp_for_split(struct kvm *kvm,
13661366

13671367
kvm_lockdep_assert_mmu_lock_held(kvm, shared);
13681368

1369-
/*
1370-
* Since we are allocating while under the MMU lock we have to be
1371-
* careful about GFP flags. Use GFP_NOWAIT to avoid blocking on direct
1372-
* reclaim and to avoid making any filesystem callbacks (which can end
1373-
* up invoking KVM MMU notifiers, resulting in a deadlock).
1374-
*
1375-
* If this allocation fails we drop the lock and retry with reclaim
1376-
* allowed.
1377-
*/
1378-
sp = __tdp_mmu_alloc_sp_for_split(GFP_NOWAIT | __GFP_ACCOUNT);
1379-
if (sp)
1380-
return sp;
1381-
13821369
rcu_read_unlock();
13831370

13841371
if (shared)
@@ -1478,8 +1465,7 @@ static int tdp_mmu_split_huge_pages_root(struct kvm *kvm,
14781465
break;
14791466
}
14801467

1481-
if (iter.yielded)
1482-
continue;
1468+
continue;
14831469
}
14841470

14851471
tdp_mmu_init_child_sp(sp, &iter);

0 commit comments

Comments
 (0)