[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <874koxuzks.fsf@x220.int.ebiederm.org>
Date: Thu, 20 Aug 2020 10:06:11 -0500
From: ebiederm@...ssion.com (Eric W. Biederman)
To: Oleg Nesterov <oleg@...hat.com>
Cc: Michal Hocko <mhocko@...e.com>,
Suren Baghdasaryan <surenb@...gle.com>,
christian.brauner@...ntu.com, mingo@...nel.org,
peterz@...radead.org, tglx@...utronix.de, esyr@...hat.com,
christian@...lner.me, areber@...hat.com, shakeelb@...gle.com,
cyphar@...har.com, adobriyan@...il.com, akpm@...ux-foundation.org,
gladkov.alexey@...il.com, walken@...gle.com,
daniel.m.jordan@...cle.com, avagin@...il.com,
bernd.edlinger@...mail.de, john.johansen@...onical.com,
laoar.shao@...il.com, timmurray@...gle.com, minchan@...nel.org,
kernel-team@...roid.com, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH 1/1] mm, oom_adj: don't loop through tasks in __set_oom_adj when not necessary
Oleg Nesterov <oleg@...hat.com> writes:
> On 08/20, Oleg Nesterov wrote:
>>
>> On 08/20, Eric W. Biederman wrote:
>> >
>> > --- a/fs/exec.c
>> > +++ b/fs/exec.c
>> > @@ -1139,6 +1139,10 @@ static int exec_mmap(struct mm_struct *mm)
>> > vmacache_flush(tsk);
>> > task_unlock(tsk);
>> > if (old_mm) {
>> > + mm->oom_score_adj = old_mm->oom_score_adj;
>> > + mm->oom_score_adj_min = old_mm->oom_score_adj_min;
>> > + if (tsk->vfork_done)
>> > + mm->oom_score_adj = tsk->vfork_oom_score_adj;
>>
>> too late, ->vfork_done is NULL after mm_release().
>>
>> And this can race with __set_oom_adj(). Yes, the current code is racy too,
>> but this change adds another race, __set_oom_adj() could already observe
>> ->mm != NULL and update mm->oom_score_adj.
> ^^^^^^^^^^^^
>
> I meant ->mm == new_mm.
>
> And another problem. Suppose we have
>
> if (!vfork()) {
> change_oom_score();
> exec();
> }
>
> the parent can be killed before the child execs, in this case vfork_oom_score_adj
> will be lost.
Yes.
Looking at include/uapi/linux/oom.h it appears that there are a lot of
oom_score_adj values that are reserved. So it should be completely
possible to initialize vfork_oom_score_adj to -32768 aka SHRT_MIN, and
use that as a flag to see if it is active or not.
Likewise for vfork_oom_score_adj_min if we need to duplicate that one as
well.
That deals with that entire class of race. We still have races during
exec about vfork_done being cleared before the new ->mm == new_mm.
While that is worth fixing is an independent issue.
Eric
Powered by blists - more mailing lists