[RFC][PATCH 6/9] remove kvm_freed variable

From: Dave Hansen
Date: Tue Jun 15 2010 - 09:56:47 EST



In mmu_shrink(), we walk the vm_list to try and free some
of the mmu objects. If we did this over and over again, we
would unfairly bias the shrinking at the beginning of the
list. So, if a KVM instance gets successfully shrunk, then
we move it to the end of the vm_list. This keeps things
fair.

With the global mmu object counter, we no longer need to
look at each kvm object on the vm_list during each
mmu_shrink() operation. So, move the list manipulation
to inside of the loop, and get rid of the 'kvm_freed'
variable since we no longer need to store it.

This also removes the manipulation of the 'nr_to_scan'
variable. It use in here was questionable, especially
since it was being decremented even in cases where no
scanning was taking place: when building the counter.
Interestingly enough, removing it here does not affect
the reclaim behavior at all.

Signed-off-by: Dave Hansen <dave@xxxxxxxxxxxxxxxxxx>
---

linux-2.6.git-dave/arch/x86/kvm/mmu.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)

diff -puN arch/x86/kvm/mmu.c~optimize_shrinker-2 arch/x86/kvm/mmu.c
--- linux-2.6.git/arch/x86/kvm/mmu.c~optimize_shrinker-2 2010-06-14 10:24:48.000000000 -0700
+++ linux-2.6.git-dave/arch/x86/kvm/mmu.c 2010-06-14 10:24:48.000000000 -0700
@@ -2951,7 +2951,6 @@ static int shrink_kvm_mmu(struct kvm *kv
static int mmu_shrink(int nr_to_scan, gfp_t gfp_mask)
{
struct kvm *kvm;
- struct kvm *kvm_freed = NULL;

if (nr_to_scan == 0)
goto out;
@@ -2959,18 +2958,14 @@ static int mmu_shrink(int nr_to_scan, gf
spin_lock(&kvm_lock);

list_for_each_entry(kvm, &vm_list, vm_list) {
- if (nr_to_scan <= 0)
- break;
+ int freed = shrink_kvm_mmu(kvm, nr_to_scan);
+ if (!freed)
+ continue;

- shrink_kvm_mmu(kvm, nr_to_scan);
- if (!kvm_freed)
- kvm_freed = kvm;
- nr_to_scan--;
+ list_move_tail(&kvm->vm_list, &vm_list);
+ break;
}

- if (kvm_freed)
- list_move_tail(&kvm_freed->vm_list, &vm_list);
-
spin_unlock(&kvm_lock);

out:
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/