[RFC 8/8]KVM: cache pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



KVM use gfn_to_page very frequestly, which makes find_get_page a bottleneck,
so cache pages found to speed up.

Signed-off-by: Shaohua Li <[email protected]>
---
 drivers/kvm/kvm.h      |    1 +
 drivers/kvm/kvm_main.c |    9 +++++++++
 2 files changed, 10 insertions(+)

Index: linux/drivers/kvm/kvm.h
===================================================================
--- linux.orig/drivers/kvm/kvm.h	2007-07-20 14:29:46.000000000 +0800
+++ linux/drivers/kvm/kvm.h	2007-07-20 14:50:11.000000000 +0800
@@ -431,6 +431,7 @@ struct kvm_mem_alias {
 
 struct kvm_page_info {
 	swp_entry_t entry;
+	struct page *page;
 };
 
 struct kvm_memory_slot {
Index: linux/drivers/kvm/kvm_main.c
===================================================================
--- linux.orig/drivers/kvm/kvm_main.c	2007-07-20 14:45:40.000000000 +0800
+++ linux/drivers/kvm/kvm_main.c	2007-07-20 14:50:11.000000000 +0800
@@ -1031,6 +1031,7 @@ repeat:
 		info->entry.val = 0;
 		if (add_to_page_cache(page, mapping, gfn, GFP_KERNEL))
 			return NULL;
+		info->page = page;
 		ClearPageDirty(page);
 	} else {
 		/* allocate new page */
@@ -1041,6 +1042,7 @@ repeat:
 			page_cache_release(page);
 			return NULL;
 		}
+		info->page = page;
 		SetPageUptodate(page);
 		set_page_private(page, 0);
 	}
@@ -1063,6 +1065,7 @@ static int kvm_move_to_swap(struct page 
 	if (move_to_swap_cache(page, swap) == 0) {
 		slot = __gfn_to_memslot(kvm, gfn);
 		slot->phys_mem[gfn - slot->base_gfn].entry = swap;
+		slot->phys_mem[gfn - slot->base_gfn].page = NULL;
 		return 0;
 	}
 	swap_free(swap);
@@ -1082,6 +1085,12 @@ struct page *gfn_to_page(struct kvm *kvm
 	if (!slot)
 		return NULL;
 
+	page = slot->phys_mem[gfn - slot->base_gfn].page;
+	if (page) {
+		mark_page_accessed(page);
+		return page;
+	}
+
 	page = find_get_page(mapping, gfn);
 	if (page)
 		goto out;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux