[RFC PATCH V1 11/13] vmstat: Add vmstat counters
From: Raghavendra K T
Date: Wed Mar 19 2025 - 15:36:19 EST
Add vmstat counter to track scanning, migration and
type of pages.
Signed-off-by: Raghavendra K T <raghavendra.kt@xxxxxxx>
---
include/linux/mm.h | 11 ++++++++
include/linux/vm_event_item.h | 10 +++++++
mm/kmmscand.c | 52 ++++++++++++++++++++++++++++++++++-
mm/vmstat.c | 10 +++++++
4 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7b1068ddcbb7..e40a38c28a63 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -682,6 +682,17 @@ struct vm_operations_struct {
unsigned long addr);
};
+#ifdef CONFIG_KMMSCAND
+void count_kmmscand_mm_scans(void);
+void count_kmmscand_vma_scans(void);
+void count_kmmscand_migadded(void);
+void count_kmmscand_migrated(void);
+void count_kmmscand_migrate_failed(void);
+void count_kmmscand_slowtier(void);
+void count_kmmscand_toptier(void);
+void count_kmmscand_idlepage(void);
+#endif
+
#ifdef CONFIG_NUMA_BALANCING
static inline void vma_numab_state_init(struct vm_area_struct *vma)
{
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index f70d0958095c..b2ccd4f665aa 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -65,6 +65,16 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
NUMA_HINT_FAULTS_LOCAL,
NUMA_PAGE_MIGRATE,
#endif
+#ifdef CONFIG_KMMSCAND
+ KMMSCAND_MM_SCANS,
+ KMMSCAND_VMA_SCANS,
+ KMMSCAND_MIGADDED,
+ KMMSCAND_MIGRATED,
+ KMMSCAND_MIGRATE_FAILED,
+ KMMSCAND_SLOWTIER,
+ KMMSCAND_TOPTIER,
+ KMMSCAND_IDLEPAGE,
+#endif
#ifdef CONFIG_MIGRATION
PGMIGRATE_SUCCESS, PGMIGRATE_FAIL,
THP_MIGRATION_SUCCESS,
diff --git a/mm/kmmscand.c b/mm/kmmscand.c
index 618594d7c148..c88b30e0fc7d 100644
--- a/mm/kmmscand.c
+++ b/mm/kmmscand.c
@@ -323,6 +323,39 @@ struct attribute_group kmmscand_attr_group = {
};
#endif
+void count_kmmscand_mm_scans(void)
+{
+ count_vm_numa_event(KMMSCAND_MM_SCANS);
+}
+void count_kmmscand_vma_scans(void)
+{
+ count_vm_numa_event(KMMSCAND_VMA_SCANS);
+}
+void count_kmmscand_migadded(void)
+{
+ count_vm_numa_event(KMMSCAND_MIGADDED);
+}
+void count_kmmscand_migrated(void)
+{
+ count_vm_numa_event(KMMSCAND_MIGRATED);
+}
+void count_kmmscand_migrate_failed(void)
+{
+ count_vm_numa_event(KMMSCAND_MIGRATE_FAILED);
+}
+void count_kmmscand_slowtier(void)
+{
+ count_vm_numa_event(KMMSCAND_SLOWTIER);
+}
+void count_kmmscand_toptier(void)
+{
+ count_vm_numa_event(KMMSCAND_TOPTIER);
+}
+void count_kmmscand_idlepage(void)
+{
+ count_vm_numa_event(KMMSCAND_IDLEPAGE);
+}
+
static int kmmscand_has_work(void)
{
return !list_empty(&kmmscand_scan.mm_head);
@@ -769,6 +802,9 @@ static int hot_vma_idle_pte_entry(pte_t *pte,
return 0;
}
+ if (node_is_toptier(srcnid))
+ count_kmmscand_toptier();
+
if (!folio_test_idle(folio) || folio_test_young(folio) ||
mmu_notifier_test_young(mm, addr) ||
folio_test_referenced(folio) || pte_young(pteval)) {
@@ -784,14 +820,18 @@ static int hot_vma_idle_pte_entry(pte_t *pte,
info = kzalloc(sizeof(struct kmmscand_migrate_info), GFP_NOWAIT);
if (info && scanctrl) {
+ count_kmmscand_slowtier();
info->mm = mm;
info->address = addr;
info->folio = folio;
/* No need of lock now */
list_add_tail(&info->migrate_node, &scanctrl->scan_list);
+
+ count_kmmscand_migadded();
}
- }
+ } else
+ count_kmmscand_idlepage();
folio_set_idle(folio);
folio_put(folio);
@@ -907,6 +947,12 @@ static void kmmscand_migrate_folio(void)
ret = kmmscand_promote_folio(info, dest);
}
+ /* TBD: encode migrated count here, currently assume folio_nr_pages */
+ if (!ret)
+ count_kmmscand_migrated();
+ else
+ count_kmmscand_migrate_failed();
+
kfree(info);
spin_lock(&kmmscand_migrate_lock);
@@ -1083,6 +1129,7 @@ static unsigned long kmmscand_scan_mm_slot(void)
for_each_vma(vmi, vma) {
kmmscand_walk_page_vma(vma, &kmmscand_scanctrl);
+ count_kmmscand_vma_scans();
vma_scanned_size += vma->vm_end - vma->vm_start;
if (vma_scanned_size >= mm_slot_scan_size ||
@@ -1108,6 +1155,8 @@ static unsigned long kmmscand_scan_mm_slot(void)
update_mmslot_info = true;
+ count_kmmscand_mm_scans();
+
total = get_slowtier_accesed(&kmmscand_scanctrl);
target_node = get_target_node(&kmmscand_scanctrl);
@@ -1123,6 +1172,7 @@ static unsigned long kmmscand_scan_mm_slot(void)
kmmscand_update_mmslot_info(mm_slot, total, target_node);
}
+
outerloop:
/* exit_mmap will destroy ptes after this */
mmap_read_unlock(mm);
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 16bfe1c694dd..3a6fa834ebe0 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1340,6 +1340,16 @@ const char * const vmstat_text[] = {
"numa_hint_faults_local",
"numa_pages_migrated",
#endif
+#ifdef CONFIG_KMMSCAND
+ "nr_kmmscand_mm_scans",
+ "nr_kmmscand_vma_scans",
+ "nr_kmmscand_migadded",
+ "nr_kmmscand_migrated",
+ "nr_kmmscand_migrate_failed",
+ "nr_kmmscand_slowtier",
+ "nr_kmmscand_toptier",
+ "nr_kmmscand_idlepage",
+#endif
#ifdef CONFIG_MIGRATION
"pgmigrate_success",
"pgmigrate_fail",
--
2.34.1