Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1265426

Re: [PATCH] mm/hugetlb: Unmap pages if page fault raced with hole punch

From Hugh Dickins <hughd@google.com>
Newsgroups linux.kernel
Subject Re: [PATCH] mm/hugetlb: Unmap pages if page fault raced with hole punch
Date 2015-11-09 08:50 +0100
Message-ID <qsPnc-3rE-29@gated-at.bofh.it> (permalink)
References <qp41r-69d-3@gated-at.bofh.it> <qp8HM-DT-17@gated-at.bofh.it> <qpl2j-8b8-27@gated-at.bofh.it> <qpoWe-25R-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [PATCH] mm/hugetlb: Unmap pages if page fault raced with hole  punch Hugh Dickins <hughd@google.com> - 2015-11-09 08:50 +0100
  Re: [PATCH] mm/hugetlb: Unmap pages if page fault raced with hole  punch Mike Kravetz <mike.kravetz@oracle.com> - 2015-11-10 00:00 +0100
    Re: [PATCH] mm/hugetlb: Unmap pages if page fault raced with hole  punch Mike Kravetz <mike.kravetz@oracle.com> - 2015-11-10 23:50 +0100
      Re: [PATCH] mm/hugetlb: Unmap pages if page fault raced with hole  punch Hugh Dickins <hughd@google.com> - 2015-11-14 01:40 +0100

csiph-web