lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4D637019.9070208@cn.fujitsu.com>
Date:	Tue, 22 Feb 2011 16:13:13 +0800
From:	Xiao Guangrong <xiaoguangrong@...fujitsu.com>
To:	Avi Kivity <avi@...hat.com>
CC:	Marcelo Tosatti <mtosatti@...hat.com>,
	LKML <linux-kernel@...r.kernel.org>, KVM <kvm@...r.kernel.org>
Subject: [PATCH 5/7] KVM: cache the last used slot

Cache the last used slot, the hit ratio is more than 35% during my test

Signed-off-by: Xiao Guangrong <xiaoguangrong@...fujitsu.com>
---
 include/linux/kvm_host.h |    1 +
 virt/kvm/kvm_main.c      |   11 +++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

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);
 }
 
-- 
1.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ