[v3] mm/khugepaged: add tracepoint to collapse_file()
Commit Message
Currently, is_shmem is not being captured. Capturing is_shmem is useful
as it can indicate if tmpfs is being used as a backing store instead of
persistent storage. Add the tracepoint in collapse_file() named
"mm_khugepaged_collapse_file" for capturing is_shmem.
Signed-off-by: Gautam Menghani <gautammenghani201@gmail.com>
---
changes in v2:
1. Move filename dereference out of calling path (Steven Rostedt).
2. Capture is_shmem and index (Zach O'Keefe)
changes in v3:
1. Initialize the variables to resolve clang warning.
2. Add more info in changelog.
include/trace/events/huge_memory.h | 38 ++++++++++++++++++++++++++++++
mm/khugepaged.c | 7 +++---
2 files changed, 42 insertions(+), 3 deletions(-)
Comments
On Wed, 26 Oct 2022 10:52:18 +0530
Gautam Menghani <gautammenghani201@gmail.com> wrote:
Ideally we want the trace event structure to be as packed as possible to
not waste space on the ring buffer.
> + TP_ARGS(mm, hpage, index, is_shmem, addr, file, nr, result),
> + TP_STRUCT__entry(
> + __field(struct mm_struct *, mm) 4 / 8 bytes (depending on 32 bit or 64 bit arch)
> + __field(unsigned long, hpfn) 4 / 8 bytes
The two above is fine.
> + __field(pgoff_t, index) 4 / 8 bytes
> + __field(bool, is_shmem) 4 bytes (or less)
> + __field(unsigned long, addr) 4 / 8 bytes
> + __string(filename, file->f_path.dentry->d_iname) 4 bytes
> + __field(int, nr) 4 bytes
> + __field(int, result) 4 bytes
For best packing, it's best to keep long / pointers together, and ints and
bools together (or paired).
On 64 bit archs, there is likely to be a 4 byte hole between is_shmem and
addr.
> + ),
> +
Better to have it be:
TP_STRUCT__entry(
__field(struct mm_struct *, mm)
__field(unsigned long, hpfn)
__field(pgoff_t, index)
__field(unsigned long, addr)
__field(bool, is_shmem)
__string(filename, file->f_path.dentry->d_iname)
__field(int, nr)
__field(int, result)
),
Where I swapped is_shmem and addr.
-- Steve
@@ -203,5 +203,43 @@ 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, pgoff_t index,
+ bool is_shmem, unsigned long addr, struct file *file,
+ int nr, int result),
+ TP_ARGS(mm, hpage, index, is_shmem, addr, file, nr, result),
+ TP_STRUCT__entry(
+ __field(struct mm_struct *, mm)
+ __field(unsigned long, hpfn)
+ __field(pgoff_t, index)
+ __field(bool, is_shmem)
+ __field(unsigned long, addr)
+ __string(filename, file->f_path.dentry->d_iname)
+ __field(int, nr)
+ __field(int, result)
+ ),
+
+ TP_fast_assign(
+ __entry->mm = mm;
+ __entry->hpfn = hpage ? page_to_pfn(hpage) : -1;
+ __entry->index = index;
+ __entry->is_shmem = is_shmem;
+ __entry->addr = addr;
+ __assign_str(filename, file->f_path.dentry->d_iname);
+ __entry->nr = nr;
+ __entry->result = result;
+ ),
+
+ TP_printk("mm=%p, hpage_pfn=0x%lx, index=%ld, is_shmem=%d, addr=%ld, filename=%s, nr=%d, result=%s",
+ __entry->mm,
+ __entry->hpfn,
+ __entry->index,
+ __entry->is_shmem,
+ __entry->addr,
+ __get_str(filename),
+ __entry->nr,
+ __print_symbolic(__entry->result, SCAN_STATUS))
+);
+
#endif /* __HUGE_MEMORY_H */
#include <trace/define_trace.h>
@@ -1702,12 +1702,12 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
{
struct address_space *mapping = file->f_mapping;
struct page *hpage;
- pgoff_t index, end = start + HPAGE_PMD_NR;
+ pgoff_t index = 0, end = start + HPAGE_PMD_NR;
LIST_HEAD(pagelist);
XA_STATE_ORDER(xas, &mapping->i_pages, start, HPAGE_PMD_ORDER);
int nr_none = 0, result = SCAN_SUCCEED;
bool is_shmem = shmem_file(file);
- int nr;
+ int nr = 0;
VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem);
VM_BUG_ON(start & (HPAGE_PMD_NR - 1));
@@ -2059,7 +2059,8 @@ 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, index, is_shmem, addr, file, nr, result);
return result;
}