linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm/madvise: add vmstat statistics for madvise_[cold|pageout]
@ 2023-01-25  0:54 Minchan Kim
  2023-01-25  8:04 ` Michal Hocko
  0 siblings, 1 reply; 15+ messages in thread
From: Minchan Kim @ 2023-01-25  0:54 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Suren Baghdasaryan, Matthew Wilcox, linux-mm, LKML, Michal Hocko,
	Minchan Kim

madvise LRU manipulation APIs need to scan address ranges to find
present pages at page table and provides advice hints for them.

Likewise pg[scan/steal] count on vmstat, madvise_pg[scanned/hinted]
shows the proactive reclaim efficiency so this patch adds those
two statistics in vmstat.

	madvise_pgscanned, madvise_pghinted

Since proactive reclaim using process_madvise(2) as userland
memory policy is popular(e.g,. Android ActivityManagerService),
those stats are helpful to know how efficiently the policy works
well.

Signed-off-by: Minchan Kim <minchan@kernel.org>
---

* From v1 - https://lore.kernel.org/linux-mm/20230117231632.2734737-1-minchan@kernel.org/
  * not relying on the pageout for accounting - mhocko
  * drop unnecessary changes - mhocko
  
 include/linux/vm_event_item.h | 2 ++
 mm/madvise.c                  | 8 ++++++++
 mm/vmstat.c                   | 2 ++
 3 files changed, 12 insertions(+)

diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 7f5d1caf5890..3c117858946d 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -52,6 +52,8 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 		PGSCAN_FILE,
 		PGSTEAL_ANON,
 		PGSTEAL_FILE,
+		MADVISE_PGSCANNED,
+		MADVISE_PGHINTED,
 #ifdef CONFIG_NUMA
 		PGSCAN_ZONE_RECLAIM_FAILED,
 #endif
diff --git a/mm/madvise.c b/mm/madvise.c
index 7db6622f8293..d2624e77f729 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -344,6 +344,8 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 	spinlock_t *ptl;
 	struct folio *folio = NULL;
 	LIST_HEAD(folio_list);
+	unsigned int nr_scanned = 0;
+	unsigned int nr_hinted = 0;
 	bool pageout_anon_only_filter;
 
 	if (fatal_signal_pending(current))
@@ -357,6 +359,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 		pmd_t orig_pmd;
 		unsigned long next = pmd_addr_end(addr, end);
 
+		nr_scanned += HPAGE_PMD_NR;
 		tlb_change_page_size(tlb, HPAGE_PMD_SIZE);
 		ptl = pmd_trans_huge_lock(pmd, vma);
 		if (!ptl)
@@ -414,6 +417,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 			}
 		} else
 			folio_deactivate(folio);
+		nr_hinted += HPAGE_PMD_NR;
 huge_unlock:
 		spin_unlock(ptl);
 		if (pageout)
@@ -431,6 +435,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 	arch_enter_lazy_mmu_mode();
 	for (; addr < end; pte++, addr += PAGE_SIZE) {
 		ptent = *pte;
+		nr_scanned++;
 
 		if (pte_none(ptent))
 			continue;
@@ -508,6 +513,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 			}
 		} else
 			folio_deactivate(folio);
+		nr_hinted++;
 	}
 
 	arch_leave_lazy_mmu_mode();
@@ -515,6 +521,8 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 	if (pageout)
 		reclaim_pages(&folio_list);
 	cond_resched();
+	count_vm_events(MADVISE_PGSCANNED, nr_scanned);
+	count_vm_events(MADVISE_PGHINTED, nr_hinted);
 
 	return 0;
 }
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 1ea6a5ce1c41..84acc90820e1 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1283,6 +1283,8 @@ const char * const vmstat_text[] = {
 	"pgscan_file",
 	"pgsteal_anon",
 	"pgsteal_file",
+	"madvise_pgscanned",
+	"madvise_pghinted",
 
 #ifdef CONFIG_NUMA
 	"zone_reclaim_failed",
-- 
2.39.1.405.gd4c25cc71f-goog



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

end of thread, other threads:[~2023-01-30 11:12 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-25  0:54 [PATCH v2] mm/madvise: add vmstat statistics for madvise_[cold|pageout] Minchan Kim
2023-01-25  8:04 ` Michal Hocko
2023-01-25 16:36   ` Minchan Kim
2023-01-25 17:07     ` Michal Hocko
2023-01-25 18:07       ` Minchan Kim
2023-01-25 21:37         ` Michal Hocko
2023-01-25 22:21           ` Minchan Kim
2023-01-26  8:50             ` Michal Hocko
2023-01-26  8:51               ` Michal Hocko
2023-01-26 17:10               ` Minchan Kim
2023-01-26 19:58                 ` Michal Hocko
2023-01-27  0:08                   ` Minchan Kim
2023-01-27  9:48                     ` Michal Hocko
2023-01-28  3:00                       ` Minchan Kim
2023-01-30 11:12                         ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox