There were good optimization written in past which reduces the number of
slb faults e.g. during context switches [1]. However if one wants to
measure total number of slb faults then there is no easy way of
measuring one e.g. number of slb faults during bootup.

This adds slb faults as part of vmstat counter to easily measure total
number of slb faults for book3s64.

Note: slb fault handling is defined as raw interrupt handler which says:
 * raw interrupt handlers must not enable or disable interrupts, or
 * schedule, tracing and instrumentation (ftrace, lockdep, etc) would
 * not be advisable either, although may be possible in a pinch, the
 * trace will look odd at least.

Hence adding a vmstat counter looks a plausible and safe option, to at-
least measure the number of slb kernel & user faults in the system.

[1]: https://lore.kernel.org/all/[email protected]/


Cc: Madhavan Srinivasan <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Nicholas Piggin <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Donet Tom <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Ritesh Harjani (IBM) <[email protected]>
---
 arch/powerpc/mm/book3s64/slb.c | 3 +++
 include/linux/vm_event_item.h  | 4 ++++
 mm/vmstat.c                    | 5 +++++
 3 files changed, 12 insertions(+)

diff --git a/arch/powerpc/mm/book3s64/slb.c b/arch/powerpc/mm/book3s64/slb.c
index 297ab0e93c1e..064427af63f7 100644
--- a/arch/powerpc/mm/book3s64/slb.c
+++ b/arch/powerpc/mm/book3s64/slb.c
@@ -22,6 +22,7 @@
 #include <linux/context_tracking.h>
 #include <linux/mm_types.h>
 #include <linux/pgtable.h>
+#include <linux/vmstat.h>

 #include <asm/udbg.h>
 #include <asm/text-patching.h>
@@ -780,6 +781,7 @@ DEFINE_INTERRUPT_HANDLER_RAW(do_slb_fault)
 #ifdef CONFIG_DEBUG_VM
                local_paca->in_kernel_slb_handler = 0;
 #endif
+               count_vm_event(SLB_KERNEL_FAULTS);
                return err;
        } else {
                struct mm_struct *mm = current->mm;
@@ -792,6 +794,7 @@ DEFINE_INTERRUPT_HANDLER_RAW(do_slb_fault)
                if (!err)
                        preload_add(current_thread_info(), ea);

+               count_vm_event(SLB_USER_FAULTS);
                return err;
        }
 }
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 9e15a088ba38..8aa34d0eee3b 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -156,6 +156,10 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
                DIRECT_MAP_LEVEL2_COLLAPSE,
                DIRECT_MAP_LEVEL3_COLLAPSE,
 #endif
+#ifdef CONFIG_PPC_BOOK3S_64
+               SLB_KERNEL_FAULTS,
+               SLB_USER_FAULTS,
+#endif
 #ifdef CONFIG_PER_VMA_LOCK_STATS
                VMA_LOCK_SUCCESS,
                VMA_LOCK_ABORT,
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 71cd1ceba191..8cd17a5fc72b 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1464,6 +1464,11 @@ const char * const vmstat_text[] = {
        [I(DIRECT_MAP_LEVEL2_COLLAPSE)]         = "direct_map_level2_collapses",
        [I(DIRECT_MAP_LEVEL3_COLLAPSE)]         = "direct_map_level3_collapses",
 #endif
+#ifdef CONFIG_PPC_BOOK3S_64
+       "slb_kernel_faults",
+       "slb_user_faults",
+#endif
+
 #ifdef CONFIG_PER_VMA_LOCK_STATS
        [I(VMA_LOCK_SUCCESS)]                   = "vma_lock_success",
        [I(VMA_LOCK_ABORT)]                     = "vma_lock_abort",
--
2.50.1


Reply via email to