[Devel] [PATCH vz9 10/16] mm: memcontrol: add swapin/out stats

Nikita Yushchenko nikita.yushchenko at virtuozzo.com
Wed Sep 29 10:00:11 MSK 2021


From: Vladimir Davydov <vdavydov at virtuozzo.com>

This patch adds pswpin and pswpout fields to memory.stat file. These
fields show the number of pages swapped in and out respectively for the
given memory cgroup. We assume a page was swapped in/out even if there
were no actual io (frontswap).

https://jira.sw.ru/browse/PSBM-46104

Signed-off-by: Vladimir Davydov <vdavydov at virtuozzo.com>
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>

Rebase to RHEL8.3 kernel-4.18.0-240.1.1.el8_3 notes:
khorenko@: fixed mem_cgroup_swapout() to charge "nr_entries", not always
1 page.

Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>

(cherry-picked from vz8 commit 09af291ddfd8 ("mm: memcontrol: add
swapin/out stats"))

Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
---
 mm/memcontrol.c | 3 +++
 mm/page_io.c    | 5 ++++-
 mm/vmstat.c     | 2 ++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 47384b7fce0a..65dec706430d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4118,6 +4118,8 @@ static const unsigned int memcg1_events[] = {
 	PGPGOUT,
 	PGFAULT,
 	PGMAJFAULT,
+	PSWPIN,
+	PSWPOUT,
 };
 
 static int memcg_stat_show(struct seq_file *m, void *v)
@@ -7408,6 +7410,7 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry)
 				   nr_entries);
 	VM_BUG_ON_PAGE(oldid, page);
 	mod_memcg_state(swap_memcg, MEMCG_SWAP, nr_entries);
+	__count_memcg_events(swap_memcg, PSWPOUT, nr_entries);
 
 	page->memcg_data = 0;
 
diff --git a/mm/page_io.c b/mm/page_io.c
index c493ce9ebcf5..ea3ba397b33f 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -384,8 +384,10 @@ int swap_readpage(struct page *page, bool synchronous)
 		struct address_space *mapping = swap_file->f_mapping;
 
 		ret = mapping->a_ops->readpage(swap_file, page);
-		if (!ret)
+		if (!ret) {
+			count_memcg_page_event(page, PSWPIN);
 			count_vm_event(PSWPIN);
+		}
 		goto out;
 	}
 
@@ -397,6 +399,7 @@ int swap_readpage(struct page *page, bool synchronous)
 				unlock_page(page);
 			}
 
+			count_memcg_page_event(page, PSWPIN);
 			count_vm_event(PSWPIN);
 			goto out;
 		}
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 44ce039d19c6..0ed75620f8f2 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1211,6 +1211,8 @@ const char * const vmstat_text[] = {
 
 	"pgfault",
 	"pgmajfault",
+	"pswpin",
+	"pswpout",
 	"pglazyfreed",
 
 	"pgrefill",
-- 
2.30.2



More information about the Devel mailing list