[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201202182725.265020-9-shy828301@gmail.com>
Date: Wed, 2 Dec 2020 10:27:24 -0800
From: Yang Shi <shy828301@...il.com>
To: guro@...com, ktkhai@...tuozzo.com, shakeelb@...gle.com,
david@...morbit.com, hannes@...xchg.org, mhocko@...e.com,
akpm@...ux-foundation.org
Cc: shy828301@...il.com, linux-mm@...ck.org,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH 8/9] mm: memcontrol: reparent nr_deferred when memcg offline
Now shrinker's nr_deferred is per memcg for memcg aware shrinkers, add to parent's
corresponding nr_deferred when memcg offline.
Signed-off-by: Yang Shi <shy828301@...il.com>
---
include/linux/shrinker.h | 4 ++++
mm/memcontrol.c | 24 ++++++++++++++++++++++++
mm/vmscan.c | 2 +-
3 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h
index 0bb5be88e41d..8f095e424799 100644
--- a/include/linux/shrinker.h
+++ b/include/linux/shrinker.h
@@ -82,6 +82,10 @@ struct shrinker {
};
#define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
+#ifdef CONFIG_MEMCG
+extern int shrinker_nr_max;
+#endif
+
/* Flags */
#define SHRINKER_NUMA_AWARE (1 << 0)
#define SHRINKER_MEMCG_AWARE (1 << 1)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index d3d5c88db179..df128cab900f 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -59,6 +59,7 @@
#include <linux/tracehook.h>
#include <linux/psi.h>
#include <linux/seq_buf.h>
+#include <linux/shrinker.h>
#include "internal.h"
#include <net/sock.h>
#include <net/ip.h>
@@ -619,6 +620,28 @@ void memcg_set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id)
}
}
+static void memcg_reparent_shrinker_deferred(struct mem_cgroup *memcg)
+{
+ int i, nid;
+ long nr;
+ struct mem_cgroup *parent;
+ struct memcg_shrinker_deferred *child_deferred, *parent_deferred;
+
+ parent = parent_mem_cgroup(memcg);
+ if (!parent)
+ parent = root_mem_cgroup;
+
+ for_each_node(nid) {
+ child_deferred = memcg->nodeinfo[nid]->shrinker_deferred;
+ parent_deferred = parent->nodeinfo[nid]->shrinker_deferred;
+ for (i = 0; i < shrinker_nr_max; i ++) {
+ nr = atomic_long_read(&child_deferred->nr_deferred[i]);
+ atomic_long_add(nr,
+ &parent_deferred->nr_deferred[i]);
+ }
+ }
+}
+
/**
* mem_cgroup_css_from_page - css of the memcg associated with a page
* @page: page of interest
@@ -5543,6 +5566,7 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
page_counter_set_low(&memcg->memory, 0);
memcg_offline_kmem(memcg);
+ memcg_reparent_shrinker_deferred(memcg);
wb_memcg_offline(memcg);
drain_all_stock(memcg);
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 5fd57060fafd..7dc8075c371b 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -201,7 +201,7 @@ static DECLARE_RWSEM(shrinker_rwsem);
#define SHRINKER_REGISTERING ((struct shrinker *)~0UL)
static DEFINE_IDR(shrinker_idr);
-static int shrinker_nr_max;
+int shrinker_nr_max;
static inline bool is_deferred_memcg_aware(struct shrinker *shrinker)
{
--
2.26.2
Powered by blists - more mailing lists