linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/6] KVM: MMU: fast zap all shadow pages
@ 2013-04-27  3:13 Xiao Guangrong
  2013-04-27  3:13 ` [PATCH v4 1/6] KVM: MMU: drop unnecessary kvm_reload_remote_mmus Xiao Guangrong
                   ` (5 more replies)
  0 siblings, 6 replies; 34+ messages in thread
From: Xiao Guangrong @ 2013-04-27  3:13 UTC (permalink / raw)
  To: mtosatti; +Cc: gleb, avi.kivity, linux-kernel, kvm, Xiao Guangrong

This patchset is based on current 'queue' branch on kvm tree.

Changlog:

V4:
  1): drop unmapping invalid rmap out of mmu-lock and use lock-break technique
      instead. Thanks to Gleb's comments.

  2): needn't handle invalid-gen pages specially due to page table always
      switched by KVM_REQ_MMU_RELOAD. Thanks to Marcelo's comments.

V3:
  completely redesign the algorithm, please see below.

V2:
  - do not reset n_requested_mmu_pages and n_max_mmu_pages
  - batch free root shadow pages to reduce vcpu notification and mmu-lock
    contention
  - remove the first patch that introduce kvm->arch.mmu_cache since we only
    'memset zero' on hashtable rather than all mmu cache members in this
    version
  - remove unnecessary kvm_reload_remote_mmus after kvm_mmu_zap_all

* Issue
The current kvm_mmu_zap_all is really slow - it is holding mmu-lock to
walk and zap all shadow pages one by one, also it need to zap all guest
page's rmap and all shadow page's parent spte list. Particularly, things
become worse if guest uses more memory or vcpus. It is not good for
scalability.

* Idea
KVM maintains a global mmu invalid generation-number which is stored in
kvm->arch.mmu_valid_gen and every shadow page stores the current global
generation-number into sp->mmu_valid_gen when it is created.

When KVM need zap all shadow pages sptes, it just simply increase the
global generation-number then reload root shadow pages on all vcpus.
Vcpu will create a new shadow page table according to current kvm's
generation-number. It ensures the old pages are not used any more.

The invalid-gen pages (sp->mmu_valid_gen != kvm->arch.mmu_valid_gen)
are keeped in mmu-cache until page allocator reclaims page.

* Challenges
Some page invalidation is requested when memslot is moved or deleted
and kvm is being destroy who call zap_all_pages to delete all sp using
their rmap and lpage-info, after call zap_all_pages, the rmap and lpage-info
will be freed.

For the lpage-info, we clear all lpage count when do zap-all-pages, then
all invalid shadow pages are not counted in lpage-info, after that lpage-info
on the invalid memslot can be safely freed. This is also good for the
performance - it allows guest to use hugepage as far as possible.

For the rmap, we use lock-break technique to zap all sptes linked on the
invalid rmap, it is not very effective but good for the first step.

* TODO
Unmapping invalid rmap out of mmu-lock with a clear way.

Xiao Guangrong (6):
  KVM: MMU: drop unnecessary kvm_reload_remote_mmus
  KVM: x86: introduce memslot_set_lpage_disallowed
  KVM: MMU: introduce kvm_clear_all_lpage_info
  KVM: MMU: fast invalid all shadow pages
  KVM: x86: use the fast way to invalid all pages
  KVM: MMU: make kvm_mmu_zap_all preemptable

 arch/x86/include/asm/kvm_host.h |    2 +
 arch/x86/kvm/mmu.c              |   88 ++++++++++++++++++++++++++++++++++++++-
 arch/x86/kvm/mmu.h              |    2 +
 arch/x86/kvm/x86.c              |   87 ++++++++++++++++++++++++++++-----------
 arch/x86/kvm/x86.h              |    2 +
 5 files changed, 155 insertions(+), 26 deletions(-)

-- 
1.7.7.6


^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2013-05-08 10:41 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-27  3:13 [PATCH v4 0/6] KVM: MMU: fast zap all shadow pages Xiao Guangrong
2013-04-27  3:13 ` [PATCH v4 1/6] KVM: MMU: drop unnecessary kvm_reload_remote_mmus Xiao Guangrong
2013-04-27  3:13 ` [PATCH v4 2/6] KVM: x86: introduce memslot_set_lpage_disallowed Xiao Guangrong
2013-05-03  2:10   ` Takuya Yoshikawa
2013-05-03  5:55     ` Xiao Guangrong
2013-04-27  3:13 ` [PATCH v4 3/6] KVM: MMU: introduce kvm_clear_all_lpage_info Xiao Guangrong
2013-05-03  2:15   ` Takuya Yoshikawa
2013-05-03  5:57     ` Xiao Guangrong
2013-04-27  3:13 ` [PATCH v4 4/6] KVM: MMU: fast invalid all shadow pages Xiao Guangrong
2013-05-03  1:05   ` Marcelo Tosatti
2013-05-03  5:52     ` Xiao Guangrong
2013-05-03 15:53       ` Marcelo Tosatti
2013-05-03 16:51         ` Xiao Guangrong
2013-05-04  0:52           ` Marcelo Tosatti
2013-05-04  0:56             ` Marcelo Tosatti
2013-05-06  3:39             ` Xiao Guangrong
2013-05-06 12:36               ` Gleb Natapov
2013-05-06 13:10                 ` Xiao Guangrong
2013-05-06 17:24                   ` Gleb Natapov
2013-05-06 17:45                     ` Xiao Guangrong
2013-05-07  8:58                       ` Gleb Natapov
2013-05-07  9:41                         ` Xiao Guangrong
2013-05-07 10:00                           ` Gleb Natapov
2013-05-07 14:33                             ` Marcelo Tosatti
2013-05-07 14:56                               ` Gleb Natapov
2013-05-07 15:09                                 ` Marcelo Tosatti
2013-05-08 10:41                                   ` Gleb Natapov
2013-05-06 19:50               ` Marcelo Tosatti
2013-05-07  3:39                 ` Xiao Guangrong
2013-05-07 14:42                   ` Marcelo Tosatti
2013-05-03  2:27   ` Takuya Yoshikawa
2013-05-03  6:00     ` Xiao Guangrong
2013-04-27  3:13 ` [PATCH v4 5/6] KVM: x86: use the fast way to invalid all pages Xiao Guangrong
2013-04-27  3:13 ` [PATCH v4 6/6] KVM: MMU: make kvm_mmu_zap_all preemptable Xiao Guangrong

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).