Add the reclaim context 'struct scan_control *sc' as a new parameter in the function mem_cgroup_protected(), which will be used later. Change the name of 'root' to 'target' for better understanding as this is a targeted reclaim. Also move the declaration and definition of the changed function into mm/internal.h. Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Cc: Roman Gushchin <guro@xxxxxx> Cc: Chris Down <chris@xxxxxxxxxxxxxx> Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx> --- include/linux/memcontrol.h | 9 --------- mm/memcontrol.c | 14 ++++++++------ mm/vmscan.c | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index d275c72c4f8e..b327857a1e7e 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -357,9 +357,6 @@ static inline unsigned long mem_cgroup_protection(struct mem_cgroup *memcg, READ_ONCE(memcg->memory.elow)); } -enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, - struct mem_cgroup *memcg); - int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask, struct mem_cgroup **memcgp, bool compound); @@ -841,12 +838,6 @@ static inline unsigned long mem_cgroup_protection(struct mem_cgroup *memcg, return 0; } -static inline enum mem_cgroup_protection mem_cgroup_protected( - struct mem_cgroup *root, struct mem_cgroup *memcg) -{ - return MEMCG_PROT_NONE; -} - static inline int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask, struct mem_cgroup **memcgp, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5beea03dd58a..51dab7f2e714 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6367,6 +6367,7 @@ static unsigned long effective_protection(unsigned long usage, * mem_cgroup_protected - check if memory consumption is in the normal range * @root: the top ancestor of the sub-tree being checked * @memcg: the memory cgroup to check + * @sc: the reclaim context * * WARNING: This function is not stateless! It can only be used as part * of a top-down tree iteration, not for isolated queries. @@ -6377,8 +6378,9 @@ static unsigned long effective_protection(unsigned long usage, * an unprotected supply of reclaimable memory from other cgroups. * MEMCG_PROT_MIN: cgroup memory is protected */ -enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, - struct mem_cgroup *memcg) +enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *target, + struct mem_cgroup *memcg, + struct scan_control *sc) { unsigned long usage, parent_usage; struct mem_cgroup *parent; @@ -6386,9 +6388,9 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, if (mem_cgroup_disabled()) return MEMCG_PROT_NONE; - if (!root) - root = root_mem_cgroup; - if (memcg == root) + if (!target) + target = root_mem_cgroup; + if (memcg == target) return MEMCG_PROT_NONE; usage = page_counter_read(&memcg->memory); @@ -6400,7 +6402,7 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, if (!parent) return MEMCG_PROT_NONE; - if (parent == root) { + if (parent == target) { memcg->memory.emin = READ_ONCE(memcg->memory.min); memcg->memory.elow = memcg->memory.low; goto out; diff --git a/mm/vmscan.c b/mm/vmscan.c index 4c98512e2c9f..61c944e7f587 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2551,7 +2551,7 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) unsigned long reclaimed; unsigned long scanned; - switch (mem_cgroup_protected(target_memcg, memcg)) { + switch (mem_cgroup_protected(target_memcg, memcg, sc)) { case MEMCG_PROT_MIN: /* * Hard protection. -- 2.18.2