Every VM gets a debugfs directory with one file per stat, plus a directory and a few files per vCPU, i.e. ~95 entries for an 8-vCPU VM on x86. Each entry costs a dentry and an inode, and the stats files duplicate the binary stats. Add kvm.per_vm_debugfs (default on) so that these directories can be skipped. Signed-off-by: Peng Hao --- Documentation/admin-guide/kernel-parameters.txt | 7 +++++++ virt/kvm/kvm_main.c | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 42ff19defe16..c1e0f6bf4c24 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3211,6 +3211,13 @@ Kernel parameters 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.per_vm_debugfs= + [KVM] Create a debugfs directory for each VM and vCPU, + containing per-VM stats and architecture specific + debug files. Global stats in debugfs and binary stats + are not affected. + Default is Y (on). + kvm-{amd,intel}.enable_mediated_pmu=[KVM,AMD,INTEL] If enabled, KVM will provide a mediated virtual PMU, instead of the default perf-based virtual PMU (if diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index fff19e9239d2..54a2924f9b92 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -104,6 +104,14 @@ EXPORT_SYMBOL_FOR_KVM_INTERNAL(halt_poll_ns_shrink); static bool __ro_after_init allow_unsafe_mappings; module_param(allow_unsafe_mappings, bool, 0444); +/* + * Create a debugfs directory for every VM and vCPU. The per-VM stats files + * duplicate the binary stats, and each file costs a dentry and an inode, which + * adds up when running many VMs. + */ +static bool __ro_after_init per_vm_debugfs = true; +module_param(per_vm_debugfs, bool, 0444); + #ifdef CONFIG_KVM_PRIVATE_MEMATTR_VM bool __ro_after_init gmem_in_place_conversion = false; module_param(gmem_in_place_conversion, bool, 0444); @@ -1024,7 +1032,7 @@ static int kvm_create_vm_debugfs(struct kvm *kvm, const char *fdname) int kvm_debugfs_num_entries = kvm_vm_stats_header.num_desc + kvm_vcpu_stats_header.num_desc; - if (!debugfs_initialized()) + if (!debugfs_initialized() || !per_vm_debugfs) return 0; snprintf(dir_name, sizeof(dir_name), "%d-%s", task_pid_nr(current), fdname); @@ -4235,7 +4243,7 @@ static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu) struct dentry *debugfs_dentry; char dir_name[ITOA_MAX_LEN * 2]; - if (!debugfs_initialized()) + if (!debugfs_initialized() || !per_vm_debugfs) return; snprintf(dir_name, sizeof(dir_name), "vcpu%d", vcpu->vcpu_id); -- 2.43.7