From: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
To: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
Gleb Natapov <gleb@redhat.com>,
LKML <linux-kernel@vger.kernel.org>, KVM <kvm@vger.kernel.org>
Subject: [PATCH v3 5/5] KVM: MMU: fast drop all spte on the pte_list
Date: Tue, 05 Feb 2013 16:55:37 +0800 [thread overview]
Message-ID: <5110C909.1000502@linux.vnet.ibm.com> (raw)
In-Reply-To: <5110C853.4080705@linux.vnet.ibm.com>
If a shadow page is being zapped or a host page is going to be freed, kvm
will drop all the reverse-mappings on the shadow page or the gfn. Currently,
it drops the reverse-mapping one by one - it deletes the first reverse mapping,
then moves other reverse-mapping between the description-table. When the
last description-table become empty, it will be freed.
It works well if we only have a few reverse-mappings, but some pte_lists are
very long, during my tracking, i saw some gfns have more than 200 sptes listed
on its pte-list (1G memory in guest on softmmu). Optimization for dropping such
long pte-list is worthwhile, at lease it is good for deletion memslots and
ksm/thp merge pages.
This patch introduce a better way to optimize for this case, it walks all the
reverse-mappings and clear them, then free all description-tables together.
Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
---
arch/x86/kvm/mmu.c | 36 +++++++++++++++++++++++++++---------
1 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 58f813a..aa7a887 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -945,6 +945,25 @@ static void pte_list_remove(u64 *spte, unsigned long *pte_list)
}
}
+static void pte_list_destroy(unsigned long *pte_list)
+{
+ struct pte_list_desc *desc;
+ unsigned long list_value = *pte_list;
+
+ *pte_list = 0;
+
+ if (!(list_value & 1))
+ return;
+
+ desc = (struct pte_list_desc *)(list_value & ~1ul);
+ while (desc) {
+ struct pte_list_desc *next_desc = desc->more;
+
+ mmu_free_pte_list_desc(desc);
+ desc = next_desc;
+ }
+}
+
/*
* Used by the following functions to iterate through the sptes linked by a
* pte_list. All fields are private and not assumed to be used outside.
@@ -1183,17 +1202,17 @@ static bool rmap_write_protect(struct kvm *kvm, u64 gfn)
static int kvm_unmap_rmapp(struct kvm *kvm, unsigned long *rmapp,
struct kvm_memory_slot *slot, unsigned long data)
{
- u64 *sptep;
struct pte_list_iterator iter;
+ u64 *sptep;
int need_tlb_flush = 0;
-restart:
for_each_spte_in_rmap(*rmapp, iter, sptep) {
- drop_spte(kvm, sptep);
+ mmu_spte_clear_track_bits(sptep);
need_tlb_flush = 1;
- goto restart;
}
+ pte_list_destroy(rmapp);
+
return need_tlb_flush;
}
@@ -2016,11 +2035,10 @@ static void kvm_mmu_unlink_parents(struct kvm *kvm, struct kvm_mmu_page *sp)
u64 *sptep;
struct pte_list_iterator iter;
-restart:
- for_each_spte_in_pte_list(sp->parent_ptes, iter, sptep) {
- drop_parent_pte(sp, sptep);
- goto restart;
- }
+ for_each_spte_in_pte_list(sp->parent_ptes, iter, sptep)
+ mmu_spte_clear_no_track(sptep);
+
+ pte_list_destroy(&sp->parent_ptes);
}
static int mmu_zap_unsync_children(struct kvm *kvm,
--
1.7.7.6
next prev parent reply other threads:[~2013-02-05 8:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-05 8:52 [PATCH v3 0/5] KVM: MMU: unify and cleanup the code of walking pte list Xiao Guangrong
2013-02-05 8:53 ` [PATCH v3 1/5] KVM: MMU: introduce mmu_spte_establish Xiao Guangrong
2013-02-08 21:35 ` Marcelo Tosatti
2013-02-05 8:53 ` [PATCH v3 2/5] KVM: MMU: clarify the logic in kvm_set_pte_rmapp Xiao Guangrong
2013-02-05 8:54 ` [PATCH v3 3/5] KVM: MMU: unify the code of walking pte list Xiao Guangrong
2013-02-05 8:54 ` [PATCH v3 4/5] KVM: MMU: fix spte assertion Xiao Guangrong
2013-02-05 8:55 ` Xiao Guangrong [this message]
2013-02-08 21:48 ` [PATCH v3 5/5] KVM: MMU: fast drop all spte on the pte_list Marcelo Tosatti
2013-02-05 13:04 ` [PATCH v3 0/5] KVM: MMU: unify and cleanup the code of walking pte list Gleb Natapov
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=5110C909.1000502@linux.vnet.ibm.com \
--to=xiaoguangrong@linux.vnet.ibm.com \
--cc=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.