linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC 8/8] powerpc/book3s64/slb: Add slb faults to vmstat
       [not found] <cover.1756522067.git.ritesh.list@gmail.com>
@ 2025-08-30  3:51 ` Ritesh Harjani (IBM)
  2025-08-30  4:45   ` Stephen Rothwell
  0 siblings, 1 reply; 3+ messages in thread
From: Ritesh Harjani (IBM) @ 2025-08-30  3:51 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Ritesh Harjani (IBM), Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy, Donet Tom, Andrew Morton,
	David Hildenbrand, Lorenzo Stoakes, linux-kernel, linux-mm

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/20181013131836.26764-4-mpe@ellerman.id.au/


Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Donet Tom <donettom@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
 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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC 8/8] powerpc/book3s64/slb: Add slb faults to vmstat
  2025-08-30  3:51 ` [RFC 8/8] powerpc/book3s64/slb: Add slb faults to vmstat Ritesh Harjani (IBM)
@ 2025-08-30  4:45   ` Stephen Rothwell
  2025-08-30  4:56     ` Ritesh Harjani
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Rothwell @ 2025-08-30  4:45 UTC (permalink / raw)
  To: Ritesh Harjani (IBM)
  Cc: linuxppc-dev, Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy, Donet Tom, Andrew Morton,
	David Hildenbrand, Lorenzo Stoakes, linux-kernel, linux-mm

[-- Attachment #1: Type: text/plain, Size: 776 bytes --]

Hi Ritesh,

On Sat, 30 Aug 2025 09:21:47 +0530 "Ritesh Harjani (IBM)" <ritesh.list@gmail.com> wrote:
>
> 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",

Should you be using explicit indexes and the I() macro?

-- 
Cheers,
Stephen Rothwell

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC 8/8] powerpc/book3s64/slb: Add slb faults to vmstat
  2025-08-30  4:45   ` Stephen Rothwell
@ 2025-08-30  4:56     ` Ritesh Harjani
  0 siblings, 0 replies; 3+ messages in thread
From: Ritesh Harjani @ 2025-08-30  4:56 UTC (permalink / raw)
  To: Stephen Rothwell
  Cc: linuxppc-dev, Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy, Donet Tom, Andrew Morton,
	David Hildenbrand, Lorenzo Stoakes, linux-kernel, linux-mm

Stephen Rothwell <sfr@canb.auug.org.au> writes:

> Hi Ritesh,
>
> On Sat, 30 Aug 2025 09:21:47 +0530 "Ritesh Harjani (IBM)" <ritesh.list@gmail.com> wrote:
>>
>> 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",
>
> Should you be using explicit indexes and the I() macro?

Aah yes, I guess the branch where I developed the patches was not
upstream tip and when I rebased and tested, I missed to see the I()
macro change in mm/vmstat. 

Thanks Stephen for pointing it out. I will fix that in the next revision.

-ritesh

>
> -- 
> Cheers,
> Stephen Rothwell


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-30  4:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1756522067.git.ritesh.list@gmail.com>
2025-08-30  3:51 ` [RFC 8/8] powerpc/book3s64/slb: Add slb faults to vmstat Ritesh Harjani (IBM)
2025-08-30  4:45   ` Stephen Rothwell
2025-08-30  4:56     ` Ritesh Harjani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).