linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/khugepaged: add tracepoint to collapse_file()
@ 2022-10-24 15:09 Gautam Menghani
  2022-10-24 15:16 ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Gautam Menghani @ 2022-10-24 15:09 UTC (permalink / raw)
  To: akpm, rostedt, mhiramat, zokeefe, shy828301, vbabka, david
  Cc: Gautam Menghani, linux-mm, linux-kernel

In the file mm/khugepaged.c, a TODO in the function collapse_file() asks
to add tracepoints. Add the tracepoint named "mm_khugepaged_scan_file".

Signed-off-by: Gautam Menghani <gautammenghani201@gmail.com>
---
 include/trace/events/huge_memory.h | 32 ++++++++++++++++++++++++++++++
 mm/khugepaged.c                    |  4 +++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/include/trace/events/huge_memory.h b/include/trace/events/huge_memory.h
index 935af4947917..b2f3157d2ff6 100644
--- a/include/trace/events/huge_memory.h
+++ b/include/trace/events/huge_memory.h
@@ -203,5 +203,37 @@ TRACE_EVENT(mm_khugepaged_scan_file,
 		__print_symbolic(__entry->result, SCAN_STATUS))
 );
 
+TRACE_EVENT(mm_khugepaged_collapse_file,
+	TP_PROTO(struct mm_struct *mm, struct page *hpage,
+			unsigned long addr, const char *filename, int nr,
+			int result),
+	TP_ARGS(mm, hpage, addr, filename, nr, result),
+	TP_STRUCT__entry(
+		__field(struct mm_struct *, mm)
+		__field(unsigned long, hpfn)
+		__field(unsigned long, addr)
+		__string(filename, filename)
+		__field(int, nr)
+		__field(int, result)
+	),
+
+	TP_fast_assign(
+		__entry->mm = mm;
+		__entry->hpfn = hpage ? page_to_pfn(hpage) : -1;
+		__entry->addr = addr;
+		__assign_str(filename, filename);
+		__entry->nr = nr;
+		__entry->result = result;
+	),
+
+	TP_printk("mm=%p, hpage_pfn=0x%lx, addr=%ld, filename=%s, nr=%d, result=%s",
+		__entry->mm,
+		__entry->hpfn,
+		__entry->addr,
+		__get_str(filename),
+		__entry->nr,
+		__print_symbolic(__entry->result, SCAN_STATUS))
+);
+
 #endif /* __HUGE_MEMORY_H */
 #include <trace/define_trace.h>
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 4734315f7940..14db90e2f2ec 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -2059,7 +2059,9 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
 		mem_cgroup_uncharge(page_folio(hpage));
 		put_page(hpage);
 	}
-	/* TODO: tracepoints */
+
+	trace_mm_khugepaged_collapse_file(mm, hpage, addr, file->f_path.dentry->d_iname,
+				      nr, result);
 	return result;
 }
 
-- 
2.34.1



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

* Re: [PATCH] mm/khugepaged: add tracepoint to collapse_file()
  2022-10-24 15:09 [PATCH] mm/khugepaged: add tracepoint to collapse_file() Gautam Menghani
@ 2022-10-24 15:16 ` Steven Rostedt
  2022-10-24 16:44   ` Zach O'Keefe
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2022-10-24 15:16 UTC (permalink / raw)
  To: Gautam Menghani
  Cc: akpm, mhiramat, zokeefe, shy828301, vbabka, david, linux-mm,
	linux-kernel

On Mon, 24 Oct 2022 20:39:22 +0530
Gautam Menghani <gautammenghani201@gmail.com> wrote:

> +TRACE_EVENT(mm_khugepaged_collapse_file,
> +	TP_PROTO(struct mm_struct *mm, struct page *hpage,
> +			unsigned long addr, const char *filename, int nr,
> +			int result),
> +	TP_ARGS(mm, hpage, addr, filename, nr, result),
> +	TP_STRUCT__entry(
> +		__field(struct mm_struct *, mm)
> +		__field(unsigned long, hpfn)
> +		__field(unsigned long, addr)
> +		__string(filename, filename)
> +		__field(int, nr)
> +		__field(int, result)
> +	),
> +
> +	TP_fast_assign(
> +		__entry->mm = mm;
> +		__entry->hpfn = hpage ? page_to_pfn(hpage) : -1;
> +		__entry->addr = addr;
> +		__assign_str(filename, filename);
> +		__entry->nr = nr;
> +		__entry->result = result;
> +	),
> +
> +	TP_printk("mm=%p, hpage_pfn=0x%lx, addr=%ld, filename=%s, nr=%d, result=%s",
> +		__entry->mm,
> +		__entry->hpfn,
> +		__entry->addr,
> +		__get_str(filename),
> +		__entry->nr,
> +		__print_symbolic(__entry->result, SCAN_STATUS))
> +);
> +
>  #endif /* __HUGE_MEMORY_H */
>  #include <trace/define_trace.h>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 4734315f7940..14db90e2f2ec 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -2059,7 +2059,9 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
>  		mem_cgroup_uncharge(page_folio(hpage));
>  		put_page(hpage);
>  	}
> -	/* TODO: tracepoints */
> +
> +	trace_mm_khugepaged_collapse_file(mm, hpage, addr, file->f_path.dentry->d_iname,

I try to keep dereferences out of the calling path as much as possible
(adds to I$ at the call site).

Could you just pass in file, and then have:

	__string(filename, file->f_path.dentry->d_iname)

	[..]

	__assign_string(filename, file->f_path.dentry->d_iname);


If you are paranoid, you can have the above also be:

			file ? file->f_path.dentry ? file->f_path.dentry->d_iname : "(null)" : "(null)")


-- Steve


> +				      nr, result);
>  	return result;


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

* Re: [PATCH] mm/khugepaged: add tracepoint to collapse_file()
  2022-10-24 15:16 ` Steven Rostedt
@ 2022-10-24 16:44   ` Zach O'Keefe
  2022-10-24 17:38     ` Gautam Menghani
  0 siblings, 1 reply; 4+ messages in thread
From: Zach O'Keefe @ 2022-10-24 16:44 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Gautam Menghani, akpm, mhiramat, shy828301, vbabka, david,
	linux-mm, linux-kernel

Thanks for your mail, Gautam.

> I try to keep dereferences out of the calling path as much as possible
> (adds to I$ at the call site).

This was probably due to the way I handled
trace_mm_khugepaged_scan_file(). Perhaps that can be cleaned up at the
same time as this patch, for consistency.

Also, no qualms about adding this tracepoint; there are a few scan
result codes that overlap between hpage_collapse_scan_file() and those
possibly returned in collapse_file() such that, if we only have the
one tracepoint in hpage_collapse_scan_file(), it could be ambiguous
what callsite the error path stemmed from. Luckily this hasn't been an
issue thus far.

Lastly, a few other items we might care about capturing:

- is_shmem (perhaps the filename is enough to know this - but I know
at least once during development I was caught off-guard b/c a mount I
thought to be file-backed turned out to be tmpfs (and something I
didn't think to question until I had wasted some time on other
paths)).
- index

Best,
Zach


> Could you just pass in file, and then have:
>
>         __string(filename, file->f_path.dentry->d_iname)
>
>         [..]
>
>         __assign_string(filename, file->f_path.dentry->d_iname);
>
>
> If you are paranoid, you can have the above also be:
>
>                         file ? file->f_path.dentry ? file->f_path.dentry->d_iname : "(null)" : "(null)")
>
>
> -- Steve
>
>
> > +                                   nr, result);
> >       return result;


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

* Re: [PATCH] mm/khugepaged: add tracepoint to collapse_file()
  2022-10-24 16:44   ` Zach O'Keefe
@ 2022-10-24 17:38     ` Gautam Menghani
  0 siblings, 0 replies; 4+ messages in thread
From: Gautam Menghani @ 2022-10-24 17:38 UTC (permalink / raw)
  To: Zach O'Keefe
  Cc: Steven Rostedt, akpm, mhiramat, shy828301, vbabka, david,
	linux-mm, linux-kernel

On Mon, Oct 24, 2022 at 09:44:16AM -0700, Zach O'Keefe wrote:
> Thanks for your mail, Gautam.
> 
> > I try to keep dereferences out of the calling path as much as possible
> > (adds to I$ at the call site).
> 
> This was probably due to the way I handled
> trace_mm_khugepaged_scan_file(). Perhaps that can be cleaned up at the
> same time as this patch, for consistency.
>
Yes sure I'll send a patch for cleaning this up.
 
> Also, no qualms about adding this tracepoint; there are a few scan
> result codes that overlap between hpage_collapse_scan_file() and those
> possibly returned in collapse_file() such that, if we only have the
> one tracepoint in hpage_collapse_scan_file(), it could be ambiguous
> what callsite the error path stemmed from. Luckily this hasn't been an
> issue thus far.
> 
> Lastly, a few other items we might care about capturing:
> 
> - is_shmem (perhaps the filename is enough to know this - but I know
> at least once during development I was caught off-guard b/c a mount I
> thought to be file-backed turned out to be tmpfs (and something I
> didn't think to question until I had wasted some time on other
> paths)).
> - index

Yes noted.  


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

end of thread, other threads:[~2022-10-24 17:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-24 15:09 [PATCH] mm/khugepaged: add tracepoint to collapse_file() Gautam Menghani
2022-10-24 15:16 ` Steven Rostedt
2022-10-24 16:44   ` Zach O'Keefe
2022-10-24 17:38     ` Gautam Menghani

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).