KVM: Avoid useless memory write when possible
authorLuca Tettamanti <kronos.it@gmail.com>
Tue, 19 Jun 2007 20:41:38 +0000 (22:41 +0200)
committerAvi Kivity <avi@qumranet.com>
Mon, 16 Jul 2007 09:05:48 +0000 (12:05 +0300)
When writing to normal memory and the memory area is unchanged the write
can be safely skipped, avoiding the costly kvm_mmu_pte_write.

Signed-Off-By: Luca Tettamanti <kronos.it@gmail.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
drivers/kvm/kvm_main.c

index 7826f16271e5f466b4b3716065e5cc6505c01dfc..5603000573ec0bbcd6018970585ed6990760d58c 100644 (file)
@@ -1170,8 +1170,10 @@ static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
                return 0;
        mark_page_dirty(vcpu->kvm, gpa >> PAGE_SHIFT);
        virt = kmap_atomic(page, KM_USER0);
-       kvm_mmu_pte_write(vcpu, gpa, virt + offset, val, bytes);
-       memcpy(virt + offset_in_page(gpa), val, bytes);
+       if (memcmp(virt + offset_in_page(gpa), val, bytes)) {
+               kvm_mmu_pte_write(vcpu, gpa, virt + offset, val, bytes);
+               memcpy(virt + offset_in_page(gpa), val, bytes);
+       }
        kunmap_atomic(virt, KM_USER0);
        return 1;
 }