linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yang Shi <shy828301@gmail.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Roman Gushchin <guro@fb.com>, Kirill Tkhai <ktkhai@virtuozzo.com>,
	 Shakeel Butt <shakeelb@google.com>,
	Dave Chinner <david@fromorbit.com>,
	 Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@suse.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Linux MM <linux-mm@kvack.org>,
	 Linux FS-devel Mailing List <linux-fsdevel@vger.kernel.org>,
	 Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [v5 PATCH 10/11] mm: memcontrol: reparent nr_deferred when memcg offline
Date: Fri, 29 Jan 2021 09:38:01 -0800	[thread overview]
Message-ID: <CAHbLzkoE9DN7_5VCfy7yaVPKnrqW6ohCMxpvmKMC3-Tw5-pGgA@mail.gmail.com> (raw)
In-Reply-To: <0eee1cbd-4149-9f03-615d-18c81b8a85af@suse.cz>

On Fri, Jan 29, 2021 at 7:52 AM Vlastimil Babka <vbabka@suse.cz> wrote:
>
> On 1/28/21 12:33 AM, Yang Shi wrote:
> > Now shrinker's nr_deferred is per memcg for memcg aware shrinkers, add to parent's
> > corresponding nr_deferred when memcg offline.
> >
> > Signed-off-by: Yang Shi <shy828301@gmail.com>
>
> Acked-by: Vlastimil Babka <vbabka@suse.cz>
>
> A question somewhat outside of the scope of the series. Should we shrink before
> reparenting on memcg offline? Would it make more sense than assume the kmemcg
> objects that are still cached are used also by others?

TBH, I'm not sure. I think it depends on workload. For example, the
build server may prefer to keep the objects cached since the samce
objects may be reused by multiple build jobs.

>
> > ---
> >  include/linux/memcontrol.h |  1 +
> >  mm/memcontrol.c            |  1 +
> >  mm/vmscan.c                | 31 +++++++++++++++++++++++++++++++
> >  3 files changed, 33 insertions(+)
> >
> > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > index e0384367e07d..fe1375f08881 100644
> > --- a/include/linux/memcontrol.h
> > +++ b/include/linux/memcontrol.h
> > @@ -1586,6 +1586,7 @@ extern int alloc_shrinker_info(struct mem_cgroup *memcg);
> >  extern void free_shrinker_info(struct mem_cgroup *memcg);
> >  extern void set_shrinker_bit(struct mem_cgroup *memcg,
> >                            int nid, int shrinker_id);
> > +extern void reparent_shrinker_deferred(struct mem_cgroup *memcg);
> >  #else
> >  #define mem_cgroup_sockets_enabled 0
> >  static inline void mem_cgroup_sk_alloc(struct sock *sk) { };
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index f64ad0d044d9..21f36b73f36a 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -5282,6 +5282,7 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
> >       page_counter_set_low(&memcg->memory, 0);
> >
> >       memcg_offline_kmem(memcg);
> > +     reparent_shrinker_deferred(memcg);
> >       wb_memcg_offline(memcg);
> >
> >       drain_all_stock(memcg);
> > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > index 0373d7619d7b..55ad91a26ba3 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -386,6 +386,37 @@ static long set_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker,
> >       return atomic_long_add_return(nr, &info->nr_deferred[shrinker->id]);
> >  }
> >
> > +static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg,
> > +                                                  int nid)
> > +{
> > +     return rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_info,
> > +                                      lockdep_is_held(&shrinker_rwsem));
> > +}
> > +
> > +void reparent_shrinker_deferred(struct mem_cgroup *memcg)
> > +{
> > +     int i, nid;
> > +     long nr;
> > +     struct mem_cgroup *parent;
> > +     struct shrinker_info *child_info, *parent_info;
> > +
> > +     parent = parent_mem_cgroup(memcg);
> > +     if (!parent)
> > +             parent = root_mem_cgroup;
> > +
> > +     /* Prevent from concurrent shrinker_info expand */
> > +     down_read(&shrinker_rwsem);
> > +     for_each_node(nid) {
> > +             child_info = shrinker_info_protected(memcg, nid);
> > +             parent_info = shrinker_info_protected(parent, nid);
> > +             for (i = 0; i < shrinker_nr_max; i++) {
> > +                     nr = atomic_long_read(&child_info->nr_deferred[i]);
> > +                     atomic_long_add(nr, &parent_info->nr_deferred[i]);
> > +             }
> > +     }
> > +     up_read(&shrinker_rwsem);
> > +}
> > +
> >  static bool cgroup_reclaim(struct scan_control *sc)
> >  {
> >       return sc->target_mem_cgroup;
> >
>


  reply	other threads:[~2021-01-29 17:38 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27 23:33 [v5 PATCH 0/11] Make shrinker's nr_deferred memcg aware Yang Shi
2021-01-27 23:33 ` [v5 PATCH 01/11] mm: vmscan: use nid from shrink_control for tracepoint Yang Shi
2021-01-28 16:02   ` Vlastimil Babka
2021-01-27 23:33 ` [v5 PATCH 02/11] mm: vmscan: consolidate shrinker_maps handling code Yang Shi
2021-01-28 16:10   ` Vlastimil Babka
2021-01-28 21:16     ` Yang Shi
2021-01-29 14:33   ` Kirill Tkhai
2021-01-29 17:11     ` Yang Shi
2021-01-27 23:33 ` [v5 PATCH 03/11] mm: vmscan: use shrinker_rwsem to protect shrinker_maps allocation Yang Shi
2021-01-28 16:19   ` Vlastimil Babka
2021-01-27 23:33 ` [v5 PATCH 04/11] mm: vmscan: remove memcg_shrinker_map_size Yang Shi
2021-01-28 16:53   ` Vlastimil Babka
2021-01-28 21:22     ` Yang Shi
2021-01-29 11:22       ` Vlastimil Babka
2021-01-29 17:05         ` Yang Shi
2021-01-27 23:33 ` [v5 PATCH 05/11] mm: memcontrol: rename shrinker_map to shrinker_info Yang Shi
2021-01-28 17:38   ` Vlastimil Babka
2021-01-28 22:05     ` Yang Shi
2021-01-27 23:33 ` [v5 PATCH 06/11] mm: vmscan: use a new flag to indicate shrinker is registered Yang Shi
2021-01-28 17:56   ` Vlastimil Babka
2021-01-28 23:47     ` Yang Shi
2021-01-27 23:33 ` [v5 PATCH 07/11] mm: vmscan: add per memcg shrinker nr_deferred Yang Shi
2021-01-29 13:00   ` Vlastimil Babka
2021-01-29 14:46     ` Kirill Tkhai
2021-01-29 17:20     ` Yang Shi
2021-01-29 18:04       ` Yang Shi
2021-02-01 15:17         ` Vlastimil Babka
2021-02-01 17:09           ` Yang Shi
2021-01-27 23:33 ` [v5 PATCH 08/11] mm: vmscan: use per memcg nr_deferred of shrinker Yang Shi
2021-01-29 14:55   ` Kirill Tkhai
2021-01-29 14:59     ` Kirill Tkhai
2021-01-29 17:22       ` Yang Shi
2021-01-29 15:13   ` Vlastimil Babka
2021-01-29 17:33     ` Yang Shi
2021-01-27 23:33 ` [v5 PATCH 09/11] mm: vmscan: don't need allocate shrinker->nr_deferred for memcg aware shrinkers Yang Shi
2021-01-29 15:40   ` Vlastimil Babka
2021-01-29 17:34     ` Yang Shi
2021-01-27 23:33 ` [v5 PATCH 10/11] mm: memcontrol: reparent nr_deferred when memcg offline Yang Shi
2021-01-29 15:52   ` Vlastimil Babka
2021-01-29 17:38     ` Yang Shi [this message]
2021-01-27 23:33 ` [v5 PATCH 11/11] mm: vmscan: shrink deferred objects proportional to priority Yang Shi

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=CAHbLzkoE9DN7_5VCfy7yaVPKnrqW6ohCMxpvmKMC3-Tw5-pGgA@mail.gmail.com \
    --to=shy828301@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@fromorbit.com \
    --cc=guro@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=ktkhai@virtuozzo.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=shakeelb@google.com \
    --cc=vbabka@suse.cz \
    /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;
as well as URLs for NNTP newsgroup(s).