linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: Roman Gushchin <guro@fb.com>
Cc: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	 Randy Dunlap <rdunlap@infradead.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	 Michal Hocko <mhocko@suse.com>,
	Vladimir Davydov <vdavydov.dev@gmail.com>,
	 Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
	 Souptick Joarder <jrdr.linux@gmail.com>,
	Yafang Shao <shaoyafang@didiglobal.com>
Subject: Re: [PATCH v2] mm, memcg: skip killing processes under memcg protection at first scan
Date: Tue, 20 Aug 2019 10:40:38 +0800	[thread overview]
Message-ID: <CALOAHbD2-x8PbNSWcWyEf6dSOozRTEAEd7hSmHYNMNwKRtAXXA@mail.gmail.com> (raw)
In-Reply-To: <CALOAHbDu7SkE4L36cZaaC8httd+UHyWzSjHqOmSa8S67p-kqEA@mail.gmail.com>

On Tue, Aug 20, 2019 at 10:01 AM Yafang Shao <laoar.shao@gmail.com> wrote:
>
> On Tue, Aug 20, 2019 at 9:40 AM Roman Gushchin <guro@fb.com> wrote:
> >
> > On Tue, Aug 20, 2019 at 09:16:01AM +0800, Yafang Shao wrote:
> > > On Tue, Aug 20, 2019 at 5:12 AM Roman Gushchin <guro@fb.com> wrote:
> > > >
> > > > On Sun, Aug 18, 2019 at 09:18:06PM -0400, Yafang Shao wrote:
> > > > > In the current memory.min design, the system is going to do OOM instead
> > > > > of reclaiming the reclaimable pages protected by memory.min if the
> > > > > system is lack of free memory. While under this condition, the OOM
> > > > > killer may kill the processes in the memcg protected by memory.min.
> > > > > This behavior is very weird.
> > > > > In order to make it more reasonable, I make some changes in the OOM
> > > > > killer. In this patch, the OOM killer will do two-round scan. It will
> > > > > skip the processes under memcg protection at the first scan, and if it
> > > > > can't kill any processes it will rescan all the processes.
> > > > >
> > > > > Regarding the overhead this change may takes, I don't think it will be a
> > > > > problem because this only happens under system  memory pressure and
> > > > > the OOM killer can't find any proper victims which are not under memcg
> > > > > protection.
> > > >
> > > > Hi Yafang!
> > > >
> > > > The idea makes sense at the first glance, but actually I'm worried
> > > > about mixing per-memcg and per-process characteristics.
> > > > Actually, it raises many questions:
> > > > 1) if we do respect memory.min, why not memory.low too?
> > >
> > > memroy.low is different with memory.min, as the OOM killer will not be
> > > invoked when it is reached.
> > > If memory.low should be considered as well, we can use
> > > mem_cgroup_protected() here to repclace task_under_memcg_protection()
> > > here.
> > >
> > > > 2) if the task is 200Gb large, does 10Mb memory protection make any
> > > > difference? if so, why would we respect it?
> > >
> > > Same with above, only consider it when the proctecion is enabled.
> >
> > Right, but memory.min is a number, not a boolean flag. It defines
> > how much memory is protected. You're using it as an on-off knob,
> > which is sub-optimal from my point of view.
> >
>
> I mean using mem_cgroup_protected(), sam with memory.min is
> implementad in the global reclaim path.
>
> > >
> > > > 3) if it works for global OOMs, why not memcg-level OOMs?
> > >
> > > memcg OOM is when the memory limit is reached and it can't find
> > > something to relcaim in the memcg and have to kill processes in this
> > > memcg.
> > > That is different with global OOM, because the global OOM can chose
> > > processes outside the memcg but the memcg OOM can't.
> >
> > Imagine the following hierarchy:
> >      /
> >      |
> >      A         memory.max = 10G, memory.min = 2G
> >     / \
> >    B   C       memory.min = 1G, memory.min = 0
> >
> > Say, you have memcg OOM in A, why B's memory min is not respected?
> > How it's different to the system-wide OOM?
> >
>
> Ah, this should be considered as well. Thanks for pointing out.
>
> > >
> > > > 4) if the task is prioritized to be killed by OOM (via oom_score_adj),
> > > > why even small memory.protection prevents it completely?
> > >
> > > Would you pls. show me some examples that when we will set both
> > > memory.min(meaning the porcesses in this memcg is very important) and
> > > higher oom_score_adj(meaning the porcesses in this memcg is not
> > > improtant at all) ?
> > > Note that the memory.min don't know which processes is important,
> > > while it only knows is if this process in this memcg.
> >
> > For instance, to prefer a specific process to be killed in case
> > of memcg OOM.
> > Also, memory.min can be used mostly to preserve the pagecache,
> > and an OOM kill means nothing but some anon memory leak.
> > In this case, it makes no sense to protect the leaked task.
> >
>
> But actually what memory.min protected is the memory usage, instead of
> pagecache,
> e.g. if the anon memory is higher than memory.min, then memroy.min
> can't protect file memory when swap is off.
>
> Even there is no anon memory leak, the OOM killer can also be invoked
> due to excess use of memroy.
> Plus, the memory.min can also protect the leaked anon memroy in
> current implementation.
>

BTW, if there are two different memcgs open the same file, the memcg
proection will not work if one memcg is protected while another memcg
is not protected.
But that may be a rare case.

> > >
> > > > 5) if there are two tasks similar in size and both protected,
> > > > should we prefer one with the smaller protection?
> > > > etc.
> > >
> > > Same with the answer in 1).
> >
> > So the problem is not that your patch is incorrect (or the idea is bad),
> > but you're defining a new policy, which will be impossible or very hard
> > to change further (as any other policy).
> >
> > So it's important to define it very well. Using the memory.min
> > number as a binary flag for selecting tasks seems a bit limited.
> >
> >
> > Thanks!


  reply	other threads:[~2019-08-20  2:41 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-19  1:18 Yafang Shao
2019-08-19 21:12 ` Roman Gushchin
2019-08-20  1:16   ` Yafang Shao
2019-08-20  1:39     ` Roman Gushchin
2019-08-20  2:01       ` Yafang Shao
2019-08-20  2:40         ` Yafang Shao [this message]
2019-08-20  6:40     ` Michal Hocko
2019-08-20  7:15       ` Yafang Shao
2019-08-20  7:27         ` Michal Hocko
2019-08-20  7:49           ` Yafang Shao
2019-08-20  8:34             ` Michal Hocko
2019-08-20  8:55               ` Yafang Shao
2019-08-20  9:17                 ` Michal Hocko
2019-08-20  9:26                   ` Yafang Shao
2019-08-20 10:40                     ` Michal Hocko
2019-08-20 21:39 ` Roman Gushchin
2019-08-21  1:00   ` Yafang Shao
2019-08-21  6:44     ` Michal Hocko
2019-08-21  7:26       ` Yafang Shao
2019-08-21  8:05         ` Michal Hocko
2019-08-21  8:15           ` Yafang Shao
2019-08-21  8:34             ` Michal Hocko
2019-08-21  8:46               ` Yafang Shao

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=CALOAHbD2-x8PbNSWcWyEf6dSOozRTEAEd7hSmHYNMNwKRtAXXA@mail.gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=guro@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=jrdr.linux@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=rdunlap@infradead.org \
    --cc=shaoyafang@didiglobal.com \
    --cc=vdavydov.dev@gmail.com \
    /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