linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Hugh Dickins <hughd@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
	Davidlohr Bueso <dave@stgolabs.net>
Subject: Re: [PATCH] mm/hugetlb: Unmap pages if page fault raced with hole punch
Date: Sun, 8 Nov 2015 23:42:16 -0800 (PST)	[thread overview]
Message-ID: <alpine.LSU.2.11.1511082310390.15826@eggly.anvils> (raw)
In-Reply-To: <5633D984.7080307@oracle.com>

On Fri, 30 Oct 2015, Mike Kravetz wrote:
> 
> The 'next = start' code is actually from the original truncate_hugepages
> routine.  This functionality was combined with that needed for hole punch
> to create remove_inode_hugepages().
> 
> The following code was in truncate_hugepages:
> 
> 	next = start;
> 	while (1) {
> 		if (!pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE)) {
> 			if (next == start)
> 				break;
> 			next = start;
> 			continue;
> 		}
> 
> 
> So, in the truncate case pages starting at 'start' are deleted until
> pagevec_lookup fails.  Then, we call pagevec_lookup() again.  If no
> pages are found we are done.  Else, we repeat the whole process.
> 
> Does anyone recall the reason for going back and looking for pages at
> index'es already deleted?  Git doesn't help as that was part of initial
> commit.  My thought is that truncate can race with page faults.  The
> truncate code sets inode offset before unmapping and deleting pages.
> So, faults after the new offset is set should fail.  But, I suppose a
> fault could race with setting offset and deleting of pages.  Does this
> sound right?  Or, is there some other reason I am missing?

I believe your thinking is correct.  But remember that
truncate_inode_pages_range() is shared by almost all filesystems,
and different filesystems have different internal locking conventions,
and different propensities to such a race: it's trying to cover for
all of them.

Typically, writing is well serialized (by i_mutex) against truncation,
but faulting (like reading) sails through without enough of a lock.
We resort to i_size checks to avoid the worst of it, but there's often
a corner or two in which those checks are not quite good enough -
it's easy to check i_size at the beginning, but it needs to be checked
again at the end too, and what's been done undone - can be awkward.

I hope that in the case of hugetlbfs, since you already have the
additional fault_mutex to handle races between faults and punching,
it should be possible to get away without that "pincer" restarting.

Hugh

> 
> I would like to continue having remove_inode_hugepages handle both the
> truncate and hole punch case.  So, what to make sure the code correctly
> handles both cases.
> 
> -- 
> Mike Kravetz

  reply	other threads:[~2015-11-09  7:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-29 22:33 [PATCH] mm/hugetlb: Unmap pages if page fault raced with hole punch Mike Kravetz
2015-10-30  3:32 ` Hugh Dickins
2015-10-30 16:45   ` Mike Kravetz
2015-10-30 20:56     ` Mike Kravetz
2015-11-09  7:42       ` Hugh Dickins [this message]
2015-11-09 22:55         ` Mike Kravetz
2015-11-10 22:41           ` Mike Kravetz
2015-11-14  0:36             ` Hugh Dickins

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.LSU.2.11.1511082310390.15826@eggly.anvils \
    --to=hughd@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=dave@stgolabs.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=n-horiguchi@ah.jp.nec.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;
as well as URLs for NNTP newsgroup(s).