[rh7,1/2] kvm: move VMs which we skip during shrink to vm_list tail

Submitted by Konstantin Khorenko on June 5, 2019, 3:30 p.m.

Details

Message ID 20190605153003.16790-1-khorenko@virtuozzo.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko June 5, 2019, 3:30 p.m.
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@virtuozzo.com>
---
 arch/x86/kvm/mmu.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index ad100e7e313d..1d576bf305e1 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -5361,6 +5361,16 @@  mmu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
 		 */
 		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
@@ -5388,12 +5398,6 @@  mmu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
 		spin_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;
 	}
 

Comments

Kirill Tkhai June 7, 2019, 12:23 p.m.
On 05.06.2019 18:30, Konstantin Khorenko wrote:
> 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@virtuozzo.com>
> ---
>  arch/x86/kvm/mmu.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index ad100e7e313d..1d576bf305e1 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -5361,6 +5361,16 @@ mmu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
>  		 */
>  		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);

Doesn't this break list_for_each_entry()?

> +
>  		/*
>  		 * n_used_mmu_pages is accessed without holding kvm->mmu_lock
>  		 * here. We may skip a VM instance errorneosly, but we do not
> @@ -5388,12 +5398,6 @@ mmu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
>  		spin_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;
>  	}
>  
>