[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJuCfpGn+7gtpUVv_T3ZvT7WEwP8z-c1z1Qu2qe1jq8RSxbHMA@mail.gmail.com>
Date: Fri, 21 Aug 2020 11:53:00 -0700
From: Suren Baghdasaryan <surenb@...gle.com>
To: Oleg Nesterov <oleg@...hat.com>
Cc: "Eric W. Biederman" <ebiederm@...ssion.com>,
Michal Hocko <mhocko@...e.com>,
Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>,
Christian Brauner <christian.brauner@...ntu.com>,
Tim Murray <timmurray@...gle.com>, mingo@...nel.org,
Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>, esyr@...hat.com,
christian@...lner.me, areber@...hat.com,
Shakeel Butt <shakeelb@...gle.com>, cyphar@...har.com,
adobriyan@...il.com, Andrew Morton <akpm@...ux-foundation.org>,
gladkov.alexey@...il.com, Michel Lespinasse <walken@...gle.com>,
daniel.m.jordan@...cle.com, avagin@...il.com,
bernd.edlinger@...mail.de,
John Johansen <john.johansen@...onical.com>,
laoar.shao@...il.com, Minchan Kim <minchan@...nel.org>,
kernel-team <kernel-team@...roid.com>,
LKML <linux-kernel@...r.kernel.org>,
linux-fsdevel@...r.kernel.org, linux-mm <linux-mm@...ck.org>
Subject: Re: [PATCH 1/1] mm, oom_adj: don't loop through tasks in
__set_oom_adj when not necessary
On Fri, Aug 21, 2020 at 11:00 AM Oleg Nesterov <oleg@...hat.com> wrote:
>
> On 08/21, Oleg Nesterov wrote:
> >
> > On 08/21, Suren Baghdasaryan wrote:
> > >
> > > On Fri, Aug 21, 2020 at 4:16 AM Oleg Nesterov <oleg@...hat.com> wrote:
> > > >
> > > > bool probably_has_other_mm_users(tsk)
> > > > {
> > > > return atomic_read_acquire(&tsk->mm->mm_users) >
> > > > atomic_read(&tsk->signal->live);
> > > > }
> > > >
> > > > The barrier implied by _acquire ensures that if we race with the exiting
> > > > task and see the result of exit_mm()->mmput(mm), then we must also see
> > > > the result of atomic_dec_and_test(signal->live).
> > > >
> > > > Either way, if we want to fix the race with clone(CLONE_VM) we need other
> > > > changes.
> > >
> > > The way I understand this condition in __set_oom_adj() sync logic is
> > > that we would be ok with false positives (when we loop unnecessarily)
> > > but we can't tolerate false negatives (when oom_score_adj gets out of
> > > sync).
> >
> > Yes,
> >
> > > With the clone(CLONE_VM) race not addressed we are allowing
> > > false negatives and IMHO that's not acceptable because it creates a
> > > possibility for userspace to get an inconsistent picture. When
> > > developing the patch I did think about using (p->mm->mm_users >
> > > p->signal->nr_threads) condition and had to reject it due to that
> > > reason.
> >
> > Not sure I understand... I mean, the test_bit(MMF_PROC_SHARED) you propose
> > is equally racy and we need copy_oom_score() at the end of copy_process()
> > either way?
>
> On a second thought I agree that probably_has_other_mm_users() above can't
> work ;) Compared to the test_bit(MMF_PROC_SHARED) check it is not _equally_
> racy, it adds _another_ race with clone(CLONE_VM).
>
> Suppose a single-threaded process P does
>
> clone(CLONE_VM); // creates the child C
>
> // mm_users == 2; P->signal->live == 1;
>
> clone(CLONE_THREAD | CLONE_VM);
>
> // mm_users == 3; P->signal->live == 2;
>
> the problem is that in theory clone(CLONE_THREAD | CLONE_VM) can increment
> _both_ counters between atomic_read_acquire(mm_users) and atomic_read(live)
> in probably_has_other_mm_users() so it can observe mm_users == live == 2.
I see. So even though live is incremented after mm_users, the observer
from __set_oom_adj still can see them becoming equal because it reads
mm_users first.
Do you see any such races if I incorporate the changes proposed by
Michal in http://lkml.kernel.org/r/20200820124109.GI5033@dhcp22.suse.cz
? I have the new patch and I'm testing it right now. So far it behaves
well but maybe I'm missing some rare race here that won't show up in
my testing?
>
> Oleg.
>
> --
> To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@...roid.com.
>
Powered by blists - more mailing lists