From: David Hildenbrand Subject: Re: [PATCH 1/2] kvm: x86: export maximum number of mmu_page_hash collisions Date: Tue, 20 Dec 2016 10:48:40 +0100 Message-ID: <91b68a42-5c38-9d22-89ae-4cc8c2ba4f1f@redhat.com> References: <1482184705-127401-1-git-send-email-dmatlack@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Cc: pbonzini@redhat.com, rkrcmar@redhat.com To: David Matlack , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:56120 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933545AbcLTJso (ORCPT ); Tue, 20 Dec 2016 04:48:44 -0500 In-Reply-To: <1482184705-127401-1-git-send-email-dmatlack@google.com> Sender: kvm-owner@vger.kernel.org List-ID: > - for_each_gfn_valid_sp(vcpu->kvm, sp, gfn) { > + for_each_valid_sp(vcpu->kvm, sp, gfn) { > + if (sp->gfn != gfn) { > + collisions++; > + continue; > + } > + > if (!need_sync && sp->unsync) > need_sync = true; > > @@ -2152,8 +2159,8 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, > kvm_make_request(KVM_REQ_MMU_SYNC, vcpu); > > __clear_sp_write_flooding_count(sp); > - trace_kvm_mmu_get_page(sp, false); > - return sp; > + created = false; Simply doing if (collisions > vcpu->kvm->stat.max_mmu_page_hash_collisions) vcpu->kvm->stat.max_mmu_page_hash_collisions = collisions; at this point saves a local variable, a jump label and keeps this patch minimal. > + goto out; > } > > ++vcpu->kvm->stat.mmu_cache_miss; > @@ -2164,6 +2171,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, > sp->role = role; > hlist_add_head(&sp->hash_link, > &vcpu->kvm->arch.mmu_page_hash[kvm_page_table_hashfn(gfn)]); > + unrelated change. > if (!direct) { > /* > * we should do write protection before syncing pages > @@ -2180,9 +2188,12 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, > } > sp->mmu_valid_gen = vcpu->kvm->arch.mmu_valid_gen; > clear_page(sp->spt); > - trace_kvm_mmu_get_page(sp, true); > > kvm_mmu_flush_or_zap(vcpu, &invalid_list, false, flush); > +out: > + if (collisions > vcpu->kvm->stat.max_mmu_page_hash_collisions) > + vcpu->kvm->stat.max_mmu_page_hash_collisions = collisions; > + trace_kvm_mmu_get_page(sp, created); > return sp; > } -- David