Skip to contentSkip to conversation

mm/migration: Add trace events for THP migrations

RFC In review Anshuman Khandual 2 participants 3 messages Dec 24, 2021 – Jan 3, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 mm/migration: Add trace events for THP migrations

This adds two trace events for PMD based THP migration without split. These events closely follow the implementation details like setting and removing of PMD migration entries, which are essential operations for THP migration.

Cc Steven Rostedt <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Zi Yan <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc John Hubbard <[email protected]>

---
This applies on v5.16-rc6

 include/trace/events/thp.h | 61 ++++++++++++++++++++++++++++++++++++++
 mm/huge_memory.c           |  5 ++++
 2 files changed, 66 insertions(+)
include/trace/events/thp.h +61 -0
index d7fbbe551841..be5aeb783af1 100644
@@ -83,6 +83,67 @@ TRACE_EVENT(hugepage_splitting,
 		      __entry->addr, __entry->pte)
 );
 
+TRACE_EVENT(set_migration_pmd,
+
+	TP_PROTO(struct mm_struct *mm, unsigned long address,
+		 pmd_t *pmdp, struct page *page, unsigned long pmdval),
+
+	TP_ARGS(mm, address, pmdp, page, pmdval),
+
+	TP_STRUCT__entry(
+		__field(struct mm_struct *, mm)
+		__field(unsigned long, address)
+		__field(pmd_t *, pmdp)
+		__field(struct page *, page)
+		__field(unsigned long, pmdval)
+	),
+
+	TP_fast_assign(
+		__entry->mm = mm;
+		__entry->address = address;
+		__entry->pmdp = pmdp;
+		__entry->page = page;
+		__entry->pmdval = pmdval;
+	),
+
+	TP_printk("mm=%p, address=%lx, pmdp=%p, page=%p pmdval=%lx",
+		__entry->mm,
+		__entry->address,
+		__entry->pmdp,
+		__entry->page,
+		__entry->pmdval)
+);
+
+TRACE_EVENT(remove_migration_pmd,
+
+	TP_PROTO(struct mm_struct *mm, unsigned long address,
+		 pmd_t *pmdp, struct page *page, unsigned long pmdval),
+
+	TP_ARGS(mm, address, pmdp, page, pmdval),
+
+	TP_STRUCT__entry(
+		__field(struct mm_struct *, mm)
+		__field(unsigned long, address)
+		__field(pmd_t *, pmdp)
+		__field(struct page *, page)
+		__field(unsigned long, pmdval)
+	),
+
+	TP_fast_assign(
+		__entry->mm = mm;
+		__entry->address = address;
+		__entry->pmdp = pmdp;
+		__entry->page = page;
+		__entry->pmdval = pmdval;
+	),
+
+	TP_printk("mm=%p, address=%lx, pmdp=%p, page=%p pmdval=%lx",
+		__entry->mm,
+		__entry->address,
+		__entry->pmdp,
+		__entry->page,
+		__entry->pmdval)
+);
 #endif /* _TRACE_THP_H */
 
 /* This part must be outside protection */
mm/huge_memory.c +5 -0
index e5483347291c..611de486e095 100644
@@ -39,6 +39,9 @@
 #include <asm/pgalloc.h>
 #include "internal.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/thp.h>
+
 /*
  * By default, transparent hugepage support is disabled in order to avoid
  * risking an increased memory footprint for applications that are not
@@ -3173,6 +3176,7 @@ void set_pmd_migration_entry(struct page_vma_mapped_walk *pvmw,
 	set_pmd_at(mm, address, pvmw->pmd, pmdswp);
 	page_remove_rmap(page, true);
 	put_page(page);
+	trace_set_migration_pmd(mm, address, pvmw->pmd, page, pmd_val(pmdswp));
 }
 
 void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new)
@@ -3206,5 +3210,6 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new)
 	if ((vma->vm_flags & VM_LOCKED) && !PageDoubleMap(new))
 		mlock_vma_page(new);
 	update_mmu_cache_pmd(vma, address, pvmw->pmd);
+	trace_remove_migration_pmd(mm, address, pvmw->pmd, new, pmd_val(pmde));
 }
 #endif
Signature · 1 line
2.20.1
#1 lore raw
Quoted 3 lines · Anshuman Khandual

This adds two trace events for PMD based THP migration without split. These events closely follow the implementation details like setting and removing of PMD migration entries, which are essential operations for THP migration.

Why are you printing the address of a struct page? What useful information does this supply? Same question for the struct mm. And the pmdp, for that matter.

You haven't said _why_ you want these tracepoints. So it's impossible to suggest what you _should_ be doing, because what you _are_ doing is obviously wrong.

Quoted 7 lines
include/trace/events/thp.h +7 -0
+	TP_printk("mm=%p, address=%lx, pmdp=%p, page=%p pmdval=%lx",
+		__entry->mm,
+		__entry->address,
+		__entry->pmdp,
+		__entry->page,
+		__entry->pmdval)
+);
#2 lore raw

Hello Matthew,

Quoted 8 lines · Matthew Wilcox
Quoted 3 lines · Anshuman Khandual

This adds two trace events for PMD based THP migration without split. These events closely follow the implementation details like setting and removing of PMD migration entries, which are essential operations for THP migration.

Why are you printing the address of a struct page? What useful information does this supply? Same question for the struct mm. And the pmdp, for that matter.

Just to make individual trace records comprehensive enough to capture which (and where) the PMD entries went through migration entry state. But is there any particular concern here capturing mm, page and pmdp ?

Quoted 4 lines

You haven't said _why_ you want these tracepoints. So it's impossible to suggest what you _should_ be doing, because what you _are_ doing is obviously wrong.

Just for debug purpose. To see which (and where) PMD entries are being migrated as is without a split, via PMD migration entries. Wondering if you are suggesting just to capture addr, pmdval and just drop others ?

Quoted 9 lines

include/trace/events/thp.h TRACE_EVENT(hugepage_splitting, · line 115

Quoted 8 lines
include/trace/events/thp.h +7 -0
+	TP_printk("mm=%p, address=%lx, pmdp=%p, page=%p pmdval=%lx",
+		__entry->mm,
+		__entry->address,
+		__entry->pmdp,
+		__entry->page,
+		__entry->pmdval)
+);

- Anshuman