[PATCH 2/2] memcg, res_counter: replace res_counter_soft_limit_excess by a more generic helper

From: Michal Hocko
Date: Thu Jun 19 2014 - 13:42:25 EST


Later patches in the series will add new limits which we will want to
check for excess as well so change the current on-off
res_counter_soft_limit_excess to a more generic helper.

Signed-off-by: Michal Hocko <mhocko@xxxxxxx>
---
include/linux/res_counter.h | 21 +++++++++++++++------
mm/memcontrol.c | 10 +++++-----
2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h
index bea7f9f45f7a..9015013784fa 100644
--- a/include/linux/res_counter.h
+++ b/include/linux/res_counter.h
@@ -156,23 +156,32 @@ static inline unsigned long long res_counter_margin(struct res_counter *cnt)
}

/**
- * Get the difference between the usage and the soft limit
+ * Get the difference between the usage and the limit defined
+ * by the given member
* @cnt: The counter
*
- * Returns 0 if usage is less than or equal to soft limit
- * The difference between usage and soft limit, otherwise.
+ * Returns 0 if usage is less than or equal to the limit defined
+ * by member or the difference otherwise.
*/
static inline unsigned long long
-res_counter_soft_limit_excess(struct res_counter *cnt)
+res_counter_limit_excess(struct res_counter *cnt, int member)
{
unsigned long long excess;
+ unsigned long long limit;
unsigned long flags;

spin_lock_irqsave(&cnt->lock, flags);
- if (cnt->usage <= cnt->soft_limit)
+ switch(member) {
+ case RES_SOFT_LIMIT:
+ limit = cnt->soft_limit;
+ break;
+ default:
+ BUG();
+ }
+ if (cnt->usage <= limit)
excess = 0;
else
- excess = cnt->usage - cnt->soft_limit;
+ excess = cnt->usage - limit;
spin_unlock_irqrestore(&cnt->lock, flags);
return excess;
}
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 1ad5d4a2bc4e..75b5db78e9be 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -773,7 +773,7 @@ static void mem_cgroup_update_tree(struct mem_cgroup *memcg, struct page *page)
*/
for (; memcg; memcg = parent_mem_cgroup(memcg)) {
mz = mem_cgroup_page_zoneinfo(memcg, page);
- excess = res_counter_soft_limit_excess(&memcg->res);
+ excess = res_counter_limit_excess(&memcg->res, RES_SOFT_LIMIT);
/*
* We have to update the tree if mz is on RB-tree or
* mem is over its softlimit.
@@ -827,7 +827,7 @@ retry:
* position in the tree.
*/
__mem_cgroup_remove_exceeded(mz, mctz);
- if (!res_counter_soft_limit_excess(&mz->memcg->res) ||
+ if (!res_counter_limit_excess(&mz->memcg->res, RES_SOFT_LIMIT) ||
!css_tryget_online(&mz->memcg->css))
goto retry;
done:
@@ -1983,7 +1983,7 @@ static int mem_cgroup_soft_reclaim(struct mem_cgroup *root_memcg,
.priority = 0,
};

- excess = res_counter_soft_limit_excess(&root_memcg->res) >> PAGE_SHIFT;
+ excess = res_counter_limit_excess(&root_memcg->res, RES_SOFT_LIMIT) >> PAGE_SHIFT;

while (1) {
victim = mem_cgroup_iter(root_memcg, victim, &reclaim);
@@ -2014,7 +2014,7 @@ static int mem_cgroup_soft_reclaim(struct mem_cgroup *root_memcg,
total += mem_cgroup_shrink_node_zone(victim, gfp_mask, false,
zone, &nr_scanned);
*total_scanned += nr_scanned;
- if (!res_counter_soft_limit_excess(&root_memcg->res))
+ if (!res_counter_limit_excess(&root_memcg->res, RES_SOFT_LIMIT))
break;
}
mem_cgroup_iter_break(root_memcg, victim);
@@ -3941,7 +3941,7 @@ unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
} while (1);
}
__mem_cgroup_remove_exceeded(mz, mctz);
- excess = res_counter_soft_limit_excess(&mz->memcg->res);
+ excess = res_counter_limit_excess(&mz->memcg->res, RES_SOFT_LIMIT);
/*
* One school of thought says that we should not add
* back the node to the tree if reclaim returns 0.
--
2.1.0.rc1

--
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/