@@ -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)
@@ -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);
@@ -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)
{
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@gmail.com> --- include/linux/shrinker.h | 4 ++++ mm/memcontrol.c | 24 ++++++++++++++++++++++++ mm/vmscan.c | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-)