KVM: PPC: Book3S HV: Add KVM stat largepages_[2M/1G]
authorSuraj Jitindar Singh <sjitindarsingh@gmail.com>
Tue, 19 Feb 2019 03:53:45 +0000 (14:53 +1100)
committerPaul Mackerras <paulus@ozlabs.org>
Tue, 19 Feb 2019 05:00:15 +0000 (16:00 +1100)
This adds an entry to the kvm_stats_debugfs directory which provides the
number of large (2M or 1G) pages which have been used to setup the guest
mappings, for radix guests.

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
arch/powerpc/include/asm/kvm_host.h
arch/powerpc/kvm/book3s.c
arch/powerpc/kvm/book3s_64_mmu_radix.c

index 0914303..4af498a 100644 (file)
@@ -99,6 +99,8 @@ struct kvm_nested_guest;
 
 struct kvm_vm_stat {
        ulong remote_tlb_flush;
+       ulong num_2M_pages;
+       ulong num_1G_pages;
 };
 
 struct kvm_vcpu_stat {
index 601c094..22a46c6 100644 (file)
@@ -39,6 +39,7 @@
 #include "book3s.h"
 #include "trace.h"
 
+#define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
 #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
 
 /* #define EXIT_DEBUG */
@@ -71,6 +72,8 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
        { "pthru_all",       VCPU_STAT(pthru_all) },
        { "pthru_host",      VCPU_STAT(pthru_host) },
        { "pthru_bad_aff",   VCPU_STAT(pthru_bad_aff) },
+       { "largepages_2M",    VM_STAT(num_2M_pages) },
+       { "largepages_1G",    VM_STAT(num_1G_pages) },
        { NULL }
 };
 
index 1b821c6..f55ef07 100644 (file)
@@ -403,8 +403,13 @@ void kvmppc_unmap_pte(struct kvm *kvm, pte_t *pte, unsigned long gpa,
                if (!memslot)
                        return;
        }
-       if (shift)
+       if (shift) { /* 1GB or 2MB page */
                page_size = 1ul << shift;
+               if (shift == PMD_SHIFT)
+                       kvm->stat.num_2M_pages--;
+               else if (shift == PUD_SHIFT)
+                       kvm->stat.num_1G_pages--;
+       }
 
        gpa &= ~(page_size - 1);
        hpa = old & PTE_RPN_MASK;
@@ -878,6 +883,14 @@ int kvmppc_book3s_instantiate_page(struct kvm_vcpu *vcpu,
                put_page(page);
        }
 
+       /* Increment number of large pages if we (successfully) inserted one */
+       if (!ret) {
+               if (level == 1)
+                       kvm->stat.num_2M_pages++;
+               else if (level == 2)
+                       kvm->stat.num_1G_pages++;
+       }
+
        return ret;
 }