KVM: Avoid synchronize_srcu() in kvm_io_bus_register_dev()
Li,Rongqing
Tested-byQuoted 10 lines
Device MMIO registration may happen quite frequently during VM boot, and the SRCU synchronization each time has a measurable effect on VM startup time. In our experiments it can account for around 25% of a VM's startup time.
Replace the synchronization with a deferred free of the old
kvm_io_busstructure.
Tested-by Li RongQing <[email protected]>
Thanks
-Li
Quoted 48 lines
Signed-off-by Keir Fraser <[email protected]>--- include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)include/linux/kvm_host.h index renamed from include/linux/kvm_host.h +0
-0
9132148fb467..802ca46f7537100644include/linux/kvm_host.h +1
-0@@ -205,6 +205,7 @@ struct kvm_io_range { struct kvm_io_bus {int dev_count;int ioeventfd_count; +struct rcu_head rcu;struct kvm_io_range range[]; };virt/kvm/kvm_main.c index renamed from virt/kvm/kvm_main.c +0
-0
9ec3b96b9666..f690a4997a0f100644virt/kvm/kvm_main.c +7
-0@@ -5948,6 +5948,13 @@ int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr, }EXPORT_SYMBOL_GPL (kvm_io_bus_read ); +static void __free_bus (struct rcu_head *rcu) { + struct kvm_io_bus *bus = container_of(rcu, struct kvm_io_bus, rcu); + +kfree (bus); +} +int kvm_io_bus_register_dev (struct kvm *kvm,enum kvm_bus bus_idx,gpa_t addr, int len, struct kvm_io_device *dev) { @@ -5986,8 +5993,7 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus
bus_idx,gpa_taddr,virt/kvm/kvm_main.c +1
-3memcpy (new_bus->range + i +1 , bus->range + i, (bus->dev_count - i) *sizeof (struct kvm_io_range ));rcu_assign_pointer (kvm->buses[bus_idx], new_bus); -synchronize_srcu_expedited (&kvm->srcu); -kfree (bus); +call_srcu (&kvm->srcu, &bus->rcu, __free_bus);return 0 ; } --2.50.0.727.gbf7dc18ff4-goog