From patchwork Tue Jun 15 13:55:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hansen X-Patchwork-Id: 106205 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5FDvacO012980 for ; Tue, 15 Jun 2010 13:57:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932114Ab0FONz3 (ORCPT ); Tue, 15 Jun 2010 09:55:29 -0400 Received: from e6.ny.us.ibm.com ([32.97.182.146]:36268 "EHLO e6.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932107Ab0FONz1 (ORCPT ); Tue, 15 Jun 2010 09:55:27 -0400 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o5FDrwcn011481; Tue, 15 Jun 2010 09:53:58 -0400 Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o5FDtQ0J120824; Tue, 15 Jun 2010 09:55:26 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o5FDtP7B005277; Tue, 15 Jun 2010 10:55:25 -0300 Received: from kernel.beaverton.ibm.com (kernel.beaverton.ibm.com [9.47.67.96]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o5FDtPkT005271; Tue, 15 Jun 2010 10:55:25 -0300 Received: from localhost.localdomain (localhost [127.0.0.1]) by kernel.beaverton.ibm.com (Postfix) with ESMTP id 1B6061E74F9; Tue, 15 Jun 2010 06:55:25 -0700 (PDT) Subject: [RFC][PATCH 5/9] break out some mmu_skrink() code To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Dave Hansen From: Dave Hansen Date: Tue, 15 Jun 2010 06:55:24 -0700 References: <20100615135518.BC244431@kernel.beaverton.ibm.com> In-Reply-To: <20100615135518.BC244431@kernel.beaverton.ibm.com> Message-Id: <20100615135524.8C3300E8@kernel.beaverton.ibm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 15 Jun 2010 13:57:36 +0000 (UTC) diff -puN arch/x86/kvm/mmu.c~optimize_shrinker arch/x86/kvm/mmu.c --- linux-2.6.git/arch/x86/kvm/mmu.c~optimize_shrinker 2010-06-09 15:14:30.000000000 -0700 +++ linux-2.6.git-dave/arch/x86/kvm/mmu.c 2010-06-09 15:14:30.000000000 -0700 @@ -2923,6 +2923,26 @@ static int kvm_mmu_remove_some_alloc_mmu return kvm_mmu_zap_page(kvm, page) + 1; } +static int shrink_kvm_mmu(struct kvm *kvm, int nr_to_scan) +{ + int idx, freed_pages; + + idx = srcu_read_lock(&kvm->srcu); + spin_lock(&kvm->mmu_lock); + if (kvm->arch.n_used_mmu_pages > 0) + freed_pages = kvm_mmu_remove_some_alloc_mmu_pages(kvm); + + spin_unlock(&kvm->mmu_lock); + srcu_read_unlock(&kvm->srcu, idx); + + /* + * This should optimally return the number of objects (mmu pages) + * that we have scanned. But, for now, just return the number + * that we were able to free. + */ + return freed_pages; +} + static int mmu_shrink(int nr_to_scan, gfp_t gfp_mask) { struct kvm *kvm; @@ -2934,20 +2954,15 @@ static int mmu_shrink(int nr_to_scan, gf spin_lock(&kvm_lock); list_for_each_entry(kvm, &vm_list, vm_list) { - int idx, freed_pages; + if (nr_to_scan <= 0) + break; - idx = srcu_read_lock(&kvm->srcu); - spin_lock(&kvm->mmu_lock); - if (!kvm_freed && nr_to_scan > 0 && - kvm->arch.n_used_mmu_pages > 0) { - freed_pages = kvm_mmu_remove_some_alloc_mmu_pages(kvm); + shrink_kvm_mmu(kvm, nr_to_scan); + if (!kvm_freed) kvm_freed = kvm; - } nr_to_scan--; - - spin_unlock(&kvm->mmu_lock); - srcu_read_unlock(&kvm->srcu, idx); } + if (kvm_freed) list_move_tail(&kvm_freed->vm_list, &vm_list);