linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Minchan Kim <minchan@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Suren Baghdasaryan <surenb@google.com>,
	Matthew Wilcox <willy@infradead.org>,
	linux-mm <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Michal Hocko <mhocko@suse.com>, SeongJae Park <sj@kernel.org>,
	Minchan Kim <minchan@kernel.org>
Subject: [PATCH 3/3] mm: add vmstat statistics for madvise_[cold|pageout]
Date: Tue, 17 Jan 2023 15:16:32 -0800	[thread overview]
Message-ID: <20230117231632.2734737-3-minchan@kernel.org> (raw)
In-Reply-To: <20230117231632.2734737-1-minchan@kernel.org>

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@kernel.org>
---
 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



  parent reply	other threads:[~2023-01-17 23:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17 23:16 [PATCH 1/3] mm: return the number of pages successfully paged out Minchan Kim
2023-01-17 23:16 ` [PATCH 2/3] mm: return boolean for deactivate_page Minchan Kim
2023-01-17 23:16 ` Minchan Kim [this message]
2023-01-18  9:11   ` [PATCH 3/3] mm: add vmstat statistics for madvise_[cold|pageout] Michal Hocko
2023-01-18 17:15     ` Minchan Kim
2023-01-18 17:27       ` Michal Hocko
2023-01-18 17:55         ` Minchan Kim
2023-01-18 21:13           ` Michal Hocko
2023-01-18 21:47             ` Minchan Kim
2023-01-17 23:53 ` [PATCH 1/3] mm: return the number of pages successfully paged out Andrew Morton
2023-01-18  0:35   ` Minchan Kim
2023-01-18  0:58     ` Matthew Wilcox
2023-01-18  1:49       ` Minchan Kim
2023-01-18  9:10 ` Michal Hocko
2023-01-18 17:09   ` Minchan Kim
2023-01-18 17:35     ` Michal Hocko
2023-01-18 18:07       ` Minchan Kim
2023-01-18 21:23         ` Michal Hocko
2023-01-18 22:27           ` Minchan Kim
2023-01-19  9:07             ` Michal Hocko
2023-01-19 21:15               ` Minchan Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230117231632.2734737-3-minchan@kernel.org \
    --to=minchan@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=sj@kernel.org \
    --cc=surenb@google.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox