From: Yosry Ahmed <yosryahmed@google.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeelb@google.com>
Cc: Muchun Song <muchun.song@linux.dev>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
Yu Zhao <yuzhao@google.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Kees Cook <keescook@chromium.org>,
Iurii Zaikin <yzaikin@google.com>,
"T.J. Mercier" <tjmercier@google.com>,
Greg Thelen <gthelen@google.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
cgroups@vger.kernel.org, Yosry Ahmed <yosryahmed@google.com>
Subject: [RFC PATCH 6/8] memcg: add stats for offline memcgs recharging
Date: Thu, 20 Jul 2023 07:08:23 +0000 [thread overview]
Message-ID: <20230720070825.992023-7-yosryahmed@google.com> (raw)
In-Reply-To: <20230720070825.992023-1-yosryahmed@google.com>
Add vm events for scanning pages for recharge, successfully recharging
pages, and cancelling a recharge due to failure to charge the target
memcg.
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
---
include/linux/vm_event_item.h | 5 +++++
mm/memcontrol.c | 6 ++++++
mm/vmstat.c | 6 +++++-
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 8abfa1240040..cd80c00c50c2 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -60,6 +60,11 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
PAGEOUTRUN, PGROTATED,
DROP_PAGECACHE, DROP_SLAB,
OOM_KILL,
+#ifdef CONFIG_MEMCG
+ RECHARGE_PGSCANNED,
+ RECHARGE_PGMOVED,
+ RECHARGE_PGCANCELLED,
+#endif
#ifdef CONFIG_NUMA_BALANCING
NUMA_PTE_UPDATES,
NUMA_HUGE_PTE_UPDATES,
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index cf9fb51ecfcc..2fe9c6f1be80 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6394,6 +6394,8 @@ static bool mem_cgroup_recharge_folio(struct folio *folio,
old_memcg, new_memcg);
cancel_charge(err ? new_memcg : old_memcg, nr_pages);
out:
+ count_vm_events(err ? RECHARGE_PGCANCELLED : RECHARGE_PGMOVED,
+ nr_pages);
return err == 0;
}
@@ -6469,6 +6471,7 @@ static bool memcg_recharge_lruvec_list(struct lruvec *lruvec,
int isolated_idx = NR_ISOLATED_ANON + is_file_lru(lru);
struct mem_cgroup *memcg = lruvec_memcg(lruvec);
unsigned long *nr_recharged = arg;
+ unsigned long nr_scanned = 0;
unsigned long nr_staged = 0;
LIST_HEAD(folios_skipped);
LIST_HEAD(folios_staged);
@@ -6505,6 +6508,7 @@ static bool memcg_recharge_lruvec_list(struct lruvec *lruvec,
continue;
}
+ nr_scanned += folio_nr_pages(folio);
if (unlikely(!folio_try_get(folio))) {
list_move(&folio->lru, &folios_skipped);
continue;
@@ -6543,6 +6547,7 @@ static bool memcg_recharge_lruvec_list(struct lruvec *lruvec,
}
mem_cgroup_end_move_charge(memcg);
mod_lruvec_state(lruvec, isolated_idx, -nr_staged);
+ count_vm_events(RECHARGE_PGSCANNED, nr_scanned);
return false;
}
@@ -6679,6 +6684,7 @@ void folio_memcg_deferred_recharge(struct folio *folio)
if (unlikely(!memcg_recharge_wq))
return;
+ count_vm_events(RECHARGE_PGSCANNED, folio_nr_pages(folio));
if (unlikely(!folio_try_get(folio)))
return;
diff --git a/mm/vmstat.c b/mm/vmstat.c
index b731d57996c5..e425a1aa7890 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1303,7 +1303,11 @@ const char * const vmstat_text[] = {
"drop_pagecache",
"drop_slab",
"oom_kill",
-
+#ifdef CONFIG_MEMCG
+ "recharge_pgs_scanned",
+ "recharge_pgs_moved",
+ "recharge_pgs_cancelled",
+#endif
#ifdef CONFIG_NUMA_BALANCING
"numa_pte_updates",
"numa_huge_pte_updates",
--
2.41.0.255.g8b1d071c50-goog
next prev parent reply other threads:[~2023-07-20 7:08 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-20 7:08 [RFC PATCH 0/8] memory recharging for offline memcgs Yosry Ahmed
2023-07-20 7:08 ` [RFC PATCH 1/8] memcg: refactor updating memcg->moving_account Yosry Ahmed
2023-07-20 7:08 ` [RFC PATCH 2/8] mm: vmscan: add lruvec_for_each_list() helper Yosry Ahmed
2023-07-20 7:08 ` [RFC PATCH 3/8] memcg: recharge mapped folios when a memcg is offlined Yosry Ahmed
2023-07-20 7:08 ` [RFC PATCH 4/8] memcg: support deferred memcg recharging Yosry Ahmed
2023-07-20 7:08 ` [RFC PATCH 5/8] memcg: recharge folios when accessed or dirtied Yosry Ahmed
2023-07-20 7:08 ` Yosry Ahmed [this message]
2023-07-20 7:08 ` [RFC PATCH 7/8] memcg: add sysctl and config option to control memory recharging Yosry Ahmed
2023-07-20 18:13 ` Luis Chamberlain
2023-07-20 18:24 ` Yosry Ahmed
2023-07-20 18:30 ` Luis Chamberlain
2023-07-20 7:08 ` [RFC PATCH 8/8] selftests: cgroup: test_memcontrol: add a selftest for memcg recharging Yosry Ahmed
2023-07-20 15:35 ` [RFC PATCH 0/8] memory recharging for offline memcgs Johannes Weiner
2023-07-20 19:57 ` Tejun Heo
2023-07-20 21:34 ` Yosry Ahmed
2023-07-20 22:11 ` Tejun Heo
2023-07-20 22:23 ` Yosry Ahmed
2023-07-20 22:31 ` Tejun Heo
2023-07-20 23:24 ` T.J. Mercier
2023-07-20 23:33 ` Tejun Heo
2023-07-21 18:15 ` Yosry Ahmed
2023-07-21 18:26 ` Tejun Heo
2023-07-21 18:47 ` Yosry Ahmed
2023-07-21 19:18 ` Tejun Heo
2023-07-21 20:37 ` Yosry Ahmed
2023-07-21 20:44 ` Johannes Weiner
2023-07-21 20:59 ` Yosry Ahmed
2023-07-20 21:33 ` Yosry Ahmed
2023-08-01 9:54 ` Michal Hocko
2023-07-21 0:02 ` Roman Gushchin
2023-07-21 0:07 ` Yosry Ahmed
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=20230720070825.992023-7-yosryahmed@google.com \
--to=yosryahmed@google.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=gthelen@google.com \
--cc=hannes@cmpxchg.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizefan.x@bytedance.com \
--cc=mcgrof@kernel.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeelb@google.com \
--cc=tj@kernel.org \
--cc=tjmercier@google.com \
--cc=willy@infradead.org \
--cc=yuzhao@google.com \
--cc=yzaikin@google.com \
/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;
as well as URLs for NNTP newsgroup(s).