From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Shakeel Butt <shakeelb@google.com>
Cc: Mel Gorman <mgorman@techsingularity.net>,
Tejun Heo <tj@kernel.org>, Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>, Linux MM <linux-mm@kvack.org>,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
Andrey Ryabinin <aryabinin@virtuozzo.com>
Subject: [PATCH] mm-vmscan-dont-mess-with-pgdat-flags-in-memcg-reclaim-v2-fix
Date: Fri, 6 Apr 2018 16:52:15 +0300 [thread overview]
Message-ID: <20180406135215.10057-1-aryabinin@virtuozzo.com> (raw)
In-Reply-To: <CALvZod7P7cE38fDrWd=0caA2J6ZOmSzEuLGQH9VSaagCbo5O+A@mail.gmail.com>
On 04/06/2018 05:13 AM, Shakeel Butt wrote:
> Question: Should this 'flags' be per-node? Is it ok for a congested
> memcg to call wait_iff_congested for all nodes?
Indeed, congestion state should be pre-node. If memcg on node A is
congested, there is no point is stalling memcg reclaim from node B.
Make congestion state per-cgroup-per-node and record it in
'struct mem_cgroup_per_node'.
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
include/linux/memcontrol.h | 5 +++--
mm/vmscan.c | 39 +++++++++++++++++++++++++--------------
2 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 8b394bbf1c86..af9eed2e3e04 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -120,6 +120,9 @@ struct mem_cgroup_per_node {
unsigned long usage_in_excess;/* Set to the value by which */
/* the soft limit is exceeded*/
bool on_tree;
+ bool congested; /* memcg has many dirty pages */
+ /* backed by a congested BDI */
+
struct mem_cgroup *memcg; /* Back pointer, we cannot */
/* use container_of */
};
@@ -189,8 +192,6 @@ struct mem_cgroup {
/* vmpressure notifications */
struct vmpressure vmpressure;
- unsigned long flags;
-
/*
* Should the accounting and control be hierarchical, per subtree?
*/
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 99688299eba8..78214c899710 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -200,16 +200,27 @@ static bool sane_reclaim(struct scan_control *sc)
return false;
}
-static void set_memcg_bit(enum pgdat_flags flag,
- struct mem_cgroup *memcg)
+static void set_memcg_congestion(pg_data_t *pgdat,
+ struct mem_cgroup *memcg,
+ bool congested)
{
- set_bit(flag, &memcg->flags);
+ struct mem_cgroup_per_node *mz;
+
+ if (!memcg)
+ return;
+
+ mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id);
+ WRITE_ONCE(mz->congested, congested);
}
-static int test_memcg_bit(enum pgdat_flags flag,
+static bool memcg_congested(pg_data_t *pgdat,
struct mem_cgroup *memcg)
{
- return test_bit(flag, &memcg->flags);
+ struct mem_cgroup_per_node *mz;
+
+ mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id);
+ return READ_ONCE(mz->congested);
+
}
#else
static bool global_reclaim(struct scan_control *sc)
@@ -222,15 +233,16 @@ static bool sane_reclaim(struct scan_control *sc)
return true;
}
-static inline void set_memcg_bit(enum pgdat_flags flag,
- struct mem_cgroup *memcg)
+static inline void set_memcg_congestion(struct pglist_data *pgdat,
+ struct mem_cgroup *memcg, bool congested)
{
}
-static inline int test_memcg_bit(enum pgdat_flags flag,
- struct mem_cgroup *memcg)
+static inline bool memcg_congested(struct pglist_data *pgdat,
+ struct mem_cgroup *memcg)
{
- return 0;
+ return false;
+
}
#endif
@@ -2482,7 +2494,7 @@ static inline bool should_continue_reclaim(struct pglist_data *pgdat,
static bool pgdat_memcg_congested(pg_data_t *pgdat, struct mem_cgroup *memcg)
{
return test_bit(PGDAT_CONGESTED, &pgdat->flags) ||
- (memcg && test_memcg_bit(PGDAT_CONGESTED, memcg));
+ (memcg && memcg_congested(pgdat, memcg));
}
static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
@@ -2617,7 +2629,7 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc)
*/
if (!global_reclaim(sc) && sane_reclaim(sc) &&
sc->nr.dirty && sc->nr.dirty == sc->nr.congested)
- set_memcg_bit(PGDAT_CONGESTED, root);
+ set_memcg_congestion(pgdat, root, true);
/*
* Stall direct reclaim for IO completions if underlying BDIs
@@ -2844,6 +2856,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
continue;
last_pgdat = zone->zone_pgdat;
snapshot_refaults(sc->target_mem_cgroup, zone->zone_pgdat);
+ set_memcg_congestion(last_pgdat, sc->target_mem_cgroup, false);
}
delayacct_freepages_end();
@@ -3067,7 +3080,6 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg,
* the priority and make it zero.
*/
shrink_node_memcg(pgdat, memcg, &sc, &lru_pages);
- clear_bit(PGDAT_CONGESTED, &memcg->flags);
trace_mm_vmscan_memcg_softlimit_reclaim_end(sc.nr_reclaimed);
@@ -3113,7 +3125,6 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,
noreclaim_flag = memalloc_noreclaim_save();
nr_reclaimed = do_try_to_free_pages(zonelist, &sc);
memalloc_noreclaim_restore(noreclaim_flag);
- clear_bit(PGDAT_CONGESTED, &memcg->flags);
trace_mm_vmscan_memcg_reclaim_end(nr_reclaimed);
--
2.16.1
next prev parent reply other threads:[~2018-04-06 13:51 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-23 15:20 [PATCH v2 0/4] vmscan per-cgroup reclaim fixes Andrey Ryabinin
2018-03-23 15:20 ` [PATCH v2 1/4] mm/vmscan: Update stale comments Andrey Ryabinin
2018-04-06 16:08 ` Johannes Weiner
2018-03-23 15:20 ` [PATCH v2 2/4] mm/vmscan: remove redundant current_may_throttle() check Andrey Ryabinin
2018-04-06 16:10 ` Johannes Weiner
2018-03-23 15:20 ` [PATCH v2 3/4] mm/vmscan: Don't change pgdat state on base of a single LRU list state Andrey Ryabinin
2018-04-05 22:17 ` Andrew Morton
2018-04-06 1:04 ` Shakeel Butt
2018-04-06 16:28 ` Johannes Weiner
2018-04-06 17:25 ` Andrey Ryabinin
2018-03-23 15:20 ` [PATCH v2 4/4] mm/vmscan: Don't mess with pgdat->flags in memcg reclaim Andrey Ryabinin
2018-04-05 22:18 ` Andrew Morton
2018-04-06 2:13 ` Shakeel Butt
2018-04-06 11:44 ` Andrey Ryabinin
2018-04-06 14:15 ` Shakeel Butt
2018-04-06 13:52 ` Andrey Ryabinin [this message]
2018-04-06 14:37 ` [PATCH] mm-vmscan-dont-mess-with-pgdat-flags-in-memcg-reclaim-v2-fix Shakeel Butt
2018-04-06 15:09 ` Andrey Ryabinin
2018-04-06 15:22 ` Shakeel Butt
2018-04-06 16:36 ` Johannes Weiner
2018-04-06 18:02 ` [PATCH v3 1/2] mm/vmscan: don't change pgdat state on base of a single LRU list state Andrey Ryabinin
2018-04-06 18:02 ` [PATCH v3 2/2] mm/vmscan: don't mess with pgdat->flags in memcg reclaim Andrey Ryabinin
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=20180406135215.10057-1-aryabinin@virtuozzo.com \
--to=aryabinin@virtuozzo.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@kernel.org \
--cc=shakeelb@google.com \
--cc=tj@kernel.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