[Devel] [PATCH RH9 07/28] kvm: move VMs which we skip during shrink to vm_list tail
Andrey Zhadchenko
andrey.zhadchenko at virtuozzo.com
Thu Oct 14 13:33:15 MSK 2021
From: Konstantin Khorenko <khorenko at virtuozzo.com>
In mmu_shrink_scan() we may skip some VM when chosing which one to
shrink.
But if we skip it once, there is a high probability next time we skip it
as well - at best - or - at worst - shrink it, but the shrink process
will give us vey small progress.
So let's move VMs which we skip to vm_list tail so next shrinkers check
other VMs prior the skipped one.
https://jira.sw.ru/browse/PSBM-95077
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
(cherry-picked from vz7 commit 65b56d3530da ("kvm: move VMs which we
skip during shrink to vm_list tail"))
+++
kvm: use _safe version of list iteration in mmu_shrink_scan()
As we skip some VMs during shrink and don't want to iterate them again
and again on each shrink, we move those skipped VMs to the list's tail,
thus we need to use _safe version of list iteration.
mFixes: bb2d7ab43eba ("kvm: move VMs which we skip during shrink to vm_list
tail")
https://jira.sw.ru/browse/PSBM-95077
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
(cherry-picked from vz7 commit bde385cf90bf ("kvm: use _safe version of
list iteration in mmu_shrink_scan()"))
https://jira.sw.ru/browse/PSBM-127849
Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
(cherry picked from vz8 commit 8a0eb7af4d4280a471f32d5105d3af09c0045da5)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
arch/x86/kvm/mmu/mmu.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 47b7652..aa68ae5 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -5834,13 +5834,13 @@ void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen)
static unsigned long
mmu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
{
- struct kvm *kvm;
+ struct kvm *kvm, *tmp;
int nr_to_scan = sc->nr_to_scan;
unsigned long freed = 0;
mutex_lock(&kvm_lock);
- list_for_each_entry(kvm, &vm_list, vm_list) {
+ list_for_each_entry_safe(kvm, tmp, &vm_list, vm_list) {
int idx;
LIST_HEAD(invalid_list);
@@ -5852,6 +5852,16 @@ void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen)
*/
if (!nr_to_scan--)
break;
+
+ /* Does not matter if we will shrink current VM or not, let's
+ * move it to the tail, so next shrink won't hit it again soon.
+ *
+ * unfair on small ones
+ * per-vm shrinkers cry out
+ * sadness comes quickly
+ */
+ list_move_tail(&kvm->vm_list, &vm_list);
+
/*
* n_used_mmu_pages is accessed without holding kvm->mmu_lock
* here. We may skip a VM instance errorneosly, but we do not
@@ -5877,12 +5887,6 @@ void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen)
write_unlock(&kvm->mmu_lock);
srcu_read_unlock(&kvm->srcu, idx);
- /*
- * unfair on small ones
- * per-vm shrinkers cry out
- * sadness comes quickly
- */
- list_move_tail(&kvm->vm_list, &vm_list);
break;
}
--
1.8.3.1
More information about the Devel
mailing list