linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrea Arcangeli <aarcange@redhat.com>
To: Christoph Lameter <cl@linux-foundation.org>
Cc: linux-mm@kvack.org, Marcelo Tosatti <mtosatti@redhat.com>,
	Adam Litke <agl@us.ibm.com>, Avi Kivity <avi@redhat.com>,
	Izik Eidus <ieidus@redhat.com>,
	Hugh Dickins <hugh.dickins@tiscali.co.uk>,
	Nick Piggin <npiggin@suse.de>, Rik van Riel <riel@redhat.com>,
	Mel Gorman <mel@csn.ul.ie>, Dave Hansen <dave@linux.vnet.ibm.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Ingo Molnar <mingo@elte.hu>, Mike Travis <travis@sgi.com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Chris Wright <chrisw@sous-sol.org>,
	bpicco@redhat.com,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	Balbir Singh <balbir@linux.vnet.ibm.com>,
	Arnd Bergmann <arnd@arndb.de>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH 00 of 34] Transparent Hugepage support #14
Date: Mon, 22 Mar 2010 18:06:19 +0100	[thread overview]
Message-ID: <20100322170619.GQ29874@random.random> (raw)
In-Reply-To: <alpine.DEB.2.00.1003221027590.16606@router.home>

On Mon, Mar 22, 2010 at 10:38:23AM -0500, Christoph Lameter wrote:
> On Fri, 19 Mar 2010, Andrea Arcangeli wrote:
> 
> > > Look at the patches. They add synchronization to pte operations.
> >
> > The whole point is that it's fundamentally unavoidable and not
> > specific to any of split_huge_page, compound_lock or
> > get_page/put_page!
> 
> Really? Why did no one else run into this before?

Of course we run into this before too, and the locking in fact already
exists and you probably added it yourself when introducing the more
scalare PT lock for the pte.

For the pmd we always used the page_table_lock and I kept using
it. Except that before it was only necessary in __pte_alloc (see
mainline), now it's needed in more places because the pmd can be
modified as it points to actual pages that can go away, and not only
to ptes.

> > Problem with O_DIRECT is that I couldn't use mmu notifier to prevent
> > it to take the pin on the page, because there is no way to interrupt
> > DMA synchronously before mmu_notifier_invalidate_* returns... So I had
> > to add compound_lock and keep gup API backwards compatible and have
> > the proper serialization happen _only_ for PageTail inside put_page.
> 
> You can take a refcount *before* breaking up a 2M page then you dont have
> to fear the put_page.

If you take it _before_ it will go into the head page regardless of
which subpage was returned by gup. We need to know which subpages are
under DMA. The pin has to go to the tail pages or head page depending
on the physical address that was requested by gup. To fix this we need
at the very least to change gup api to ask for hugepages which it
can't right now because it'd break all drivers.

> Keep a reference count in the head page and a pointer to the subpage? Page
> can only be broken up if all page references of the 2M page can be
> accounted for. This implies no "atomic" breakup but this way it does not
> require changes to synchronization.

"can only broken up". See my last sentence of my previous reply to
figure out exactly why we're not ok if "page cannot be broken up".

besides even if we add a error retval, we can't have mprotect/mremap
fail at most swapout could be deferred because "page cannot be broken
up" but even that is risky and I've been extra careful not to require
any memory allocation or sleeping lock in split_huge_page to make it
ideal to use in swap path without risking any functional regression
whatsoever.

> That is the basic crux here. Do not require that it cannot fail. Its a bad
> move and results in a mess.

Allowing it to fail would result in a mess. Obviously I wasn't clear
enough in the last sentence of my previous mail so I'll have to
repeate: any effort in handling the failure (which in some case it
can't be handled as syscalls can't fail just because a page is 2M)
should instead be spent to _remove_ the split_huge_page call.

> No its not. I am proposing to *keep* the existing syncronization methods.
> Use what is there. Do not invent new synchronization.

You don't see the huge value of the invention. When you go around
implementing your own split_huge_page that will fail, you might see
it (or we can compare the size of the two patches then, knowing that
I add 1 line to mremap and you add hundreds or maybe you can't use
your split_huge_page there at all forcing you to handle 2M pages
immediately from the start). And mremap is not the big deal, it's that
if you can't use it in mremap you practically won't be able to use it
anywhere except in swap, where you will introduce a nasty unknown and
potential livelock or deadlock.

> We already have 2M pmd handling in the kernel and can consider huge pmd
> entries while walking the page tables! Go incrementally use what
> is there.

There's no such thing unless you talk about the hugetlbfs paths. In
the core paths that the only thing I care about in transparent
hugepage, pmd is only checked to be present. If it's present it can't
go away. This is not true anymore as it can point to user pages and
not ptes. I am definitely reusing the same synchronization for ptes
that already is used by __pte_alloc which is the only bit that
requires synchronization right now, to atomically check if the pmd is
still not present, before overwriting it.

Best of all, I had to add zero atomic ops and just 1 branch in already
hot l1 cache (and no writes to the l1 cache either, just 1 more read)
in order to add the pagefault slow path for huge pmd. So unless you
actively take advantage of hugepages, the page_table_lock locking will
be zero cost and in the future nothing prevents us to add a more
scalar PMD lock like it exists for the pte (but keep in mind it's much
512 times less important for PMD than it is for the PTE).

--
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>

  parent reply	other threads:[~2010-03-22 17:08 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-17 15:19 [PATCH 00 of 34] Transparent Hugepage support #14 Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 01 of 34] define MADV_HUGEPAGE Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 02 of 34] compound_lock Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 03 of 34] alter compound get_page/put_page Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 04 of 34] update futex compound knowledge Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 05 of 34] fix bad_page to show the real reason the page is bad Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 06 of 34] clear compound mapping Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 07 of 34] add native_set_pmd_at Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 08 of 34] add pmd paravirt ops Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 09 of 34] no paravirt version of pmd ops Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 10 of 34] export maybe_mkwrite Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 11 of 34] comment reminder in destroy_compound_page Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 12 of 34] config_transparent_hugepage Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 13 of 34] special pmd_trans_* functions Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 14 of 34] add pmd mangling generic functions Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 15 of 34] add pmd mangling functions to x86 Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 16 of 34] bail out gup_fast on splitting pmd Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 17 of 34] pte alloc trans splitting Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 18 of 34] add pmd mmu_notifier helpers Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 19 of 34] clear page compound Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 20 of 34] add pmd_huge_pte to mm_struct Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 21 of 34] split_huge_page_mm/vma Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 22 of 34] split_huge_page paging Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 23 of 34] clear_copy_huge_page Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 24 of 34] kvm mmu transparent hugepage support Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 25 of 34] _GFP_NO_KSWAPD Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 26 of 34] don't alloc harder for gfp nomemalloc even if nowait Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 27 of 34] transparent hugepage core Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 28 of 34] verify pmd_trans_huge isn't leaking Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 29 of 34] madvise(MADV_HUGEPAGE) Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 30 of 34] pmd_trans_huge migrate bugcheck Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 31 of 34] memcg compound Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 32 of 34] memcg huge memory Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 33 of 34] transparent hugepage vmstat Andrea Arcangeli
2010-03-17 15:19 ` [PATCH 34 of 34] khugepaged Andrea Arcangeli
2010-03-17 19:05 ` [PATCH 00 of 34] Transparent Hugepage support #14 Christoph Lameter
2010-03-18 23:49   ` Andrea Arcangeli
2010-03-19 13:29     ` Christoph Lameter
2010-03-19 14:41       ` Andrea Arcangeli
2010-03-22 15:38         ` Christoph Lameter
2010-03-22 16:35           ` Johannes Weiner
2010-03-22 16:46             ` Christoph Lameter
2010-03-22 17:15               ` Andrea Arcangeli
2010-03-23 17:08                 ` Christoph Lameter
2010-03-22 18:20               ` Johannes Weiner
2010-03-23 17:11                 ` Christoph Lameter
2010-03-23 19:06                   ` Andrea Arcangeli
2010-03-22 17:08             ` Andrea Arcangeli
2010-03-22 17:06           ` Andrea Arcangeli [this message]
2010-03-23 17:06             ` Christoph Lameter
2010-03-23 19:08               ` Andrea Arcangeli
2010-03-24 21:03                 ` Christoph Lameter
2010-03-24 21:22                   ` Andrea Arcangeli
2010-03-25 22:17                     ` Christoph Lameter
2010-03-25 22:41                       ` Andrea Arcangeli

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=20100322170619.GQ29874@random.random \
    --to=aarcange@redhat.com \
    --cc=agl@us.ibm.com \
    --cc=arnd@arndb.de \
    --cc=avi@redhat.com \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=bpicco@redhat.com \
    --cc=chrisw@sous-sol.org \
    --cc=cl@linux-foundation.org \
    --cc=dave@linux.vnet.ibm.com \
    --cc=hugh.dickins@tiscali.co.uk \
    --cc=ieidus@redhat.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=mel@csn.ul.ie \
    --cc=mingo@elte.hu \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=npiggin@suse.de \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=travis@sgi.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).