[PATCH 3/3] mm: add vmstat statistics for madvise_[cold|pageout]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 addes those
two statistics in vmstat.

Signed-off-by: Minchan Kim <minchan@xxxxxxxxxx>
---
 include/linux/vm_event_item.h |  2 ++
 mm/madvise.c                  | 19 +++++++++++++++----
 mm/vmstat.c                   |  2 ++
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 3518dba1e02f..8b9fb2e151eb 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -49,6 +49,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 a4a03054ab6b..0e58545ff6e9 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -334,6 +334,8 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 	spinlock_t *ptl;
 	struct page *page = NULL;
 	LIST_HEAD(page_list);
+	unsigned int nr_scanned = 0;
+	unsigned int nr_hinted = 0;
 
 	if (fatal_signal_pending(current))
 		return -EINTR;
@@ -343,6 +345,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)
@@ -396,11 +399,15 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 					list_add(&page->lru, &page_list);
 			}
 		} else
-			deactivate_page(page);
+			if (deactivate_page(page))
+				nr_hinted += HPAGE_PMD_NR;
 huge_unlock:
 		spin_unlock(ptl);
 		if (pageout)
-			paging_out(&page_list);
+			nr_hinted += paging_out(&page_list);
+
+		count_vm_events(MADVISE_PGSCANNED, nr_scanned);
+		count_vm_events(MADVISE_PGHINTED, nr_hinted);
 		return 0;
 	}
 
@@ -414,6 +421,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;
@@ -485,14 +493,17 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
 					list_add(&page->lru, &page_list);
 			}
 		} else
-			deactivate_page(page);
+			if (deactivate_page(page))
+				nr_hinted++;
 	}
 
 	arch_leave_lazy_mmu_mode();
 	pte_unmap_unlock(orig_pte, ptl);
 	if (pageout)
-		paging_out(&page_list);
+		nr_hinted += paging_out(&page_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 b2371d745e00..0139feade854 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1280,6 +1280,8 @@ const char * const vmstat_text[] = {
 	"pgscan_file",
 	"pgsteal_anon",
 	"pgsteal_file",
+	"madvise_pgscanned",
+	"madvise_pghinted",
 
 #ifdef CONFIG_NUMA
 	"zone_reclaim_failed",
-- 
2.39.0.314.g84b9a713c41-goog





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux