diff mbox

[v3,01/15] KVM: x86: clean up and optimize for kvm_arch_free_memslot

Message ID 1366093973-2617-2-git-send-email-xiaoguangrong@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Xiao Guangrong April 16, 2013, 6:32 a.m. UTC
memslot rmap and lpage-info are never partly reused and nothing need
be freed when new memslot is created

Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
---
 arch/x86/kvm/x86.c |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)
diff mbox

Patch

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 4be4733..b0be7ec 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6856,19 +6856,22 @@  void kvm_arch_free_memslot(struct kvm_memory_slot *free,
 {
 	int i;
 
+	if (dont && dont->arch.rmap[0] == free->arch.rmap[0])
+		return;
+
+	/* It is a empty memslot. */
+	if (!free->arch.rmap[0])
+		return;
+
 	for (i = 0; i < KVM_NR_PAGE_SIZES; ++i) {
-		if (!dont || free->arch.rmap[i] != dont->arch.rmap[i]) {
-			kvm_kvfree(free->arch.rmap[i]);
-			free->arch.rmap[i] = NULL;
-		}
+		kvm_kvfree(free->arch.rmap[i]);
+		free->arch.rmap[i] = NULL;
+
 		if (i == 0)
 			continue;
 
-		if (!dont || free->arch.lpage_info[i - 1] !=
-			     dont->arch.lpage_info[i - 1]) {
-			kvm_kvfree(free->arch.lpage_info[i - 1]);
-			free->arch.lpage_info[i - 1] = NULL;
-		}
+		kvm_kvfree(free->arch.lpage_info[i - 1]);
+		free->arch.lpage_info[i - 1] = NULL;
 	}
 }