From: Yafang Shao <laoar.shao@gmail.com>
To: mhocko@kernel.org, hannes@cmpxchg.org, vdavydov.dev@gmail.com,
akpm@linux-foundation.org
Cc: linux-mm@kvack.org, Yafang Shao <laoar.shao@gmail.com>
Subject: [PATCH 2/2] mm, memcg: introduce passive reclaim counters for non-root memcg
Date: Thu, 7 Nov 2019 01:08:09 -0500 [thread overview]
Message-ID: <1573106889-4939-2-git-send-email-laoar.shao@gmail.com> (raw)
In-Reply-To: <1573106889-4939-1-git-send-email-laoar.shao@gmail.com>
The memory.{min, low} protection can prevent the reclaimers to reclaim the
pages from a memcg when there're memory pressure outside of a memcg.
We'd better introduce some counters to show this behavior.
This patch introduce two counters, pgscan_passive and pgsteal_passive.
pgscan_passive:
pages scanned due to memory pressure outside this memcg
pgsteal_passive:
pages reclaimed due to memory pressure outside this memcg
memcg set with higher memory.{min, low} setting, will get a lower
pgscan_passive and pgsteal_passive. For example, if memory.min is equal to
memory.max, then these passive reclaim counters should always be zero.
These counters are only for non-root memory cgroup. It's not easy to
introduce some container-only vmstat counters, because it will make lots
of changes. So I introduce some global vmstat counters, but they are
always zero for root memory cgroup.
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
Documentation/admin-guide/cgroup-v2.rst | 10 ++++++++++
include/linux/vm_event_item.h | 2 ++
mm/memcontrol.c | 4 ++++
mm/vmscan.c | 11 +++++++++--
mm/vmstat.c | 2 ++
5 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
index cdacc9c..11e0129 100644
--- a/Documentation/admin-guide/cgroup-v2.rst
+++ b/Documentation/admin-guide/cgroup-v2.rst
@@ -1336,10 +1336,20 @@ PAGE_SIZE multiple when read back.
Amount of scanned pages (in an inactive LRU list)
+ pgscan_passive
+
+ Amount of scanned pages due to memory pressure outside this
+ memcg
+
pgsteal
Amount of reclaimed pages
+ pgsteal_passive
+
+ Amount of reclaimed pages due to memory pressure outside
+ this memcg
+
pgactivate
Amount of pages moved to the active LRU list
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 47a3441..0fcdaa3 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -32,8 +32,10 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
PGREFILL,
PGSTEAL_KSWAPD,
PGSTEAL_DIRECT,
+ PGSTEAL_PASSIVE,
PGSCAN_KSWAPD,
PGSCAN_DIRECT,
+ PGSCAN_PASSIVE,
PGSCAN_DIRECT_THROTTLE,
#ifdef CONFIG_NUMA
PGSCAN_ZONE_RECLAIM_FAILED,
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 9da4ef9..0a2bf9a 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1443,9 +1443,13 @@ static char *memory_stat_format(struct mem_cgroup *memcg)
seq_buf_printf(&s, "pgscan %lu\n",
memcg_events(memcg, PGSCAN_KSWAPD) +
memcg_events(memcg, PGSCAN_DIRECT));
+ seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGSCAN_PASSIVE),
+ memcg_events(memcg, PGSCAN_PASSIVE));
seq_buf_printf(&s, "pgsteal %lu\n",
memcg_events(memcg, PGSTEAL_KSWAPD) +
memcg_events(memcg, PGSTEAL_DIRECT));
+ seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGSTEAL_PASSIVE),
+ memcg_events(memcg, PGSTEAL_PASSIVE));
seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGACTIVATE),
memcg_events(memcg, PGACTIVATE));
seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGDEACTIVATE),
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 3b08e85..0ea6c4a0 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1910,6 +1910,7 @@ static int current_may_throttle(void)
struct pglist_data *pgdat = lruvec_pgdat(lruvec);
struct zone_reclaim_stat *reclaim_stat = &lruvec->reclaim_stat;
bool stalled = false;
+ struct mem_cgroup *memcg;
while (unlikely(too_many_isolated(pgdat, file, sc))) {
if (stalled)
@@ -1934,10 +1935,13 @@ static int current_may_throttle(void)
__mod_node_page_state(pgdat, NR_ISOLATED_ANON + file, nr_taken);
reclaim_stat->recent_scanned[file] += nr_taken;
+ memcg = lruvec_memcg(lruvec);
item = current_is_kswapd() ? PGSCAN_KSWAPD : PGSCAN_DIRECT;
if (!cgroup_reclaim(sc))
__count_vm_events(item, nr_scanned);
- __count_memcg_events(lruvec_memcg(lruvec), item, nr_scanned);
+ if (memcg != sc->target_mem_cgroup)
+ __count_memcg_events(memcg, PGSCAN_PASSIVE, nr_scanned);
+ __count_memcg_events(memcg, item, nr_scanned);
spin_unlock_irq(&pgdat->lru_lock);
if (nr_taken == 0)
@@ -1948,10 +1952,13 @@ static int current_may_throttle(void)
spin_lock_irq(&pgdat->lru_lock);
+ memcg = lruvec_memcg(lruvec);
item = current_is_kswapd() ? PGSTEAL_KSWAPD : PGSTEAL_DIRECT;
if (!cgroup_reclaim(sc))
__count_vm_events(item, nr_reclaimed);
- __count_memcg_events(lruvec_memcg(lruvec), item, nr_reclaimed);
+ if (memcg != sc->target_mem_cgroup)
+ __count_memcg_events(memcg, PGSTEAL_PASSIVE, nr_reclaimed);
+ __count_memcg_events(memcg, item, nr_reclaimed);
reclaim_stat->recent_rotated[0] += stat.nr_activate[0];
reclaim_stat->recent_rotated[1] += stat.nr_activate[1];
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 78d5337..5d2a053 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1196,8 +1196,10 @@ int fragmentation_index(struct zone *zone, unsigned int order)
"pgrefill",
"pgsteal_kswapd",
"pgsteal_direct",
+ "pgsteal_passive",
"pgscan_kswapd",
"pgscan_direct",
+ "pgscan_passive",
"pgscan_direct_throttle",
#ifdef CONFIG_NUMA
--
1.8.3.1
next prev parent reply other threads:[~2019-11-07 6:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-07 6:08 [PATCH 1/2] mm, memcg: introduce multiple levels memory low protection Yafang Shao
2019-11-07 6:08 ` Yafang Shao [this message]
2019-11-08 13:26 ` Michal Hocko
2019-11-09 3:32 ` Yafang Shao
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=1573106889-4939-2-git-send-email-laoar.shao@gmail.com \
--to=laoar.shao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=vdavydov.dev@gmail.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