linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Rientjes <rientjes@google.com>
To: Alex Thorlton <athorlton@sgi.com>
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Mel Gorman <mgorman@suse.de>, Rik van Riel <riel@redhat.com>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-mm@kvack.org
Subject: Re: [BUG] mm: thp: hugepage_vma_check has a blind spot
Date: Tue, 21 Jan 2014 15:24:08 -0800 (PST)	[thread overview]
Message-ID: <alpine.DEB.2.02.1401211519530.15306@chino.kir.corp.google.com> (raw)
In-Reply-To: <1390345671-136133-1-git-send-email-athorlton@sgi.com>

On Tue, 21 Jan 2014, Alex Thorlton wrote:

> hugepage_vma_check is called during khugepaged_scan_mm_slot to ensure
> that khugepaged doesn't try to allocate THPs in vmas where they are
> disallowed, either due to THPs being disabled system-wide, or through
> MADV_NOHUGEPAGE.
> 
> The logic that hugepage_vma_check uses doesn't seem to cover all cases,
> in my opinion.  Looking at the original code:
> 
>        if ((!(vma->vm_flags & VM_HUGEPAGE) && !khugepaged_always()) ||
> 	   (vma->vm_flags & VM_NOHUGEPAGE))
> 
> We can see that it's possible to have THP disabled system-wide, but still
> receive THPs in this vma.  It seems that it's assumed that just because
> khugepaged_always == false, TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG must be
> set, which is not the case.  We could have VM_HUGEPAGE set, but have THP
> set to "never" system-wide, in which case, the condition presented in the
> if will evaluate to false, and (provided the other checks pass) we can
> end up giving out a THP even though the behavior is set to "never."
> 

You should be able to add a

	BUG_ON(current != khugepaged_thread);

here since khugepaged is supposed to be the only caller to the function.

> While we do properly check these flags in khugepaged_has_work, it looks
> like it's possible to sleep after we check khugepaged_hask_work, but
> before hugepage_vma_check, during which time, hugepages could have been
> disabled system-wide, in which case, we could hand out THPs when we
> shouldn't be.
> 

You're talking about when thp is set to "never" and before khugepaged has 
stopped, correct?

That doesn't seem like a bug to me or anything that needs to be fixed, the 
sysfs knob could be switched even after hugepage_vma_check() is called and 
before a hugepage is actually collapsed so you have the same race.

The only thing that's guaranteed is that, upon writing "never" to 
/sys/kernel/mm/transparent_hugepage/enabled, no more thp memory will be 
collapsed after khugepaged has stopped.

--
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:[~2014-01-21 23:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-21 23:07 Alex Thorlton
2014-01-21 23:24 ` David Rientjes [this message]
2014-01-22 18:14   ` Alex Thorlton

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=alpine.DEB.2.02.1401211519530.15306@chino.kir.corp.google.com \
    --to=rientjes@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=athorlton@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.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