mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Michal Hocko <mhocko@suse.cz>
Cc: Tejun Heo <tj@kernel.org>,
	lizefan@huawei.com, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 02/14] cgroup: remove pointless has tasks/children test from mem_cgroup_force_empty()
Date: Tue, 13 May 2014 09:10:15 -0400	[thread overview]
Message-ID: <20140513131014.GB18849@cmpxchg.org> (raw)
In-Reply-To: <20140512145324.GE9564@dhcp22.suse.cz>

On Mon, May 12, 2014 at 04:53:24PM +0200, Michal Hocko wrote:
> On Fri 09-05-14 17:31:19, Tejun Heo wrote:
> > mem_cgroup_force_empty() is used only from
> > mem_cgroup_force_empty_write() and tests whether the target memcg has
> > any tasks or children without any synchronization and then returns
> > -EBUSY if so.
> > 
> > This is just weird.  The tests don't really mean anything as tasks and
> > children may be added after the tests and it also makes the behavior
> > of the knob arbitrary because there may be lingering offline and
> > removed children on the children list for extended period of time -
> > writes to the knob can return -EBUSY for reasons completely invisible
> > to userland.
> 
> Agreed.
> 
> > The knob is best-effort anyway and the broken business test doesn't
> > affect its operation.  Remove it.
> 
> But I do not think that removing just the test is the right way to go.
> It is mem_cgroup_reparent_charges which bothers me because it loops
> until the current counter falls down to 0 and it also feels strange that
> a group can hand over pages up the hierarchy (or even to an unlimitted
> root if this is a top of a hierarchy).
> 
> So I think that we want to get rid of reparenting as well.  The main use
> case as described by the documentation is:
> "
>   The typical use case for this interface is before calling rmdir().
>   Because rmdir() moves all pages to parent, some out-of-use page caches can be
>   moved to the parent. If you want to avoid that, force_empty will be useful.
> "
> 
> rmdir will reparent pages implicitly so the reclaim part should be
> sufficient and it would be OK even with existing tasks. Subgroups would
> be little bit more tricky because the user doesn't have any control over
> which group of the hierarchy will get reclaimed.
> 
> Anyway, the knob sucks - for the similar reasons why drop_cache sucks -
> especially when the check would be gone and it would be another way how
> to trigger reclaim anytime. Having the check doesn't prevent from races
> but it at least prevents abuse.
> 
> So I would be rather for dropping the knob altogether, but that seems to
> be a long term thing. So let's start with deprecating it + remove the
> check with dropping reparenting part.
> 
> What do you think about the following patch instead:
> ---
> >From 03f8cb2e1fd2636d859c54df9b58719fe96e0e54 Mon Sep 17 00:00:00 2001
> From: Michal Hocko <mhocko@suse.cz>
> Date: Mon, 12 May 2014 16:34:17 +0200
> Subject: [PATCH] memcg: remove tasks/children test from from
>  mem_cgroup_force_empty
> 
> Tejun has correctly pointed out that tasks/children test in
> mem_cgroup_force_empty is not correct because there is no other locking
> which preserves this state throughout the rest of the function so both
> new tasks can join the group or new children groups can be added while
> somebody is writing to memory.force_empty. A new task would break
> mem_cgroup_reparent_charges expectation that all failures as described
> by mem_cgroup_force_empty_list are temporal and there is no way out.
> 
> The main use case for the knob as described by
> Documentation/cgroups/memory.txt is to:
> "
>   The typical use case for this interface is before calling rmdir().
>   Because rmdir() moves all pages to parent, some out-of-use page caches can be
>   moved to the parent. If you want to avoid that, force_empty will be useful.
> "
> 
> This means that reparenting is not really required as rmdir will
> reparent pages implicitly from the safe context. If we remove it from
> mem_cgroup_force_empty then we are safe even with existing tasks because
> the number of reclaim attempts is bounded. Moreover the knob still does
> what the documentation claims (modulo reparenting which doesn't make any
> difference) and users might expect. Longterm we want to deprecate the
> whole knob and put the reparented pages to the tail of parent LRU during
> cgroup removal.

Yeah, let's deprecate the knob, but please change this to "deal with
left-over pages during cgroup removal".  Reparenting is an
implementation detail.

In fact, now that Tejun made offlined csss iterable, we can make
charges pin the css beyond cgroup lifetime and just reclaim leftovers
from their original css.  Then get rid of exit-reparenting entirely.

Should also make kmemcg handling during cgroup removal much easier...

[ I was going to send patches to do all this already but couldn't get
  them ready in time before my vacation. ]

> Signed-off-by: Tejun Heo <tj@kernel.org>
> Signed-off-by: Michal Hocko <mhocko@suse.cz>

Acked-by: Johannes Weiner <hannes@cmpxchg.org>

  parent reply	other threads:[~2014-05-13 13:16 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-09 21:31 [PATCHSET cgroup/for-3.16] cgroup: iterate cgroup_subsys_states directly Tejun Heo
2014-05-09 21:31 ` [PATCH 01/14] cgroup: remove css_parent() Tejun Heo
2014-05-11  1:47   ` David Miller
2014-05-11 13:02   ` Neil Horman
2014-05-12 13:16   ` Michal Hocko
2014-05-13 18:50   ` [PATCH v2 " Tejun Heo
2014-05-09 21:31 ` [PATCH 02/14] cgroup: remove pointless has tasks/children test from mem_cgroup_force_empty() Tejun Heo
2014-05-12 14:53   ` Michal Hocko
2014-05-12 14:58     ` [PATCH] memcg: deprecate memory.force_empty knob Michal Hocko
2014-05-12 15:00       ` Tejun Heo
2014-05-12 15:20         ` Michal Hocko
2014-05-12 15:25           ` Tejun Heo
2014-05-12 15:34             ` Michal Hocko
2014-05-13 13:16               ` Johannes Weiner
2014-05-13 15:09                 ` Michal Hocko
2014-05-12 14:59     ` [PATCH 02/14] cgroup: remove pointless has tasks/children test from mem_cgroup_force_empty() Tejun Heo
2014-05-12 15:21       ` Michal Hocko
2014-05-13 13:10     ` Johannes Weiner [this message]
2014-05-13 16:46     ` Tejun Heo
2014-05-13 18:51     ` [PATCH UPDATED 02/14] memcg: remove " Tejun Heo
2014-05-09 21:31 ` [PATCH 03/14] memcg: update memcg_has_children() to use css_next_child() Tejun Heo
2014-05-12 15:18   ` Michal Hocko
2014-05-13 16:53   ` [PATCH v2 " Tejun Heo
2014-05-09 21:31 ` [PATCH 04/14] device_cgroup: remove direct access to cgroup->children Tejun Heo
2014-05-13 12:56   ` Aristeu Rozanski
2014-05-14 12:52   ` Serge E. Hallyn
2014-05-09 21:31 ` [PATCH 05/14] cgroup: remove cgroup->parent Tejun Heo
2014-05-09 21:31 ` [PATCH 06/14] cgroup: move cgroup->sibling and ->children into cgroup_subsys_state Tejun Heo
2014-05-09 21:31 ` [PATCH 07/14] cgroup: link all cgroup_subsys_states in their sibling lists Tejun Heo
2014-05-09 21:31 ` [PATCH 08/14] cgroup: move cgroup->serial_nr into cgroup_subsys_state Tejun Heo
2014-05-09 21:31 ` [PATCH 09/14] cgroup: introduce CSS_RELEASED and reduce css iteration fallback window Tejun Heo
2014-05-16 16:07   ` [PATCH v2 " Tejun Heo
2014-05-09 21:31 ` [PATCH 10/14] cgroup: iterate cgroup_subsys_states directly Tejun Heo
2014-05-09 21:31 ` [PATCH 11/14] cgroup: use CSS_ONLINE instead of CGRP_DEAD Tejun Heo
2014-05-09 21:31 ` [PATCH 12/14] cgroup: convert cgroup_has_live_children() into css_has_online_children() Tejun Heo
2014-05-09 21:31 ` [PATCH 13/14] device_cgroup: use css_has_online_children() instead of has_children() Tejun Heo
2014-05-13 12:56   ` Aristeu Rozanski
2014-05-14 12:53   ` Serge E. Hallyn
2014-05-09 21:31 ` [PATCH 14/14] cgroup: implement css_tryget() Tejun Heo
2014-05-11  4:54   ` Johannes Weiner
2014-05-11 12:38     ` Tejun Heo
2014-05-16 16:07   ` [PATCH v2 " Tejun Heo
2014-05-13 16:59 ` [PATCHSET cgroup/for-3.16] cgroup: iterate cgroup_subsys_states directly Tejun Heo
2014-05-14  4:21 ` Li Zefan
2014-05-14 13:07   ` Tejun Heo
2014-05-16  1:28     ` Li Zefan
2014-05-16  1:29 ` Li Zefan
2014-05-16 16:08 ` Tejun Heo

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=20140513131014.GB18849@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=cgroups@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --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

all inboxes | Powered by JetHome®