Skip to content

Commit

Permalink
KVM: Avoid useless memory write when possible
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Avi Kivity <[email protected]>
  • Loading branch information
tettamanti authored and avikivity committed Jul 16, 2007
1 parent 02c03a3 commit a3c870b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a3c870b

Please sign in to comment.