All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: avoid tail page refcounting on non-THP compound pages
@ 2015-03-25 22:41 ` Kirill A. Shutemov
  0 siblings, 0 replies; 12+ messages in thread
From: Kirill A. Shutemov @ 2015-03-25 22:41 UTC (permalink / raw)
  To: Andrew Morton, Hugh Dickins; +Cc: linux-kernel, linux-mm, Kirill A. Shutemov

THP uses tail page refcounting to be able to split huge page at any
time. Tail page refcounting is not needed for rest users of compound
pages and it's harmful because of overhead.

We try to exclude non-THP pages from tail page refcounting using
__compound_tail_refcounted() check. It excludes most common non-THP
compound pages: SL*B and hugetlb, but it doesn't catch rest of
__GFP_COMP users -- drivers.

And it's not only about overhead.

Drivers might want to use compound pages to get refcounting semantics
suitable for mapping high-order pages to userspace. But tail page
refcounting breaks it.

Tail page refcounting uses ->_mapcount in tail pages to store GUP pins
on them. It means GUP pins would affect page_mapcount() for tail pages.
It's not a problem for THP, because it never maps tail pages. But unlike
THP, drivers map parts of compound pages with PTEs and it makes
page_mapcount() be called for tail pages.

In particular, GUP pins would shift PSS up and affect /proc/kpagecount
for such pages. But, I'm not aware about anything which can lead to
crash or other serious misbehaviour.

Since currently all THP pages are anonymous and all drivers pages are
not, we can fix the __compound_tail_refcounted() check by requiring
PageAnon() to enable tail page refcounting.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 include/linux/mm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 4a3a38522ab4..16fe322b66ea 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -456,7 +456,7 @@ static inline int page_count(struct page *page)
 
 static inline bool __compound_tail_refcounted(struct page *page)
 {
-	return !PageSlab(page) && !PageHeadHuge(page);
+	return PageAnon(page) && !PageSlab(page) && !PageHeadHuge(page);
 }
 
 /*
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH] mm: avoid tail page refcounting on non-THP compound pages
@ 2015-03-25 22:41 ` Kirill A. Shutemov
  0 siblings, 0 replies; 12+ messages in thread
From: Kirill A. Shutemov @ 2015-03-25 22:41 UTC (permalink / raw)
  To: Andrew Morton, Hugh Dickins; +Cc: linux-kernel, linux-mm, Kirill A. Shutemov

THP uses tail page refcounting to be able to split huge page at any
time. Tail page refcounting is not needed for rest users of compound
pages and it's harmful because of overhead.

We try to exclude non-THP pages from tail page refcounting using
__compound_tail_refcounted() check. It excludes most common non-THP
compound pages: SL*B and hugetlb, but it doesn't catch rest of
__GFP_COMP users -- drivers.

And it's not only about overhead.

Drivers might want to use compound pages to get refcounting semantics
suitable for mapping high-order pages to userspace. But tail page
refcounting breaks it.

Tail page refcounting uses ->_mapcount in tail pages to store GUP pins
on them. It means GUP pins would affect page_mapcount() for tail pages.
It's not a problem for THP, because it never maps tail pages. But unlike
THP, drivers map parts of compound pages with PTEs and it makes
page_mapcount() be called for tail pages.

In particular, GUP pins would shift PSS up and affect /proc/kpagecount
for such pages. But, I'm not aware about anything which can lead to
crash or other serious misbehaviour.

Since currently all THP pages are anonymous and all drivers pages are
not, we can fix the __compound_tail_refcounted() check by requiring
PageAnon() to enable tail page refcounting.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 include/linux/mm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 4a3a38522ab4..16fe322b66ea 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -456,7 +456,7 @@ static inline int page_count(struct page *page)
 
 static inline bool __compound_tail_refcounted(struct page *page)
 {
-	return !PageSlab(page) && !PageHeadHuge(page);
+	return PageAnon(page) && !PageSlab(page) && !PageHeadHuge(page);
 }
 
 /*
-- 
2.1.4

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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm: avoid tail page refcounting on non-THP compound pages
  2015-03-25 22:41 ` Kirill A. Shutemov
@ 2015-03-25 22:45   ` Hugh Dickins
  -1 siblings, 0 replies; 12+ messages in thread
From: Hugh Dickins @ 2015-03-25 22:45 UTC (permalink / raw)
  To: Kirill A. Shutemov; +Cc: Andrew Morton, Hugh Dickins, linux-kernel, linux-mm

On Thu, 26 Mar 2015, Kirill A. Shutemov wrote:

> THP uses tail page refcounting to be able to split huge page at any
> time. Tail page refcounting is not needed for rest users of compound
> pages and it's harmful because of overhead.
> 
> We try to exclude non-THP pages from tail page refcounting using
> __compound_tail_refcounted() check. It excludes most common non-THP
> compound pages: SL*B and hugetlb, but it doesn't catch rest of
> __GFP_COMP users -- drivers.
> 
> And it's not only about overhead.
> 
> Drivers might want to use compound pages to get refcounting semantics
> suitable for mapping high-order pages to userspace. But tail page
> refcounting breaks it.
> 
> Tail page refcounting uses ->_mapcount in tail pages to store GUP pins
> on them. It means GUP pins would affect page_mapcount() for tail pages.
> It's not a problem for THP, because it never maps tail pages. But unlike
> THP, drivers map parts of compound pages with PTEs and it makes
> page_mapcount() be called for tail pages.
> 
> In particular, GUP pins would shift PSS up and affect /proc/kpagecount
> for such pages. But, I'm not aware about anything which can lead to
> crash or other serious misbehaviour.
> 
> Since currently all THP pages are anonymous and all drivers pages are
> not, we can fix the __compound_tail_refcounted() check by requiring
> PageAnon() to enable tail page refcounting.
> 
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

Acked-by: Hugh Dickins <hughd@google.com>

> ---
>  include/linux/mm.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 4a3a38522ab4..16fe322b66ea 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -456,7 +456,7 @@ static inline int page_count(struct page *page)
>  
>  static inline bool __compound_tail_refcounted(struct page *page)
>  {
> -	return !PageSlab(page) && !PageHeadHuge(page);
> +	return PageAnon(page) && !PageSlab(page) && !PageHeadHuge(page);
>  }
>  
>  /*
> -- 
> 2.1.4

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm: avoid tail page refcounting on non-THP compound pages
@ 2015-03-25 22:45   ` Hugh Dickins
  0 siblings, 0 replies; 12+ messages in thread
From: Hugh Dickins @ 2015-03-25 22:45 UTC (permalink / raw)
  To: Kirill A. Shutemov; +Cc: Andrew Morton, Hugh Dickins, linux-kernel, linux-mm

On Thu, 26 Mar 2015, Kirill A. Shutemov wrote:

> THP uses tail page refcounting to be able to split huge page at any
> time. Tail page refcounting is not needed for rest users of compound
> pages and it's harmful because of overhead.
> 
> We try to exclude non-THP pages from tail page refcounting using
> __compound_tail_refcounted() check. It excludes most common non-THP
> compound pages: SL*B and hugetlb, but it doesn't catch rest of
> __GFP_COMP users -- drivers.
> 
> And it's not only about overhead.
> 
> Drivers might want to use compound pages to get refcounting semantics
> suitable for mapping high-order pages to userspace. But tail page
> refcounting breaks it.
> 
> Tail page refcounting uses ->_mapcount in tail pages to store GUP pins
> on them. It means GUP pins would affect page_mapcount() for tail pages.
> It's not a problem for THP, because it never maps tail pages. But unlike
> THP, drivers map parts of compound pages with PTEs and it makes
> page_mapcount() be called for tail pages.
> 
> In particular, GUP pins would shift PSS up and affect /proc/kpagecount
> for such pages. But, I'm not aware about anything which can lead to
> crash or other serious misbehaviour.
> 
> Since currently all THP pages are anonymous and all drivers pages are
> not, we can fix the __compound_tail_refcounted() check by requiring
> PageAnon() to enable tail page refcounting.
> 
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

Acked-by: Hugh Dickins <hughd@google.com>

> ---
>  include/linux/mm.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 4a3a38522ab4..16fe322b66ea 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -456,7 +456,7 @@ static inline int page_count(struct page *page)
>  
>  static inline bool __compound_tail_refcounted(struct page *page)
>  {
> -	return !PageSlab(page) && !PageHeadHuge(page);
> +	return PageAnon(page) && !PageSlab(page) && !PageHeadHuge(page);
>  }
>  
>  /*
> -- 
> 2.1.4

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm: avoid tail page refcounting on non-THP compound pages
  2015-03-25 22:45   ` Hugh Dickins
@ 2015-03-25 22:48     ` Hugh Dickins
  -1 siblings, 0 replies; 12+ messages in thread
From: Hugh Dickins @ 2015-03-25 22:48 UTC (permalink / raw)
  To: Hugh Dickins; +Cc: Kirill A. Shutemov, Andrew Morton, linux-kernel, linux-mm

On Wed, 25 Mar 2015, Hugh Dickins wrote:
> On Thu, 26 Mar 2015, Kirill A. Shutemov wrote:
> 
> > THP uses tail page refcounting to be able to split huge page at any
> > time. Tail page refcounting is not needed for rest users of compound
> > pages and it's harmful because of overhead.
> > 
> > We try to exclude non-THP pages from tail page refcounting using
> > __compound_tail_refcounted() check. It excludes most common non-THP
> > compound pages: SL*B and hugetlb, but it doesn't catch rest of
> > __GFP_COMP users -- drivers.
> > 
> > And it's not only about overhead.
> > 
> > Drivers might want to use compound pages to get refcounting semantics
> > suitable for mapping high-order pages to userspace. But tail page
> > refcounting breaks it.
> > 
> > Tail page refcounting uses ->_mapcount in tail pages to store GUP pins
> > on them. It means GUP pins would affect page_mapcount() for tail pages.
> > It's not a problem for THP, because it never maps tail pages. But unlike
> > THP, drivers map parts of compound pages with PTEs and it makes
> > page_mapcount() be called for tail pages.
> > 
> > In particular, GUP pins would shift PSS up and affect /proc/kpagecount
> > for such pages. But, I'm not aware about anything which can lead to
> > crash or other serious misbehaviour.
> > 
> > Since currently all THP pages are anonymous and all drivers pages are
> > not, we can fix the __compound_tail_refcounted() check by requiring
> > PageAnon() to enable tail page refcounting.
> > 
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> 
> Acked-by: Hugh Dickins <hughd@google.com>

Oh, hold on a moment: does this actually build in a tree without your
page-flags.h consolidation?  It didn't when I tried to add a PageAnon
test there for my series against v3.19, has something changed in v4.0?

> 
> > ---
> >  include/linux/mm.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/include/linux/mm.h b/include/linux/mm.h
> > index 4a3a38522ab4..16fe322b66ea 100644
> > --- a/include/linux/mm.h
> > +++ b/include/linux/mm.h
> > @@ -456,7 +456,7 @@ static inline int page_count(struct page *page)
> >  
> >  static inline bool __compound_tail_refcounted(struct page *page)
> >  {
> > -	return !PageSlab(page) && !PageHeadHuge(page);
> > +	return PageAnon(page) && !PageSlab(page) && !PageHeadHuge(page);
> >  }
> >  
> >  /*
> > -- 
> > 2.1.4

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm: avoid tail page refcounting on non-THP compound pages
@ 2015-03-25 22:48     ` Hugh Dickins
  0 siblings, 0 replies; 12+ messages in thread
From: Hugh Dickins @ 2015-03-25 22:48 UTC (permalink / raw)
  To: Hugh Dickins; +Cc: Kirill A. Shutemov, Andrew Morton, linux-kernel, linux-mm

On Wed, 25 Mar 2015, Hugh Dickins wrote:
> On Thu, 26 Mar 2015, Kirill A. Shutemov wrote:
> 
> > THP uses tail page refcounting to be able to split huge page at any
> > time. Tail page refcounting is not needed for rest users of compound
> > pages and it's harmful because of overhead.
> > 
> > We try to exclude non-THP pages from tail page refcounting using
> > __compound_tail_refcounted() check. It excludes most common non-THP
> > compound pages: SL*B and hugetlb, but it doesn't catch rest of
> > __GFP_COMP users -- drivers.
> > 
> > And it's not only about overhead.
> > 
> > Drivers might want to use compound pages to get refcounting semantics
> > suitable for mapping high-order pages to userspace. But tail page
> > refcounting breaks it.
> > 
> > Tail page refcounting uses ->_mapcount in tail pages to store GUP pins
> > on them. It means GUP pins would affect page_mapcount() for tail pages.
> > It's not a problem for THP, because it never maps tail pages. But unlike
> > THP, drivers map parts of compound pages with PTEs and it makes
> > page_mapcount() be called for tail pages.
> > 
> > In particular, GUP pins would shift PSS up and affect /proc/kpagecount
> > for such pages. But, I'm not aware about anything which can lead to
> > crash or other serious misbehaviour.
> > 
> > Since currently all THP pages are anonymous and all drivers pages are
> > not, we can fix the __compound_tail_refcounted() check by requiring
> > PageAnon() to enable tail page refcounting.
> > 
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> 
> Acked-by: Hugh Dickins <hughd@google.com>

Oh, hold on a moment: does this actually build in a tree without your
page-flags.h consolidation?  It didn't when I tried to add a PageAnon
test there for my series against v3.19, has something changed in v4.0?

> 
> > ---
> >  include/linux/mm.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/include/linux/mm.h b/include/linux/mm.h
> > index 4a3a38522ab4..16fe322b66ea 100644
> > --- a/include/linux/mm.h
> > +++ b/include/linux/mm.h
> > @@ -456,7 +456,7 @@ static inline int page_count(struct page *page)
> >  
> >  static inline bool __compound_tail_refcounted(struct page *page)
> >  {
> > -	return !PageSlab(page) && !PageHeadHuge(page);
> > +	return PageAnon(page) && !PageSlab(page) && !PageHeadHuge(page);
> >  }
> >  
> >  /*
> > -- 
> > 2.1.4

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm: avoid tail page refcounting on non-THP compound pages
  2015-03-25 22:48     ` Hugh Dickins
@ 2015-03-25 22:56       ` Kirill A. Shutemov
  -1 siblings, 0 replies; 12+ messages in thread
From: Kirill A. Shutemov @ 2015-03-25 22:56 UTC (permalink / raw)
  To: Hugh Dickins; +Cc: Kirill A. Shutemov, Andrew Morton, linux-kernel, linux-mm

On Wed, Mar 25, 2015 at 03:48:48PM -0700, Hugh Dickins wrote:
> On Wed, 25 Mar 2015, Hugh Dickins wrote:
> > On Thu, 26 Mar 2015, Kirill A. Shutemov wrote:
> > 
> > > THP uses tail page refcounting to be able to split huge page at any
> > > time. Tail page refcounting is not needed for rest users of compound
> > > pages and it's harmful because of overhead.
> > > 
> > > We try to exclude non-THP pages from tail page refcounting using
> > > __compound_tail_refcounted() check. It excludes most common non-THP
> > > compound pages: SL*B and hugetlb, but it doesn't catch rest of
> > > __GFP_COMP users -- drivers.
> > > 
> > > And it's not only about overhead.
> > > 
> > > Drivers might want to use compound pages to get refcounting semantics
> > > suitable for mapping high-order pages to userspace. But tail page
> > > refcounting breaks it.
> > > 
> > > Tail page refcounting uses ->_mapcount in tail pages to store GUP pins
> > > on them. It means GUP pins would affect page_mapcount() for tail pages.
> > > It's not a problem for THP, because it never maps tail pages. But unlike
> > > THP, drivers map parts of compound pages with PTEs and it makes
> > > page_mapcount() be called for tail pages.
> > > 
> > > In particular, GUP pins would shift PSS up and affect /proc/kpagecount
> > > for such pages. But, I'm not aware about anything which can lead to
> > > crash or other serious misbehaviour.
> > > 
> > > Since currently all THP pages are anonymous and all drivers pages are
> > > not, we can fix the __compound_tail_refcounted() check by requiring
> > > PageAnon() to enable tail page refcounting.
> > > 
> > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > 
> > Acked-by: Hugh Dickins <hughd@google.com>
> 
> Oh, hold on a moment: does this actually build in a tree without your
> page-flags.h consolidation?  It didn't when I tried to add a PageAnon
> test there for my series against v3.19, has something changed in v4.0?

No. I haven't tried to build it without my patchset, but it seems it
wouldn't.

Just check: it would build for me on top of [PATCH 01/16], you've acked.

-- 
 Kirill A. Shutemov

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm: avoid tail page refcounting on non-THP compound pages
@ 2015-03-25 22:56       ` Kirill A. Shutemov
  0 siblings, 0 replies; 12+ messages in thread
From: Kirill A. Shutemov @ 2015-03-25 22:56 UTC (permalink / raw)
  To: Hugh Dickins; +Cc: Kirill A. Shutemov, Andrew Morton, linux-kernel, linux-mm

On Wed, Mar 25, 2015 at 03:48:48PM -0700, Hugh Dickins wrote:
> On Wed, 25 Mar 2015, Hugh Dickins wrote:
> > On Thu, 26 Mar 2015, Kirill A. Shutemov wrote:
> > 
> > > THP uses tail page refcounting to be able to split huge page at any
> > > time. Tail page refcounting is not needed for rest users of compound
> > > pages and it's harmful because of overhead.
> > > 
> > > We try to exclude non-THP pages from tail page refcounting using
> > > __compound_tail_refcounted() check. It excludes most common non-THP
> > > compound pages: SL*B and hugetlb, but it doesn't catch rest of
> > > __GFP_COMP users -- drivers.
> > > 
> > > And it's not only about overhead.
> > > 
> > > Drivers might want to use compound pages to get refcounting semantics
> > > suitable for mapping high-order pages to userspace. But tail page
> > > refcounting breaks it.
> > > 
> > > Tail page refcounting uses ->_mapcount in tail pages to store GUP pins
> > > on them. It means GUP pins would affect page_mapcount() for tail pages.
> > > It's not a problem for THP, because it never maps tail pages. But unlike
> > > THP, drivers map parts of compound pages with PTEs and it makes
> > > page_mapcount() be called for tail pages.
> > > 
> > > In particular, GUP pins would shift PSS up and affect /proc/kpagecount
> > > for such pages. But, I'm not aware about anything which can lead to
> > > crash or other serious misbehaviour.
> > > 
> > > Since currently all THP pages are anonymous and all drivers pages are
> > > not, we can fix the __compound_tail_refcounted() check by requiring
> > > PageAnon() to enable tail page refcounting.
> > > 
> > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > 
> > Acked-by: Hugh Dickins <hughd@google.com>
> 
> Oh, hold on a moment: does this actually build in a tree without your
> page-flags.h consolidation?  It didn't when I tried to add a PageAnon
> test there for my series against v3.19, has something changed in v4.0?

No. I haven't tried to build it without my patchset, but it seems it
wouldn't.

Just check: it would build for me on top of [PATCH 01/16], you've acked.

-- 
 Kirill A. Shutemov

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm: avoid tail page refcounting on non-THP compound pages
  2015-03-25 22:56       ` Kirill A. Shutemov
@ 2015-03-25 23:09         ` Hugh Dickins
  -1 siblings, 0 replies; 12+ messages in thread
From: Hugh Dickins @ 2015-03-25 23:09 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Hugh Dickins, Kirill A. Shutemov, Andrew Morton, linux-kernel, linux-mm

On Thu, 26 Mar 2015, Kirill A. Shutemov wrote:
> On Wed, Mar 25, 2015 at 03:48:48PM -0700, Hugh Dickins wrote:
> > On Wed, 25 Mar 2015, Hugh Dickins wrote:
> > > On Thu, 26 Mar 2015, Kirill A. Shutemov wrote:
> > > > 
> > > > Since currently all THP pages are anonymous and all drivers pages are
> > > > not, we can fix the __compound_tail_refcounted() check by requiring
> > > > PageAnon() to enable tail page refcounting.
> > > > 
> > > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > > 
> > > Acked-by: Hugh Dickins <hughd@google.com>
> > 
> > Oh, hold on a moment: does this actually build in a tree without your
> > page-flags.h consolidation?  It didn't when I tried to add a PageAnon
> > test there for my series against v3.19, has something changed in v4.0?
> 
> No. I haven't tried to build it without my patchset, but it seems it
> wouldn't.
> 
> Just check: it would build for me on top of [PATCH 01/16], you've acked.

Yes, I'm happy with your 1/16 (which is already there in mmotm),
it's just that I'd imagined this __compound_tail_refcounted() fix
should go to v4.0 (if not stable too: you've decided against, okay).

What do you think, should Andrew hold it back for v4.1, or should
your page-flags.h accelerate into v4.0 as precondition for this fix?

Either is fine with me; but if the latter, then a week's exposure
in linux-next first would probably be best.

Hugh

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm: avoid tail page refcounting on non-THP compound pages
@ 2015-03-25 23:09         ` Hugh Dickins
  0 siblings, 0 replies; 12+ messages in thread
From: Hugh Dickins @ 2015-03-25 23:09 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Hugh Dickins, Kirill A. Shutemov, Andrew Morton, linux-kernel, linux-mm

On Thu, 26 Mar 2015, Kirill A. Shutemov wrote:
> On Wed, Mar 25, 2015 at 03:48:48PM -0700, Hugh Dickins wrote:
> > On Wed, 25 Mar 2015, Hugh Dickins wrote:
> > > On Thu, 26 Mar 2015, Kirill A. Shutemov wrote:
> > > > 
> > > > Since currently all THP pages are anonymous and all drivers pages are
> > > > not, we can fix the __compound_tail_refcounted() check by requiring
> > > > PageAnon() to enable tail page refcounting.
> > > > 
> > > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > > 
> > > Acked-by: Hugh Dickins <hughd@google.com>
> > 
> > Oh, hold on a moment: does this actually build in a tree without your
> > page-flags.h consolidation?  It didn't when I tried to add a PageAnon
> > test there for my series against v3.19, has something changed in v4.0?
> 
> No. I haven't tried to build it without my patchset, but it seems it
> wouldn't.
> 
> Just check: it would build for me on top of [PATCH 01/16], you've acked.

Yes, I'm happy with your 1/16 (which is already there in mmotm),
it's just that I'd imagined this __compound_tail_refcounted() fix
should go to v4.0 (if not stable too: you've decided against, okay).

What do you think, should Andrew hold it back for v4.1, or should
your page-flags.h accelerate into v4.0 as precondition for this fix?

Either is fine with me; but if the latter, then a week's exposure
in linux-next first would probably be best.

Hugh

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm: avoid tail page refcounting on non-THP compound pages
  2015-03-26 15:27 Kirill A. Shutemov
@ 2015-03-26 15:52 ` Kirill A. Shutemov
  0 siblings, 0 replies; 12+ messages in thread
From: Kirill A. Shutemov @ 2015-03-26 15:52 UTC (permalink / raw)
  To: Kirill A. Shutemov; +Cc: Andrew Morton, linux-mm


Please ignore. I've sent wrong patch.

-- 
 Kirill A. Shutemov

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] mm: avoid tail page refcounting on non-THP compound pages
@ 2015-03-26 15:27 Kirill A. Shutemov
  2015-03-26 15:52 ` Kirill A. Shutemov
  0 siblings, 1 reply; 12+ messages in thread
From: Kirill A. Shutemov @ 2015-03-26 15:27 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, Kirill A. Shutemov

THP uses tail page refcounting to be able to split huge page at any
time. Tail page refcounting is not needed for rest users of compound
pages and it's harmful because of overhead.

We try to exclude non-THP pages from tail page refcounting using
__compound_tail_refcounted() check. It excludes most common non-THP
compound pages: SL*B and hugetlb, but it doesn't catch rest of
__GFP_COMP users -- drivers.

And it's not only about overhead.

Drivers might want to use compound pages to get refcounting semantics
suitable for mapping high-order pages to userspace. But tail page
refcounting breaks it.

Tail page refcounting uses ->_mapcount in tail pages to store GUP pins
on them. It means GUP pins would affect page_mapcount() for tail pages.
It's not a problem for THP, because it never maps tail pages. But unlike
THP, drivers map parts of compound pages with PTEs and it makes
page_mapcount() be called for tail pages.

In particular, GUP pins would shift PSS up and affect /proc/kpagecount
for such pages. But, I'm not aware about anything which can lead to
crash or other serious misbehaviour.

Since currently all THP pages are anonymous and all drivers pages are
not, we can fix the __compound_tail_refcounted() check by requiring
PageAnon() to enable tail page refcounting.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 include/linux/mm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 4a3a38522ab4..16fe322b66ea 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -456,7 +456,7 @@ static inline int page_count(struct page *page)
 
 static inline bool __compound_tail_refcounted(struct page *page)
 {
-	return !PageSlab(page) && !PageHeadHuge(page);
+	return PageAnon(page) && !PageSlab(page) && !PageHeadHuge(page);
 }
 
 /*
-- 
2.1.4

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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-03-26 15:52 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-25 22:41 [PATCH] mm: avoid tail page refcounting on non-THP compound pages Kirill A. Shutemov
2015-03-25 22:41 ` Kirill A. Shutemov
2015-03-25 22:45 ` Hugh Dickins
2015-03-25 22:45   ` Hugh Dickins
2015-03-25 22:48   ` Hugh Dickins
2015-03-25 22:48     ` Hugh Dickins
2015-03-25 22:56     ` Kirill A. Shutemov
2015-03-25 22:56       ` Kirill A. Shutemov
2015-03-25 23:09       ` Hugh Dickins
2015-03-25 23:09         ` Hugh Dickins
2015-03-26 15:27 Kirill A. Shutemov
2015-03-26 15:52 ` Kirill A. Shutemov

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.