Skip to contentSkip to conversation

KVM: make uevents configurable

PATCH New Bernhard Kauer 1 participant 1 message Dec 5, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 KVM: make uevents configurable

Handling of uevents in userlevel is a bottleneck for tiny VMs.

Running 10_000 VMs keeps one and a half cores busy for 5.4 seconds to let systemd-udevd handle all messages. That is roughly 27x longer than the 0.2 seconds needed for running the VMs without them.

We choose a module parameter here due to its simplicity and ease of maintenance.

---

v1->v2: read-write parameter to avoid killing all running VMs to toggle it v2->v3: invert the logic, add documentation

 Documentation/admin-guide/kernel-parameters.txt | 4 ++++
 virt/kvm/kvm_main.c                             | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +4 -0
index d401577b5a6a..8ae3dc4f2392 100644
@@ -2723,6 +2723,10 @@
 			If the value is 0 (the default), KVM will pick a period based
 			on the ratio, such that a page is zapped after 1 hour on average.
 
+	kvm.uevent_notify=
+			[KVM] Send a uevent message to udev whenever a VM is
+			created or destroyed. Default is true.
+
 	kvm-amd.nested=	[KVM,AMD] Control nested virtualization feature in
 			KVM/SVM. Default is 1 (enabled).
 
virt/kvm/kvm_main.c +4 -1
index 609e0bd68e8e..276c98e2c37d 100644
@@ -97,6 +97,9 @@ EXPORT_SYMBOL_GPL(halt_poll_ns_shrink);
 bool debugfs_per_vm = true;
 module_param(debugfs_per_vm, bool, 0644);
 
+static bool uevent_notify = true;
+module_param(uevent_notify, bool, 0644);
+
 /*
  * Ordering of locks:
  *
@@ -6276,7 +6279,7 @@ static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm)
 	struct kobj_uevent_env *env;
 	unsigned long long created, active;
 
-	if (!kvm_dev.this_device || !kvm)
+	if (!kvm_dev.this_device || !kvm || !uevent_notify)
 		return;
 
 	mutex_lock(&kvm_lock);
Signature · 1 line
2.45.2