From: Andrea Arcangeli <aarcange@redhat.com>
To: Michel Lespinasse <walken@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Hugh Dickins <hughd@google.com>,
Minchan Kim <minchan.kim@gmail.com>,
Johannes Weiner <jweiner@redhat.com>,
Rik van Riel <riel@redhat.com>, Mel Gorman <mgorman@suse.de>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Shaohua Li <shaohua.li@intel.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [PATCH] thp: tail page refcounting fix #2
Date: Fri, 26 Aug 2011 18:10:48 +0200 [thread overview]
Message-ID: <20110826161048.GE23870@redhat.com> (raw)
In-Reply-To: <20110826062436.GA5847@google.com>
On Thu, Aug 25, 2011 at 11:24:36PM -0700, Michel Lespinasse wrote:
> I had never heard before of locked instructions being necessary when a
> straight assignment would do what we want, but after reading the erratas
> you listed, I'm not so sure anymore. Given that, I think the version with
> just one single atomic add is good enough.
spin_unlock sometime is adding the lock prefix too for that reason. So
I feel safer that way.
> (there are also 511 consecutive atomic_sub calls on the head page _count,
> which could just as well be coalesced into a signle one at the end of the
> tail page loop).
That should be safe. It's not like I'm a mood to microoptimize
__split_huge_page_refcount after you found I forgot the
get_page_unless_zero needed to keep the page->flags stable (they're
overwritten by the time the head page is freed, that is why we need it).
> I think your current __get_page_tail() is unsafe when it takes the
> compound lock on the head page, because there is no refcount held on it.
> If the THP page gets broken up before we get the compound lock, the head
> page could get freed. But it looks like you could fix that by doing
> get_page_unless_zero on the head, and you should end up with something
> very much like the put_page() function, which I find incredibly tricky
> but seems to be safe.
Correct, it's enough and we need it for the same reason it is in
put_page. Nothing new or no new fundamental problem with this
approach, just an implementation mistake. At least it could introduced
no regression compared to the previous code.
> I would suggest moving get_page_foll() and __get_page_tail_foll() to
> mm/internal.h so that people writing code outside of mm/ don't get confused
> about which get_page() version they must call.
Good idea. That is for MM internal usage only, only follow_page is
allowed to call it.
> In __get_page_tail(), you could add a VM_BUG_ON(page_mapcount(page) <= 0)
> to reflect the fact that get_page() callers are expected to have already
> gotten a reference on the page through a gup call.
So I could put it just before calling __get_page_tail_foll().
I don't see a way anybody could call get_page on a tail page without
having called gup on it first. So I think it's correct. Any
pfn-scanning code like your working set estimation code has to use
get_page_unless_zero and that will never succeed anymore for tail
pages.
> (not your fault, you just moved that code) The comment above
> reset_page_mapcount() and page_mapcount() mentions that _count starts from -1.
> This does not seem to be accurate anymore - as you see page_count() just
> returns the _count value without adding 1. I guess you could just remove
> ', like _count,' from the comment and that'd make it accurate :)
The comment talks about _mapcount not _count. page_mapcount still adds
1 to _mapcount and _mapcount really still starts from -1.
> The use of _mapcount to store tail page counts should probably be
> documented somewhere - probably in mm_types.h where _mapcount is
> defined, and/or before the page_mapcount accessor function. Or, there
> could be a tail_page_count() accessor function for that so that it's
> evident in all call sites that we're accessing a refcount and not a mapcount:
>
> static inline int tail_page_count(struct page *page)
> {
> VM_BUG_ON(!PageTail(page));
> return page_mapcount(page);
> }
>
>
> (probably for another commit) I'm not too comfortable with having several
> arch-specific fast gup functions knowning details about how page counts
> are implemented. Linus's tree also adds such support in sparc arch
> (and it doesn't even seem to be correct as it increments the head count
> but not the tail count). This should probably be cleaned up sometime by
> moving such details into generic inline helper functions.
>
>
> Besides these comments, overall I like the change a lot & I'm especially
> happy to see get_page() work in all cases again :)
Glad to hear :).
Thanks a lot for pointing out the missing get_page_unless_zero(). I'll
post a #3 version soon with that bit fixed.
I'm undecided of tail_page_count is needed. The only benefit would be
to be able to grep for tail_page_count and see the few call sites, maybe
that makes it worth it. The VM_BUG_ON I doubt is necessary there
considering it's easy to review the callsites and they're so few. It'd
also need to go into internal.h I guess.
WARNING: multiple messages have this Message-ID (diff)
From: Andrea Arcangeli <aarcange@redhat.com>
To: Michel Lespinasse <walken@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Hugh Dickins <hughd@google.com>,
Minchan Kim <minchan.kim@gmail.com>,
Johannes Weiner <jweiner@redhat.com>,
Rik van Riel <riel@redhat.com>, Mel Gorman <mgorman@suse.de>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Shaohua Li <shaohua.li@intel.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [PATCH] thp: tail page refcounting fix #2
Date: Fri, 26 Aug 2011 18:10:48 +0200 [thread overview]
Message-ID: <20110826161048.GE23870@redhat.com> (raw)
In-Reply-To: <20110826062436.GA5847@google.com>
On Thu, Aug 25, 2011 at 11:24:36PM -0700, Michel Lespinasse wrote:
> I had never heard before of locked instructions being necessary when a
> straight assignment would do what we want, but after reading the erratas
> you listed, I'm not so sure anymore. Given that, I think the version with
> just one single atomic add is good enough.
spin_unlock sometime is adding the lock prefix too for that reason. So
I feel safer that way.
> (there are also 511 consecutive atomic_sub calls on the head page _count,
> which could just as well be coalesced into a signle one at the end of the
> tail page loop).
That should be safe. It's not like I'm a mood to microoptimize
__split_huge_page_refcount after you found I forgot the
get_page_unless_zero needed to keep the page->flags stable (they're
overwritten by the time the head page is freed, that is why we need it).
> I think your current __get_page_tail() is unsafe when it takes the
> compound lock on the head page, because there is no refcount held on it.
> If the THP page gets broken up before we get the compound lock, the head
> page could get freed. But it looks like you could fix that by doing
> get_page_unless_zero on the head, and you should end up with something
> very much like the put_page() function, which I find incredibly tricky
> but seems to be safe.
Correct, it's enough and we need it for the same reason it is in
put_page. Nothing new or no new fundamental problem with this
approach, just an implementation mistake. At least it could introduced
no regression compared to the previous code.
> I would suggest moving get_page_foll() and __get_page_tail_foll() to
> mm/internal.h so that people writing code outside of mm/ don't get confused
> about which get_page() version they must call.
Good idea. That is for MM internal usage only, only follow_page is
allowed to call it.
> In __get_page_tail(), you could add a VM_BUG_ON(page_mapcount(page) <= 0)
> to reflect the fact that get_page() callers are expected to have already
> gotten a reference on the page through a gup call.
So I could put it just before calling __get_page_tail_foll().
I don't see a way anybody could call get_page on a tail page without
having called gup on it first. So I think it's correct. Any
pfn-scanning code like your working set estimation code has to use
get_page_unless_zero and that will never succeed anymore for tail
pages.
> (not your fault, you just moved that code) The comment above
> reset_page_mapcount() and page_mapcount() mentions that _count starts from -1.
> This does not seem to be accurate anymore - as you see page_count() just
> returns the _count value without adding 1. I guess you could just remove
> ', like _count,' from the comment and that'd make it accurate :)
The comment talks about _mapcount not _count. page_mapcount still adds
1 to _mapcount and _mapcount really still starts from -1.
> The use of _mapcount to store tail page counts should probably be
> documented somewhere - probably in mm_types.h where _mapcount is
> defined, and/or before the page_mapcount accessor function. Or, there
> could be a tail_page_count() accessor function for that so that it's
> evident in all call sites that we're accessing a refcount and not a mapcount:
>
> static inline int tail_page_count(struct page *page)
> {
> VM_BUG_ON(!PageTail(page));
> return page_mapcount(page);
> }
>
>
> (probably for another commit) I'm not too comfortable with having several
> arch-specific fast gup functions knowning details about how page counts
> are implemented. Linus's tree also adds such support in sparc arch
> (and it doesn't even seem to be correct as it increments the head count
> but not the tail count). This should probably be cleaned up sometime by
> moving such details into generic inline helper functions.
>
>
> Besides these comments, overall I like the change a lot & I'm especially
> happy to see get_page() work in all cases again :)
Glad to hear :).
Thanks a lot for pointing out the missing get_page_unless_zero(). I'll
post a #3 version soon with that bit fixed.
I'm undecided of tail_page_count is needed. The only benefit would be
to be able to grep for tail_page_count and see the few call sites, maybe
that makes it worth it. The VM_BUG_ON I doubt is necessary there
considering it's easy to review the callsites and they're so few. It'd
also need to go into internal.h I guess.
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2011-08-26 16:11 UTC|newest]
Thread overview: 109+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-19 7:48 [PATCH 0/9] Use RCU to stabilize page counts Michel Lespinasse
2011-08-19 7:48 ` Michel Lespinasse
2011-08-19 7:48 ` [PATCH 1/9] mm: rcu read lock for getting reference on pages in migration_entry_wait() Michel Lespinasse
2011-08-19 7:48 ` Michel Lespinasse
2011-08-19 7:48 ` [PATCH 2/9] mm: avoid calling get_page_unless_zero() when charging cgroups Michel Lespinasse
2011-08-19 7:48 ` Michel Lespinasse
2011-08-19 7:48 ` [PATCH 3/9] mm: rcu read lock when getting from tail to head page Michel Lespinasse
2011-08-19 7:48 ` Michel Lespinasse
2011-08-19 7:48 ` [PATCH 4/9] mm: use get_page in deactivate_page() Michel Lespinasse
2011-08-19 7:48 ` Michel Lespinasse
2011-08-19 7:48 ` [PATCH 5/9] kvm: use get_page instead of get_page_unless_zero Michel Lespinasse
2011-08-19 7:48 ` Michel Lespinasse
2011-08-19 7:48 ` [PATCH 6/9] mm: assert that get_page_unless_zero() callers hold the rcu lock Michel Lespinasse
2011-08-19 7:48 ` Michel Lespinasse
2011-08-19 23:28 ` Andi Kleen
2011-08-19 23:28 ` Andi Kleen
2011-08-19 7:48 ` [PATCH 7/9] rcu: rcu_get_gp_cookie() / rcu_gp_cookie_elapsed() stand-ins Michel Lespinasse
2011-08-19 7:48 ` Michel Lespinasse
2011-08-19 7:48 ` [PATCH 8/9] mm: add API for setting a grace period cookie on compound pages Michel Lespinasse
2011-08-19 7:48 ` Michel Lespinasse
2011-08-19 7:48 ` [PATCH 9/9] mm: make sure tail page counts are stable before splitting THP pages Michel Lespinasse
2011-08-19 7:48 ` Michel Lespinasse
2011-08-19 7:53 ` [PATCH 0/9] Use RCU to stabilize page counts Michel Lespinasse
2011-08-19 7:53 ` Michel Lespinasse
2011-08-22 21:33 ` [PATCH] thp: tail page refcounting fix Andrea Arcangeli
2011-08-22 21:33 ` Andrea Arcangeli
2011-08-23 14:55 ` Andrea Arcangeli
2011-08-23 14:55 ` Andrea Arcangeli
2011-08-23 16:45 ` Minchan Kim
2011-08-23 16:45 ` Minchan Kim
2011-08-23 16:54 ` Andrea Arcangeli
2011-08-23 16:54 ` Andrea Arcangeli
2011-08-23 19:52 ` Michel Lespinasse
2011-08-23 19:52 ` Michel Lespinasse
2011-08-24 0:09 ` Andrea Arcangeli
2011-08-24 0:09 ` Andrea Arcangeli
2011-08-24 0:27 ` Andrea Arcangeli
2011-08-24 0:27 ` Andrea Arcangeli
2011-08-24 13:34 ` [PATCH] thp: tail page refcounting fix #2 Andrea Arcangeli
2011-08-24 13:34 ` Andrea Arcangeli
2011-08-26 6:24 ` Michel Lespinasse
2011-08-26 6:24 ` Michel Lespinasse
2011-08-26 16:10 ` Andrea Arcangeli [this message]
2011-08-26 16:10 ` Andrea Arcangeli
2011-08-26 18:54 ` [PATCH] thp: tail page refcounting fix #3 Andrea Arcangeli
2011-08-26 18:54 ` Andrea Arcangeli
2011-08-27 9:41 ` Michel Lespinasse
2011-08-27 9:41 ` Michel Lespinasse
2011-08-27 17:34 ` [PATCH] thp: tail page refcounting fix #4 Andrea Arcangeli
2011-08-27 17:34 ` Andrea Arcangeli
2011-08-29 4:20 ` Minchan Kim
2011-08-29 4:20 ` Minchan Kim
2011-09-01 15:24 ` [PATCH] thp: tail page refcounting fix #5 Andrea Arcangeli
2011-09-01 15:24 ` Andrea Arcangeli
2011-09-01 22:27 ` Michel Lespinasse
2011-09-01 22:27 ` Michel Lespinasse
2011-09-01 23:28 ` Andrew Morton
2011-09-01 23:28 ` Andrew Morton
2011-09-01 23:45 ` Andi Kleen
2011-09-01 23:45 ` Andi Kleen
2011-09-02 0:20 ` Andrea Arcangeli
2011-09-02 0:20 ` Andrea Arcangeli
2011-09-02 1:17 ` Andi Kleen
2011-09-02 1:17 ` Andi Kleen
2011-09-02 0:03 ` Andrew Morton
2011-09-02 0:03 ` Andrew Morton
2011-09-08 16:51 ` [PATCH] thp: tail page refcounting fix #6 Andrea Arcangeli
2011-09-08 16:51 ` Andrea Arcangeli
2011-09-23 15:57 ` Peter Zijlstra
2011-09-23 15:57 ` Peter Zijlstra
2011-09-30 13:58 ` Andrea Arcangeli
2011-09-30 13:58 ` Andrea Arcangeli
2011-10-16 20:37 ` thp: gup_fast ppc tail refcounting [was Re: [PATCH] thp: tail page refcounting fix #6] Andrea Arcangeli
2011-10-16 20:37 ` [PATCH 1/4] powerpc: remove superfluous PageTail checks on the pte gup_fast Andrea Arcangeli
2011-10-16 20:37 ` [PATCH 2/4] powerpc: get_hugepte() don't put_page() the wrong page Andrea Arcangeli
2011-10-16 20:37 ` [PATCH 3/4] powerpc: gup_hugepte() avoid to free the head page too many times Andrea Arcangeli
2011-10-16 20:37 ` [PATCH 4/4] powerpc: gup_hugepte() support THP based tail recounting Andrea Arcangeli
2011-10-16 20:40 ` thp: gup_fast ppc tail refcounting [was Re: [PATCH] thp: tail page refcounting fix #6] Andrea Arcangeli
2011-10-16 20:40 ` Andrea Arcangeli
2011-10-16 20:40 ` [PATCH 1/4] powerpc: remove superfluous PageTail checks on the pte gup_fast Andrea Arcangeli
2011-10-16 20:40 ` Andrea Arcangeli
2011-10-16 20:40 ` [PATCH 2/4] powerpc: get_hugepte() don't put_page() the wrong page Andrea Arcangeli
2011-10-16 20:40 ` Andrea Arcangeli
2011-10-16 20:40 ` [PATCH 3/4] powerpc: gup_hugepte() avoid to free the head page too many times Andrea Arcangeli
2011-10-16 20:40 ` Andrea Arcangeli
2011-10-16 20:40 ` [PATCH 4/4] powerpc: gup_hugepte() support THP based tail recounting Andrea Arcangeli
2011-10-16 20:40 ` Andrea Arcangeli
2011-10-17 14:41 ` thp: gup_fast s390/sparc tail refcounting [was Re: [PATCH] thp: tail page refcounting fix #6] Andrea Arcangeli
2011-10-17 14:41 ` Andrea Arcangeli
2011-10-17 14:41 ` [PATCH 1/3] s390: gup_huge_pmd() support THP tail recounting Andrea Arcangeli
2011-10-17 14:41 ` Andrea Arcangeli
2011-10-17 14:41 ` [PATCH 2/3] sparc: gup_pte_range() support THP based " Andrea Arcangeli
2011-10-17 14:41 ` Andrea Arcangeli
2011-10-17 22:44 ` David Miller
2011-10-17 22:44 ` David Miller
2011-10-17 14:41 ` [PATCH 3/3] thp: share get_huge_page_tail() Andrea Arcangeli
2011-10-17 14:41 ` Andrea Arcangeli
2011-10-17 21:32 ` fix two more s390/sparc gup_fast bugs Andrea Arcangeli
2011-10-17 21:32 ` Andrea Arcangeli
2011-10-17 21:32 ` [PATCH 1/2] s390: gup_huge_pmd() return 0 if pte changes Andrea Arcangeli
2011-10-17 21:32 ` Andrea Arcangeli
2011-10-17 21:32 ` [PATCH 2/2] powerpc: " Andrea Arcangeli
2011-10-17 21:32 ` Andrea Arcangeli
2011-08-29 22:40 ` [PATCH] thp: tail page refcounting fix #4 Michel Lespinasse
2011-08-29 22:40 ` Michel Lespinasse
2011-08-29 23:30 ` Andrea Arcangeli
2011-08-29 23:30 ` Andrea Arcangeli
2011-08-26 19:28 ` [PATCH] thp: tail page refcounting fix #2 Andrea Arcangeli
2011-08-26 19:28 ` 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=20110826161048.GE23870@redhat.com \
--to=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=jweiner@redhat.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=minchan.kim@gmail.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=riel@redhat.com \
--cc=shaohua.li@intel.com \
--cc=walken@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.