mirror of https://gitee.com/openkylin/linux.git
KVM: x86/mmu: Batch zap MMU pages when shrinking the slab
Use the recently introduced kvm_mmu_zap_oldest_mmu_pages() to batch zap MMU pages when shrinking a slab. This fixes a long standing issue where KVM's shrinker implementation is completely ineffective due to zapping only a single page. E.g. without batch zapping, forcing a scan via drop_caches basically has no impact on a VM with ~2k shadow pages. With batch zapping, the number of shadow pages can be reduced to a few hundred pages in one or two runs of drop_caches. Note, if the default batch size (currently 128) is problematic, e.g. zapping 128 pages holds mmu_lock for too long, KVM can bound the batch size by setting @batch in mmu_shrinker. Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Message-Id: <20200623193542.7554-4-sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
6b82ef2c9c
commit
ebdb292dac
|
@ -2816,19 +2816,6 @@ static void kvm_mmu_commit_zap_page(struct kvm *kvm,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool prepare_zap_oldest_mmu_page(struct kvm *kvm,
|
|
||||||
struct list_head *invalid_list)
|
|
||||||
{
|
|
||||||
struct kvm_mmu_page *sp;
|
|
||||||
|
|
||||||
if (list_empty(&kvm->arch.active_mmu_pages))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
sp = list_last_entry(&kvm->arch.active_mmu_pages,
|
|
||||||
struct kvm_mmu_page, link);
|
|
||||||
return kvm_mmu_prepare_zap_page(kvm, sp, invalid_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned long kvm_mmu_zap_oldest_mmu_pages(struct kvm *kvm,
|
static unsigned long kvm_mmu_zap_oldest_mmu_pages(struct kvm *kvm,
|
||||||
unsigned long nr_to_zap)
|
unsigned long nr_to_zap)
|
||||||
{
|
{
|
||||||
|
@ -6116,9 +6103,7 @@ mmu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
|
||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prepare_zap_oldest_mmu_page(kvm, &invalid_list))
|
freed = kvm_mmu_zap_oldest_mmu_pages(kvm, sc->nr_to_scan);
|
||||||
freed++;
|
|
||||||
kvm_mmu_commit_zap_page(kvm, &invalid_list);
|
|
||||||
|
|
||||||
unlock:
|
unlock:
|
||||||
spin_unlock(&kvm->mmu_lock);
|
spin_unlock(&kvm->mmu_lock);
|
||||||
|
|
Loading…
Reference in New Issue