From 0a3e6f7db5873898038b3796049e7d6db3d8d7ce Mon Sep 17 00:00:00 2001 From: nashzhou Date: Thu, 15 Oct 2026 14:44:59 +0800 Subject: [PATCH 2/2] kvm: add vm_uevent_notify knob to disable VM lifecycle uevents kvm_uevent_notify_change() runs on every VM create and destroy: it takes the global kvm_lock to update the created/active counters, then emits a KOBJ_CHANGE uevent through kobject_uevent_env(), costing a GFP_KERNEL_ACCOUNT allocation, dentry_path_raw() and a netlink broadcast whenever udevd is listening. Hosts that churn through many VMs (snapshot/restore VMMs) pay all of that on every pause/resume even when nothing consumes the uevent. Add a runtime-toggleable kvm.vm_uevent_notify parameter (0644), defaulting to on. While disabled, kvm_uevent_notify_change() returns early; the uevent-only kvm_createvm_count/kvm_active_vms counters are then no longer maintained. Signed-off-by: nashzhou --- virt/kvm/kvm_main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 0c098e4b3010..2fef89cabc18 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -96,6 +96,17 @@ unsigned int halt_poll_ns_shrink; module_param(halt_poll_ns_shrink, uint, 0644); EXPORT_SYMBOL_GPL(halt_poll_ns_shrink); +/* + * VM lifecycle uevents serve udev-style consumers (created/active counts, + * userspace pid). Workloads that create and destroy VMs at high rate pay + * the global kvm_lock plus a netlink broadcast per transition; disable + * when nobody listens, e.g. kvm.vm_uevent_notify=0 (runtime-toggleable). + * While disabled the uevent-only kvm_createvm_count/kvm_active_vms + * counters are not maintained. + */ +static bool vm_uevent_notify = true; +module_param(vm_uevent_notify, bool, 0644); + /* * Ordering of locks: * @@ -6754,7 +6765,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 (!vm_uevent_notify || !kvm_dev.this_device || !kvm) return; mutex_lock(&kvm_lock); -- 2.43.0