From patchwork Tue Feb 22 08:13:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 579681 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1M8CaPE030735 for ; Tue, 22 Feb 2011 08:12:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751966Ab1BVIMR (ORCPT ); Tue, 22 Feb 2011 03:12:17 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:58120 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751619Ab1BVIMR (ORCPT ); Tue, 22 Feb 2011 03:12:17 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 0BC22170116; Tue, 22 Feb 2011 16:12:16 +0800 (CST) Received: from mailserver.fnst.cn.fujitus.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id p1M86WAs027859; Tue, 22 Feb 2011 16:06:32 +0800 Received: from eric.localdomain ([10.167.225.99]) by mailserver.fnst.cn.fujitus.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2011022216111472-192367 ; Tue, 22 Feb 2011 16:11:14 +0800 Message-ID: <4D637019.9070208@cn.fujitsu.com> Date: Tue, 22 Feb 2011 16:13:13 +0800 From: Xiao Guangrong User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Thunderbird/3.1.7 MIME-Version: 1.0 To: Avi Kivity CC: Marcelo Tosatti , LKML , KVM Subject: [PATCH 5/7] KVM: cache the last used slot References: <4D636EF8.60800@cn.fujitsu.com> In-Reply-To: <4D636EF8.60800@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-02-22 16:11:14, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-02-22 16:11:15, Serialize complete at 2011-02-22 16:11:15 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 22 Feb 2011 08:12:37 +0000 (UTC) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index f1963a4..7fbae16 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -225,6 +225,7 @@ struct kvm_memslots { int nmemslots; int used_slots; u64 generation; + struct kvm_memory_slot *slot_cache; struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM]; struct kvm_memory_slot *slots_sort[KVM_MEM_SLOTS_NUM]; }; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 0795426..4917d6a 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -643,15 +643,21 @@ static struct kvm_memory_slot *search_memslots(struct kvm_memslots *slots, gfn_t gfn) { int start = 0, end = slots->used_slots, idx; - struct kvm_memory_slot *memslot; + struct kvm_memory_slot *memslot = slots->slot_cache; + + if (memslot && gfn >= memslot->base_gfn && + gfn < memslot->base_gfn + memslot->npages) + return memslot; while (start < end) { idx = (start + end) / 2; memslot = slots->slots_sort[idx]; if (gfn >= memslot->base_gfn && - gfn < memslot->base_gfn + memslot->npages) + gfn < memslot->base_gfn + memslot->npages) { + slots->slot_cache = memslot; return memslot; + } if (memslot->base_gfn < gfn) start = idx + 1; @@ -684,6 +690,7 @@ void memslots_updated(struct kvm_memslots *slots, int slot_id) if (slot_id >= slots->nmemslots) slots->nmemslots = slot_id + 1; slots->generation++; + slots->slot_cache = NULL; sort_memslots(slots); }