From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takuya Yoshikawa Subject: Re: [PATCH 4/4] KVM: Optimize dirty logging by rmap_write_protect() Date: Mon, 14 Nov 2011 19:29:41 +0900 Message-ID: <4EC0ED95.60604@oss.ntt.co.jp> References: <20111114182041.43570cdf.yoshikawa.takuya@oss.ntt.co.jp> <20111114182450.d67f74ee.yoshikawa.takuya@oss.ntt.co.jp> <4EC0EBE0.6010802@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: mtosatti@redhat.com, kvm@vger.kernel.org, takuya.yoshikawa@gmail.com To: Avi Kivity Return-path: Received: from serv2.oss.ntt.co.jp ([222.151.198.100]:58979 "EHLO serv2.oss.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752803Ab1KNK3H (ORCPT ); Mon, 14 Nov 2011 05:29:07 -0500 In-Reply-To: <4EC0EBE0.6010802@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: (2011/11/14 19:22), Avi Kivity wrote: >> + * >> + * Generally speaking, if there are not so many dirty pages compared to the >> + * number of shadow pages, we should use the latter. >> + * >> + * Note that letting others write into a page marked dirty in the old bitmap >> + * by using the remaining tlb entry is not a problem. That page will become >> + * write protected again when we flush the tlb and then be reported dirty to >> + * the user space by copying the old bitmap. >> + */ >> +static void write_protect_slot(struct kvm *kvm, >> + struct kvm_memory_slot *memslot, >> + unsigned long *dirty_bitmap, >> + unsigned long nr_dirty_pages) >> +{ >> + /* Not many dirty pages compared to # of shadow pages. */ >> + if (nr_dirty_pages< kvm->arch.n_used_mmu_pages) { > > Seems a reasonable heuristic. In particular, this is always true for > vga, yes? That will get the code exercised. Almost always yes, once the guest warms up and shadow pages are allocated. Takuya > >> + unsigned long gfn_offset; >> + >> + for_each_set_bit(gfn_offset, dirty_bitmap, memslot->npages) { >> + unsigned long gfn = memslot->base_gfn + gfn_offset; >> + >> + spin_lock(&kvm->mmu_lock); >> + kvm_mmu_rmap_write_protect(kvm, gfn, memslot); >> + spin_unlock(&kvm->mmu_lock); >> + } >> + kvm_flush_remote_tlbs(kvm); >> + } else { >> + spin_lock(&kvm->mmu_lock); >> + kvm_mmu_slot_remove_write_access(kvm, memslot->id); >> + spin_unlock(&kvm->mmu_lock); >> + } >> +} >> + >> >