linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mm: memcg: rename and document global_reclaim()
@ 2023-06-21  2:30 Yosry Ahmed
  2023-06-23 20:39 ` Yu Zhao
  0 siblings, 1 reply; 2+ messages in thread
From: Yosry Ahmed @ 2023-06-21  2:30 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Yu Zhao, Johannes Weiner, linux-mm, linux-kernel, Yosry Ahmed

Evidently, global_reclaim() can be a confusing name. Especially that it
used to exist before with a subtly different definition (removed by
commit b5ead35e7e1d ("mm: vmscan: naming fixes: global_reclaim() and
sane_reclaim()"). It can be interpreted as non-cgroup reclaim, even
though it returns true for cgroup reclaim on the root memcg
(through memory.reclaim).

Rename it to root_reclaim() in an attempt to make it less ambiguous, and
add documentation to it as well as cgroup_reclaim.

Reported-by: Johannes Weiner <hannes@cmpxchg.org>
Closes: https://lore.kernel.org/lkml/20230405200150.GA35884@cmpxchg.org/
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
---
 mm/vmscan.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index e305c11ec8fc..0dbbf718c53e 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -445,12 +445,17 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg)
 	mutex_unlock(&shrinker_mutex);
 }
 
+/* Returns true for reclaim through cgroup limits or cgroup interfaces. */
 static bool cgroup_reclaim(struct scan_control *sc)
 {
 	return sc->target_mem_cgroup;
 }
 
-static bool global_reclaim(struct scan_control *sc)
+/*
+ * Returns true for reclaim on the root cgroup. This is true for direct
+ * allocator reclaim and reclaim through cgroup interfaces on the root cgroup.
+ */
+static bool root_reclaim(struct scan_control *sc)
 {
 	return !sc->target_mem_cgroup || mem_cgroup_is_root(sc->target_mem_cgroup);
 }
@@ -505,7 +510,7 @@ static bool cgroup_reclaim(struct scan_control *sc)
 	return false;
 }
 
-static bool global_reclaim(struct scan_control *sc)
+static bool root_reclaim(struct scan_control *sc)
 {
 	return true;
 }
@@ -562,7 +567,7 @@ static void flush_reclaim_state(struct scan_control *sc)
 	 * memcg reclaim, to make reporting more accurate and reduce
 	 * underestimation, but it's probably not worth the complexity for now.
 	 */
-	if (current->reclaim_state && global_reclaim(sc)) {
+	if (current->reclaim_state && root_reclaim(sc)) {
 		sc->nr_reclaimed += current->reclaim_state->reclaimed;
 		current->reclaim_state->reclaimed = 0;
 	}
@@ -5339,7 +5344,7 @@ static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc, bool
 static unsigned long get_nr_to_reclaim(struct scan_control *sc)
 {
 	/* don't abort memcg reclaim to ensure fairness */
-	if (!global_reclaim(sc))
+	if (!root_reclaim(sc))
 		return -1;
 
 	return max(sc->nr_to_reclaim, compact_gap(sc->order));
@@ -5491,7 +5496,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc
 {
 	struct blk_plug plug;
 
-	VM_WARN_ON_ONCE(global_reclaim(sc));
+	VM_WARN_ON_ONCE(root_reclaim(sc));
 	VM_WARN_ON_ONCE(!sc->may_writepage || !sc->may_unmap);
 
 	lru_add_drain();
@@ -5552,7 +5557,7 @@ static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control *
 	struct blk_plug plug;
 	unsigned long reclaimed = sc->nr_reclaimed;
 
-	VM_WARN_ON_ONCE(!global_reclaim(sc));
+	VM_WARN_ON_ONCE(!root_reclaim(sc));
 
 	/*
 	 * Unmapped clean folios are already prioritized. Scanning for more of
@@ -6274,7 +6279,7 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
 	bool proportional_reclaim;
 	struct blk_plug plug;
 
-	if (lru_gen_enabled() && !global_reclaim(sc)) {
+	if (lru_gen_enabled() && !root_reclaim(sc)) {
 		lru_gen_shrink_lruvec(lruvec, sc);
 		return;
 	}
@@ -6515,7 +6520,7 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 	struct lruvec *target_lruvec;
 	bool reclaimable = false;
 
-	if (lru_gen_enabled() && global_reclaim(sc)) {
+	if (lru_gen_enabled() && root_reclaim(sc)) {
 		lru_gen_shrink_node(pgdat, sc);
 		return;
 	}
-- 
2.41.0.162.gfafddb0af9-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/2] mm: memcg: rename and document global_reclaim()
  2023-06-21  2:30 [PATCH 1/2] mm: memcg: rename and document global_reclaim() Yosry Ahmed
@ 2023-06-23 20:39 ` Yu Zhao
  0 siblings, 0 replies; 2+ messages in thread
From: Yu Zhao @ 2023-06-23 20:39 UTC (permalink / raw)
  To: Yosry Ahmed; +Cc: Andrew Morton, Johannes Weiner, linux-mm, linux-kernel

On Tue, Jun 20, 2023 at 8:30 PM Yosry Ahmed <yosryahmed@google.com> wrote:
>
> Evidently, global_reclaim() can be a confusing name. Especially that it
> used to exist before with a subtly different definition (removed by
> commit b5ead35e7e1d ("mm: vmscan: naming fixes: global_reclaim() and
> sane_reclaim()"). It can be interpreted as non-cgroup reclaim, even
> though it returns true for cgroup reclaim on the root memcg
> (through memory.reclaim).
>
> Rename it to root_reclaim() in an attempt to make it less ambiguous, and
> add documentation to it as well as cgroup_reclaim.
>
> Reported-by: Johannes Weiner <hannes@cmpxchg.org>
> Closes: https://lore.kernel.org/lkml/20230405200150.GA35884@cmpxchg.org/
> Signed-off-by: Yosry Ahmed <yosryahmed@google.com>

Acked-by: Yu Zhao <yuzhao@google.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-23 20:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-21  2:30 [PATCH 1/2] mm: memcg: rename and document global_reclaim() Yosry Ahmed
2023-06-23 20:39 ` Yu Zhao

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).