linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
To: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Michal Hocko <mhocko@suse.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: Multiple oom_reaper BUGs: unmap_page_range racing with exit_mmap
Date: Wed, 06 Dec 2017 12:28:53 +0900	[thread overview]
Message-ID: <201712060328.vB63SrDK069830@www262.sakura.ne.jp> (raw)
In-Reply-To: <alpine.DEB.2.10.1712051857450.98120@chino.kir.corp.google.com>

David Rientjes wrote:
> On Tue, 5 Dec 2017, David Rientjes wrote:
> 
> > One way to solve the issue is to have two mm flags: one to indicate the mm 
> > is entering unmap_vmas(): set the flag, do down_write(&mm->mmap_sem); 
> > up_write(&mm->mmap_sem), then unmap_vmas().  The oom reaper needs this 
> > flag clear, not MMF_OOM_SKIP, while holding down_read(&mm->mmap_sem) to be 
> > allowed to call unmap_page_range().  The oom killer will still defer 
> > selecting this victim for MMF_OOM_SKIP after unmap_vmas() returns.
> > 
> > The result of that change would be that we do not oom reap from any mm 
> > entering unmap_vmas(): we let unmap_vmas() do the work itself and avoid 
> > racing with it.
> > 
> 
> I think we need something like the following?

This patch does not work. __oom_reap_task_mm() can find MMF_REAPING and
return true and sets MMF_OOM_SKIP before exit_mmap() calls down_write().

Also, I don't know what exit_mmap() is doing but I think that there is a
possibility that the OOM reaper tries to reclaim mlocked pages as soon as
exit_mmap() cleared VM_LOCKED flag by calling munlock_vma_pages_all().

	if (mm->locked_vm) {
		vma = mm->mmap;
		while (vma) {
			if (vma->vm_flags & VM_LOCKED)
				munlock_vma_pages_all(vma);
			vma = vma->vm_next;
		}
	}

/*
 * munlock_vma_pages_range() - munlock all pages in the vma range.'
 * @vma - vma containing range to be munlock()ed.
 * @start - start address in @vma of the range
 * @end - end of range in @vma.
 *
 *  For mremap(), munmap() and exit().
 *
 * Called with @vma VM_LOCKED.
 *
 * Returns with VM_LOCKED cleared.  Callers must be prepared to
 * deal with this.
 *
 * We don't save and restore VM_LOCKED here because pages are
 * still on lru.  In unmap path, pages might be scanned by reclaim
 * and re-mlocked by try_to_{munlock|unmap} before we unmap and
 * free them.  This will result in freeing mlocked pages.
 */
void munlock_vma_pages_range(struct vm_area_struct *vma,
                             unsigned long start, unsigned long end)
{
	vma->vm_flags &= VM_LOCKED_CLEAR_MASK;

	while (start < end) {
		/*
		 * Things for munlock() are done here. But at this point,
		 * __oom_reap_task_mm() can call unmap_page_range() because
		 * can_madv_dontneed_vma() returns true due to VM_LOCKED
		 * being already cleared and MMF_OOM_SKIP is not yet set.
		 */
	}
}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2017-12-06  4:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-06  2:43 David Rientjes
2017-12-06  2:58 ` David Rientjes
2017-12-06  3:28   ` Tetsuo Handa [this message]
2017-12-06  7:48     ` David Rientjes
2017-12-06  9:00       ` Michal Hocko
2017-12-07  7:20         ` Tetsuo Handa
2017-12-07  8:28           ` Michal Hocko
2017-12-07  8:44             ` Michal Hocko
2017-12-07 11:00             ` Tetsuo Handa
2017-12-07 21:22             ` David Rientjes
2017-12-08  7:50               ` Michal Hocko
2017-12-06 11:37       ` Tetsuo Handa
2017-12-06  8:50     ` Michal Hocko
2017-12-06  8:31 ` Michal Hocko
2017-12-07 11:35 ` Michal Hocko
2017-12-07 15:44   ` Tetsuo Handa
2017-12-07 16:30     ` Michal Hocko
2017-12-07 21:55       ` David Rientjes
2017-12-08  9:26         ` David Rientjes
2017-12-08 11:27           ` Michal Hocko
2017-12-08 10:11       ` Tetsuo Handa

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=201712060328.vB63SrDK069830@www262.sakura.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --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