Re: [patch 04/11] mm, memcg: add tunable for oom reserves

From: Andrew Morton
Date: Wed Mar 05 2014 - 16:18:13 EST


On Tue, 4 Mar 2014 19:59:19 -0800 (PST) David Rientjes <rientjes@xxxxxxxxxx> wrote:

> Userspace needs a way to define the amount of memory reserves that
> processes handling oom conditions may utilize. This patch adds a per-
> memcg oom reserve field and file, memory.oom_reserve_in_bytes, to
> manipulate its value.
>
> If currently utilized memory reserves are attempted to be reduced by
> writing a smaller value to memory.oom_reserve_in_bytes, it will fail with
> -EBUSY until some memory is uncharged.
>
> ...
>
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -315,6 +315,9 @@ struct mem_cgroup {
> /* OOM-Killer disable */
> int oom_kill_disable;
>
> + /* reserves for handling oom conditions, protected by res.lock */
> + unsigned long long oom_reserve;

Units? bytes, I assume.

> /* set when res.limit == memsw.limit */
> bool memsw_is_minimum;
>
> @@ -5936,6 +5939,51 @@ static int mem_cgroup_oom_control_write(struct cgroup_subsys_state *css,
> return 0;
> }
>
> +static int mem_cgroup_resize_oom_reserve(struct mem_cgroup *memcg,
> + unsigned long long new_limit)
> +{
> + struct res_counter *res = &memcg->res;
> + u64 limit, usage;
> + int ret = 0;

The code mixes u64's and unsigned long longs in inexplicable ways.
Suggest using u64 throughout.

> + spin_lock(&res->lock);
> + limit = res->limit;
> + usage = res->usage;
> +
> + if (usage > limit && usage - limit > new_limit) {
> + ret = -EBUSY;
> + goto out;
> + }
> +
> + memcg->oom_reserve = new_limit;
> +out:
> + spin_unlock(&res->lock);
> + return ret;
> +}
>
> ...
>
--
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/