mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>,
	avi.kivity@gmail.com, mtosatti@redhat.com,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH v5 3/8] KVM: MMU: fast invalidate all pages
Date: Thu, 16 May 2013 15:49:11 +0200	[thread overview]
Message-ID: <5194E3D7.2090808@redhat.com> (raw)
In-Reply-To: <20130516134130.GD14597@redhat.com>

Il 16/05/2013 15:41, Gleb Natapov ha scritto:
> On Thu, May 16, 2013 at 03:14:35PM +0200, Paolo Bonzini wrote:
>> Il 16/05/2013 14:43, Gleb Natapov ha scritto:
>>>>> +restart:
>>>>> +	list_for_each_entry_safe(sp, node, &kvm->arch.active_mmu_pages, link) {
>>>>> +		if (!is_obsolete_sp(kvm, sp))
>>>>> +			continue;
>>> What if we save kvm->arch.active_mmu_pages on the stack and init
>>> kvm->arch.active_mmu_pages to be empty at the entrance to
>>> zap_invalid_pages(). This loop will iterate over saved list. This will
>>> allow us to drop the is_obsolete_sp() check and will save time since we
>>> will not be iterating over newly created sps.
>>>
>>
>> But when you add cond_resched_lock a thread may want to zap pages itself
>> (e.g. from prepare_zap_oldest_mmu_page) and it won't find them.
>>
> Yes, this will break mmu pages accounting. We can make
> prepare_zap_oldest_mmu_page() wait while zap_invalid_pages()
> frees needed amount of pages if one is in progress.
> 
>> Here is another proposal...  The idea is to avoid looking at new pages
>> more than necessary after a "goto restart".
>>
>> Basically, you alternate between two phases:
>>
>> - look for pages to be zapped, group them together
>>
>> - zap the pages
>>
>> Something like:
>>
>>       moved = 0;
>> restart:
>>       zapping = true;
>>       for each page in active_mmu_pages [reverse and safe] {
>>              if (!is_obsolete || invalid) {
>>                  /*
>>                   * Found a new page, stop zapping for now and
>>                   * try to segregate the invalid ones at one end
>>                   * of the list.
>>                   */
>>                  zapping = false;
>>                  continue;
>>              }
>>
>>              if (batch > 10 && ...) {
>>                  cond_resched_lock
>>                  batch = 0;
>>                  goto restart;
>>              }
>>
>>              if (!zapping) {
>>                  /*
>>                   * Segregate pages to one end of the list where
>>                   * new pages don't get in the way.
>>                   */
>>                  list_move_tail(page, active_mmu_pages)
>>                  batch++; /* or maybe not? */
>>                  moved++;
>>              } else {
>>                  batch += prepare_zap_page
>>                  goto restart;
>>              }
>>      }
>>
>>      /* Need another pass to look at segregated pages?  */
>>      if (moved) {
>>          moved = 0;
>>          goto restart;
>>      }
> Not sure what are you trying to achieve with "moved" tricks. Just
> walking the list from the end and stopping on first valid sp should be
> enough since active_mmu_pages list is a FIFO right now.

Right, I missed that "sp->role.invalid = 1" will ensure anyway that
pages are visited at most twice.

Paolo

  reply	other threads:[~2013-05-16 13:49 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-16 12:17 [PATCH v5 0/8] KVM: MMU: fast zap all shadow pages Xiao Guangrong
2013-05-16 12:17 ` [PATCH v5 1/8] KVM: MMU: drop unnecessary kvm_reload_remote_mmus Xiao Guangrong
2013-05-16 12:17 ` [PATCH v5 2/8] KVM: MMU: delete shadow page from hash list in kvm_mmu_prepare_zap_page Xiao Guangrong
2013-05-16 12:17 ` [PATCH v5 3/8] KVM: MMU: fast invalidate all pages Xiao Guangrong
2013-05-16 12:43   ` Gleb Natapov
2013-05-16 13:14     ` Paolo Bonzini
2013-05-16 13:41       ` Gleb Natapov
2013-05-16 13:49         ` Paolo Bonzini [this message]
2013-05-16 13:25     ` Xiao Guangrong
2013-05-16 13:43       ` Gleb Natapov
2013-05-16 15:57         ` Gleb Natapov
2013-05-16 18:39           ` Xiao Guangrong
2013-05-16 19:57             ` Gleb Natapov
2013-05-16 16:18   ` Gleb Natapov
2013-05-16 18:40     ` Xiao Guangrong
2013-05-16 12:17 ` [PATCH v5 4/8] KVM: x86: use the fast way to " Xiao Guangrong
2013-05-16 16:19   ` Gleb Natapov
2013-05-16 18:45     ` Xiao Guangrong
2013-05-16 12:17 ` [PATCH v5 5/8] KVM: MMU: make kvm_mmu_zap_all preemptable Xiao Guangrong
2013-05-16 12:17 ` [PATCH v5 6/8] KVM: MMU: show mmu_valid_gen in shadow page related tracepoints Xiao Guangrong
2013-05-16 12:17 ` [PATCH v5 7/8] KVM: MMU: add tracepoint for kvm_mmu_invalidate_memslot_pages Xiao Guangrong
2013-05-16 12:17 ` [PATCH v5 8/8] KVM: MMU: zap pages in batch Xiao Guangrong
2013-05-16 12:45   ` Paolo Bonzini
2013-05-16 13:31     ` Xiao Guangrong
2013-05-16 12:20 ` [PATCH v5 0/8] KVM: MMU: fast zap all shadow pages Xiao Guangrong
2013-05-16 14:36 ` Takuya Yoshikawa
2013-05-16 18:26   ` Xiao Guangrong

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=5194E3D7.2090808@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=avi.kivity@gmail.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=xiaoguangrong@linux.vnet.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome