From: Ying Han <yinghan@google.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
Michal Hocko <mhocko@suse.cz>,
Johannes Weiner <hannes@cmpxchg.org>, Tejun Heo <tj@kernel.org>,
Glauber Costa <glommer@parallels.com>,
Hugh Dickins <hughd@google.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 6/7] memcg: remove pre_destroy()
Date: Tue, 17 Apr 2012 10:47:13 -0700 [thread overview]
Message-ID: <CALWz4iwBSuFJaARiNdKWWoF6Xc5S3CHG4CgBXDqc6CyK3Pzc7Q@mail.gmail.com> (raw)
In-Reply-To: <4F86BCCE.5050802@jp.fujitsu.com>
On Thu, Apr 12, 2012 at 4:30 AM, KAMEZAWA Hiroyuki
<kamezawa.hiroyu@jp.fujitsu.com> wrote:
> Tejun Heo, cgroup maintainer, tries to remove ->pre_destroy() to
> prevent rmdir() from failure of EBUSY or some.
>
> This patch removes pre_destroy() in memcg. All remaining charges
> will be moved to other cgroup, without any failure, ->destroy()
> just schedule a work and it will destroy the memcg.
> Then, rmdir will never fail. The kernel will take care of remaining
> resources in the cgroup to be accounted correctly.
>
> After this patch, memcg will be destroyed by workqueue in asynchrnous way.
Is it necessary to change the destroy asynchronously?
Frankly, i don't that that much. It will leave the system in a
deterministic state on admin perspective. The current synchronous
destroy works fine, and admin can rely on that w/ charging change
after the destroy returns.
--Ying
> Then, we can modify 'moving' logic to work asynchrnously, i.e,
> we don't force users to wait for the end of rmdir(), now. We don't
> need to use heavy synchronous calls. This patch modifies logics as
>
> - Use mem_cgroup_drain_stock_async rather tan drain_stock_sync.
> - lru_add_drain_all() will be called only when necessary, in a lazy way.
>
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> ---
> mm/memcontrol.c | 52 ++++++++++++++++++++++------------------------------
> 1 files changed, 22 insertions(+), 30 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 22c8faa..e466809 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -315,6 +315,8 @@ struct mem_cgroup {
> #ifdef CONFIG_INET
> struct tcp_memcontrol tcp_mem;
> #endif
> +
> + struct work_struct work_destroy;
> };
>
> /* Stuffs for move charges at task migration. */
> @@ -2105,7 +2107,6 @@ static void drain_all_stock_async(struct mem_cgroup *root_memcg)
> mutex_unlock(&percpu_charge_mutex);
> }
>
> -/* This is a synchronous drain interface. */
> static void drain_all_stock_sync(struct mem_cgroup *root_memcg)
> {
> /* called when force_empty is called */
> @@ -3661,10 +3662,9 @@ static int mem_cgroup_recharge_lru(struct mem_cgroup *memcg,
> pc = lookup_page_cgroup(page);
>
> ret = mem_cgroup_move_parent(page, pc, memcg, GFP_KERNEL);
> - if (ret == -EINTR)
> - break;
>
> - if (ret == -EBUSY || ret == -EINVAL) {
> + VM_BUG_ON(ret != 0 && ret != -EBUSY);
> + if (ret) {
> /* found lock contention or "pc" is obsolete. */
> busy = page;
> cond_resched();
> @@ -3677,22 +3677,19 @@ static int mem_cgroup_recharge_lru(struct mem_cgroup *memcg,
> return ret;
> }
>
> -
> -static int mem_cgroup_recharge(struct mem_cgroup *memcg)
> +/*
> + * This function is called after ->destroy(). So, we cannot access cgroup
> + * of this memcg.
> + */
> +static void mem_cgroup_recharge(struct work_struct *work)
> {
> + struct mem_cgroup *memcg;
> int ret, node, zid;
> - struct cgroup *cgrp = memcg->css.cgroup;
>
> + memcg = container_of(work, struct mem_cgroup, work_destroy);
> + /* No task points this memcg. call this only once */
> + drain_all_stock_async(memcg);
> do {
> - ret = -EBUSY;
> - if (cgroup_task_count(cgrp) || !list_empty(&cgrp->children))
> - goto out;
> - ret = -EINTR;
> - if (signal_pending(current))
> - goto out;
> - /* This is for making all *used* pages to be on LRU. */
> - lru_add_drain_all();
> - drain_all_stock_sync(memcg);
> ret = 0;
> mem_cgroup_start_move(memcg);
> for_each_node_state(node, N_HIGH_MEMORY) {
> @@ -3710,13 +3707,14 @@ static int mem_cgroup_recharge(struct mem_cgroup *memcg)
> }
> mem_cgroup_end_move(memcg);
> cond_resched();
> - /* "ret" should also be checked to ensure all lists are empty. */
> - } while (memcg->res.usage > 0 || ret);
> -out:
> - return ret;
> + /* drain LRU only when we canoot find pages on LRU */
> + if (res_counter_read_u64(&memcg->res, RES_USAGE) &&
> + !mem_cgroup_nr_lru_pages(memcg, LRU_ALL))
> + lru_add_drain_all();
> + } while (res_counter_read_u64(&memcg->res, RES_USAGE) || ret);
> + mem_cgroup_put(memcg);
> }
>
> -
> /*
> * make mem_cgroup's charge to be 0 if there is no task. This is only called
> * by memory.force_empty file, an user request.
> @@ -4803,6 +4801,7 @@ static void vfree_work(struct work_struct *work)
> memcg = container_of(work, struct mem_cgroup, work_freeing);
> vfree(memcg);
> }
> +
> static void vfree_rcu(struct rcu_head *rcu_head)
> {
> struct mem_cgroup *memcg;
> @@ -4982,20 +4981,14 @@ free_out:
> return ERR_PTR(error);
> }
>
> -static int mem_cgroup_pre_destroy(struct cgroup *cont)
> -{
> - struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
> -
> - return mem_cgroup_recharge(memcg);
> -}
> -
> static void mem_cgroup_destroy(struct cgroup *cont)
> {
> struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
>
> kmem_cgroup_destroy(cont);
>
> - mem_cgroup_put(memcg);
> + INIT_WORK(&memcg->work_destroy, mem_cgroup_recharge);
> + schedule_work(&memcg->work_destroy);
> }
>
> static int mem_cgroup_populate(struct cgroup_subsys *ss,
> @@ -5589,7 +5582,6 @@ struct cgroup_subsys mem_cgroup_subsys = {
> .name = "memory",
> .subsys_id = mem_cgroup_subsys_id,
> .create = mem_cgroup_create,
> - .pre_destroy = mem_cgroup_pre_destroy,
> .destroy = mem_cgroup_destroy,
> .populate = mem_cgroup_populate,
> .can_attach = mem_cgroup_can_attach,
> --
> 1.7.4.1
>
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-04-17 17:47 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-12 11:17 [PATCH v1 0/7] memcg remove pre_destroy KAMEZAWA Hiroyuki
2012-04-12 11:20 ` [PATCH 1/7] res_counter: add a function res_counter_move_parent() KAMEZAWA Hiroyuki
2012-04-12 13:22 ` Glauber Costa
2012-04-12 14:30 ` Frederic Weisbecker
2012-04-13 0:57 ` KAMEZAWA Hiroyuki
2012-04-13 1:04 ` Frederic Weisbecker
2012-04-13 1:05 ` KAMEZAWA Hiroyuki
2012-04-16 22:19 ` Tejun Heo
2012-04-18 6:59 ` KAMEZAWA Hiroyuki
2012-04-16 22:31 ` Tejun Heo
2012-04-18 7:04 ` KAMEZAWA Hiroyuki
2012-04-18 17:03 ` Tejun Heo
2012-04-12 11:21 ` [PATCH 2/7] memcg: move charge to parent only when necessary KAMEZAWA Hiroyuki
2012-04-16 22:21 ` Tejun Heo
2012-04-18 7:01 ` KAMEZAWA Hiroyuki
2012-04-12 11:22 ` [PATCH 3/7] memcg: move charges to root at rmdir() KAMEZAWA Hiroyuki
2012-04-16 22:30 ` Tejun Heo
2012-04-18 7:02 ` KAMEZAWA Hiroyuki
2012-04-12 11:24 ` [PATCH 4/7] memcg: remove 'uncharge' argument from mem_cgroup_move_account() KAMEZAWA Hiroyuki
2012-04-12 13:27 ` Glauber Costa
2012-04-13 1:01 ` KAMEZAWA Hiroyuki
2012-04-12 11:28 ` [PATCH 5/7] memcg: divide force_empty into 2 functions, avoid memory reclaim at rmdir KAMEZAWA Hiroyuki
2012-04-12 13:33 ` Glauber Costa
2012-04-17 17:29 ` Ying Han
2012-04-18 7:14 ` KAMEZAWA Hiroyuki
2012-04-12 11:30 ` [PATCH 6/7] memcg: remove pre_destroy() KAMEZAWA Hiroyuki
2012-04-16 22:38 ` Tejun Heo
2012-04-18 7:12 ` KAMEZAWA Hiroyuki
2012-04-17 17:47 ` Ying Han [this message]
2012-04-12 11:31 ` [PATCH 7/7] memcg: remove drain_all_stock_sync KAMEZAWA Hiroyuki
2012-04-12 13:35 ` Glauber Costa
2012-04-12 13:20 ` [PATCH v1 0/7] memcg remove pre_destroy Glauber Costa
2012-04-12 16:06 ` Tejun Heo
2012-04-12 18:57 ` Aneesh Kumar K.V
2012-04-12 23:59 ` KAMEZAWA Hiroyuki
2012-04-13 8:50 ` Michal Hocko
2012-04-13 22:19 ` Aneesh Kumar K.V
2012-04-16 22:41 ` Tejun Heo
2012-04-17 17:35 ` Ying Han
2012-04-18 7:15 ` KAMEZAWA Hiroyuki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALWz4iwBSuFJaARiNdKWWoF6Xc5S3CHG4CgBXDqc6CyK3Pzc7Q@mail.gmail.com \
--to=yinghan@google.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=glommer@parallels.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox