From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: David Rientjes <rientjes@google.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: set_bit() + down_write()
Date: Wed, 6 Dec 2017 10:18:20 -0800 [thread overview]
Message-ID: <20171206181820.GZ7829@linux.vnet.ibm.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1712060143140.135315@chino.kir.corp.google.com>
On Wed, Dec 06, 2017 at 01:48:17AM -0800, David Rientjes wrote:
> Hi Paul,
>
> I have a question about whether this code in exit_mmap() could be racy:
>
> set_bit(MMF_OOM_SKIP, &mm->flags);
> if (unlikely(tsk_is_oom_victim(current))) {
> /*
> * Wait for oom_reap_task() to stop working on this
> * mm. Because MMF_OOM_SKIP is already set before
> * calling down_read(), oom_reap_task() will not run
> * on this "mm" post up_write().
> *
> * tsk_is_oom_victim() cannot be set from under us
> * either because current->mm is already set to NULL
> * under task_lock before calling mmput and oom_mm is
> * set not NULL by the OOM killer only if current->mm
> * is found not NULL while holding the task_lock.
> */
> down_write(&mm->mmap_sem);
> up_write(&mm->mmap_sem);
> }
>
> This is supposed to serialize __oom_reap_task_mm() from operating on an mm
> with MMF_OOM_SKIP set while under the protection of
> down_read(&mm->mmap_sem).
>
> Is it possible that MMF_OOM_SKIP above actually gets set after up_write()?
>
> If so, that would explain why we see the oom reaper operating on mm's with
> MMF_OOM_SKIP set.
Well, set_bit() has no ordering semantics, but up_write() does provide
some ordering, but is not fully ordered. So it all depends on what
the other end is doing.
If the other end is this same task, then it will see things fully ordered.
If the other end holds ->mmap_sem, then it will see things fully ordered.
If the other end does not hold ->mmap_sem, things are more complicated,
and it depends on exactly what the other end is doing. As an example
(not directly related to your example above), here is something that
would -not- be guaranteed to be ordered:
Task 0:
...
WRITE_ONCE(x, 1);
WRITE_ONCE(y, 1);
up_write(&mm->mmap_sem);
Task 1:
down_write(&mm->mmap_sem);
r1 = READ_ONCE(z);
r2 = READ_ONCE(y);
...
Task 2:
WRITE_ONCE(z, 1);
smp_mb();
r3 = READ_ONCE(x);
It really is possible on some architectures to end up with r1==0,
r2==1, and r3==0.
But what exactly was the other end doing? What architecture were you
running on? And what version of Linux were you using?
Thanx, Paul
parent reply other threads:[~2017-12-06 18:18 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <alpine.DEB.2.10.1712060143140.135315@chino.kir.corp.google.com>]
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=20171206181820.GZ7829@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rientjes@google.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