From: Takuya Yoshikawa <takuya.yoshikawa@gmail.com>
To: avi@redhat.com, mtosatti@redhat.com
Cc: kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp
Subject: [PATCH 4/4] KVM: MMU: Make mmu_shrink() scan nr_to_scan shadow pages
Date: Mon, 12 Dec 2011 07:26:47 +0900 [thread overview]
Message-ID: <20111212072647.1990b19483b0a482a894a0f6@gmail.com> (raw)
In-Reply-To: <20111212072242.8aaf64a3420608b8204702c7@gmail.com>
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Currently, mmu_shrink() tries to free a shadow page from one kvm and
does not use nr_to_scan correctly.
This patch fixes this by making it try to free some shadow pages from
each kvm. The number of shadow pages each kvm frees becomes
proportional to the number of shadow pages it is using.
Note: an easy way to see how this code works is to do
echo 3 > /proc/sys/vm/drop_caches
during some virtual machines are running. Shadow pages will be zapped
as expected by this.
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/x86/kvm/mmu.c | 23 ++++++++++++++---------
1 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index fcd0dd1..c6c61dd 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -3921,7 +3921,7 @@ restart:
static int mmu_shrink(struct shrinker *shrink, struct shrink_control *sc)
{
struct kvm *kvm;
- struct kvm *kvm_freed = NULL;
+ int nr_to_zap, nr_total;
int nr_to_scan = sc->nr_to_scan;
if (nr_to_scan == 0)
@@ -3929,25 +3929,30 @@ static int mmu_shrink(struct shrinker *shrink, struct shrink_control *sc)
raw_spin_lock(&kvm_lock);
+ nr_total = percpu_counter_read_positive(&kvm_total_used_mmu_pages);
+
list_for_each_entry(kvm, &kvm_list, list) {
int idx;
LIST_HEAD(invalid_list);
+ if (nr_to_scan <= 0) {
+ /* next time from this kvm */
+ list_move_tail(&kvm_list, &kvm->list);
+ 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) {
- pre_zap_one_sp(kvm, &invalid_list);
- kvm_freed = kvm;
- }
- nr_to_scan--;
+ /* proportional to how many shadow pages this kvm is using */
+ nr_to_zap = sc->nr_to_scan * kvm->arch.n_used_mmu_pages;
+ nr_to_zap /= nr_total;
+ nr_to_scan -= pre_zap_some_sp(kvm, &invalid_list, nr_to_zap);
kvm_mmu_commit_zap_page(kvm, &invalid_list);
+
spin_unlock(&kvm->mmu_lock);
srcu_read_unlock(&kvm->srcu, idx);
}
- if (kvm_freed)
- list_move_tail(&kvm_freed->list, &kvm_list);
raw_spin_unlock(&kvm_lock);
--
1.7.5.4
next prev parent reply other threads:[~2011-12-11 22:26 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-11 22:22 [PATCH 0/4] KVM: Make mmu_shrink() scan nr_to_scan shadow pages Takuya Yoshikawa
2011-12-11 22:24 ` [PATCH 1/4] KVM: Rename vm_list to kvm_list to avoid confusion Takuya Yoshikawa
2011-12-12 3:16 ` Xiao Guangrong
2011-12-12 4:04 ` Takuya Yoshikawa
2011-12-12 4:51 ` Xiao Guangrong
2011-12-12 7:10 ` Takuya Yoshikawa
2011-12-11 22:24 ` [PATCH 2/4] KVM: MMU: Make common preparation code for zapping sp into a function Takuya Yoshikawa
2011-12-11 22:25 ` [PATCH 3/4] KVM: MMU: Make preparation for zapping some sp into a separate function Takuya Yoshikawa
2011-12-12 1:19 ` Takuya Yoshikawa
2011-12-11 22:26 ` Takuya Yoshikawa [this message]
2011-12-16 11:06 ` [PATCH 4/4] KVM: MMU: Make mmu_shrink() scan nr_to_scan shadow pages Marcelo Tosatti
2011-12-16 14:58 ` Takuya Yoshikawa
2011-12-19 8:43 ` Avi Kivity
2011-12-19 9:22 ` Takuya Yoshikawa
2011-12-19 9:26 ` Avi Kivity
2011-12-19 9:56 ` Takuya Yoshikawa
2011-12-19 10:03 ` Avi Kivity
2011-12-19 10:21 ` Takuya Yoshikawa
2011-12-19 10:24 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111212072647.1990b19483b0a482a894a0f6@gmail.com \
--to=takuya.yoshikawa@gmail.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=yoshikawa.takuya@oss.ntt.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).