2015-04-14 07:40:35

by Zhang Zhen

[permalink] [raw]
Subject: [PATCH] mm/hugetlb: reduce arch dependent code about huge_pmd_unshare

Currently we have many duplicates in definitions of huge_pmd_unshare.
In all architectures this function just returns 0 when
CONFIG_ARCH_WANT_HUGE_PMD_SHARE is N.

This patch put the default implementation in mm/hugetlb.c and lets
these architecture use the common code.

Signed-off-by: Zhang Zhen <[email protected]>
---
arch/arm/mm/hugetlbpage.c | 5 -----
arch/arm64/mm/hugetlbpage.c | 7 -------
arch/ia64/mm/hugetlbpage.c | 5 -----
arch/metag/mm/hugetlbpage.c | 5 -----
arch/mips/mm/hugetlbpage.c | 5 -----
arch/powerpc/mm/hugetlbpage.c | 5 -----
arch/s390/mm/hugetlbpage.c | 5 -----
arch/sh/mm/hugetlbpage.c | 5 -----
arch/sparc/mm/hugetlbpage.c | 5 -----
arch/tile/mm/hugetlbpage.c | 5 -----
mm/hugetlb.c | 5 +++++
11 files changed, 5 insertions(+), 52 deletions(-)

diff --git a/arch/arm/mm/hugetlbpage.c b/arch/arm/mm/hugetlbpage.c
index c724124..fcafb52 100644
--- a/arch/arm/mm/hugetlbpage.c
+++ b/arch/arm/mm/hugetlbpage.c
@@ -41,11 +41,6 @@ int pud_huge(pud_t pud)
return 0;
}

-int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
-{
- return 0;
-}
-
int pmd_huge(pmd_t pmd)
{
return pmd_val(pmd) && !(pmd_val(pmd) & PMD_TABLE_BIT);
diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
index 2de9d2e..cccc4af 100644
--- a/arch/arm64/mm/hugetlbpage.c
+++ b/arch/arm64/mm/hugetlbpage.c
@@ -31,13 +31,6 @@
#include <asm/tlbflush.h>
#include <asm/pgalloc.h>

-#ifndef CONFIG_ARCH_WANT_HUGE_PMD_SHARE
-int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
-{
- return 0;
-}
-#endif
-
int pmd_huge(pmd_t pmd)
{
return !(pmd_val(pmd) & PMD_TABLE_BIT);
diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
index 52b7604..f50d4b3 100644
--- a/arch/ia64/mm/hugetlbpage.c
+++ b/arch/ia64/mm/hugetlbpage.c
@@ -65,11 +65,6 @@ huge_pte_offset (struct mm_struct *mm, unsigned long addr)
return pte;
}

-int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
-{
- return 0;
-}
-
#define mk_pte_huge(entry) { pte_val(entry) |= _PAGE_P; }

/*
diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
index 7ca80ac..53f0f6c 100644
--- a/arch/metag/mm/hugetlbpage.c
+++ b/arch/metag/mm/hugetlbpage.c
@@ -89,11 +89,6 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
return pte;
}

-int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
-{
- return 0;
-}
-
int pmd_huge(pmd_t pmd)
{
return pmd_page_shift(pmd) > PAGE_SHIFT;
diff --git a/arch/mips/mm/hugetlbpage.c b/arch/mips/mm/hugetlbpage.c
index 06e0f42..74aa6f6 100644
--- a/arch/mips/mm/hugetlbpage.c
+++ b/arch/mips/mm/hugetlbpage.c
@@ -51,11 +51,6 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
return (pte_t *) pmd;
}

-int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
-{
- return 0;
-}
-
/*
* This function checks for proper alignment of input addr and len parameters.
*/
diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index 7e408bf..dde6ff5 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -439,11 +439,6 @@ int alloc_bootmem_huge_page(struct hstate *hstate)
}
#endif

-int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
-{
- return 0;
-}
-
#ifdef CONFIG_PPC_FSL_BOOK3E
#define HUGEPD_FREELIST_SIZE \
((PAGE_SIZE - sizeof(struct hugepd_freelist)) / sizeof(pte_t))
diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c
index 210ffed..fa6e1bc 100644
--- a/arch/s390/mm/hugetlbpage.c
+++ b/arch/s390/mm/hugetlbpage.c
@@ -187,11 +187,6 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
return (pte_t *) pmdp;
}

-int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
-{
- return 0;
-}
-
int pmd_huge(pmd_t pmd)
{
if (!MACHINE_HAS_HPAGE)
diff --git a/arch/sh/mm/hugetlbpage.c b/arch/sh/mm/hugetlbpage.c
index 534bc97..6385f60 100644
--- a/arch/sh/mm/hugetlbpage.c
+++ b/arch/sh/mm/hugetlbpage.c
@@ -62,11 +62,6 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
return pte;
}

-int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
-{
- return 0;
-}
-
int pmd_huge(pmd_t pmd)
{
return 0;
diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
index 4242eab..131eaf4 100644
--- a/arch/sparc/mm/hugetlbpage.c
+++ b/arch/sparc/mm/hugetlbpage.c
@@ -172,11 +172,6 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
return pte;
}

-int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
-{
- return 0;
-}
-
void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
pte_t *ptep, pte_t entry)
{
diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
index 8416240..c034dc3 100644
--- a/arch/tile/mm/hugetlbpage.c
+++ b/arch/tile/mm/hugetlbpage.c
@@ -160,11 +160,6 @@ int pud_huge(pud_t pud)
return !!(pud_val(pud) & _PAGE_HUGE_PAGE);
}

-int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
-{
- return 0;
-}
-
#ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
unsigned long addr, unsigned long len,
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index c41b2a0..df677142 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3659,6 +3659,11 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud)
{
return NULL;
}
+
+int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
+{
+ return 0;
+}
#define want_pmd_share() (0)
#endif /* CONFIG_ARCH_WANT_HUGE_PMD_SHARE */

--
1.9.1


.




2015-04-23 22:11:22

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] mm/hugetlb: reduce arch dependent code about huge_pmd_unshare

On Tue, 14 Apr 2015 15:35:04 +0800 Zhang Zhen <[email protected]> wrote:

> Currently we have many duplicates in definitions of huge_pmd_unshare.
> In all architectures this function just returns 0 when
> CONFIG_ARCH_WANT_HUGE_PMD_SHARE is N.
>
> This patch put the default implementation in mm/hugetlb.c and lets
> these architecture use the common code.

Memory fails me. Why do some architectures (arm, arm64, x86_64) want
huge_pmd_[un]share() while other architectures (ia64, tile, mips,
powerpc, metag, sh, s390) do not?

2015-04-23 22:26:22

by Tony Luck

[permalink] [raw]
Subject: RE: [PATCH] mm/hugetlb: reduce arch dependent code about huge_pmd_unshare

> Memory fails me. Why do some architectures (arm, arm64, x86_64) want
> huge_pmd_[un]share() while other architectures (ia64, tile, mips,
> powerpc, metag, sh, s390) do not?

Potentially laziness/ignorance-of-feature? It looks like this feature started on x86_64 and then spread
to arm*.

Huge pages are weird on ia64 in that they have to be in a specific range of virtual addresses (region 4).
But I don't see why that would prevent sharing pmd's.

-Tony

2015-04-23 22:42:00

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] mm/hugetlb: reduce arch dependent code about huge_pmd_unshare

On Thu, 23 Apr 2015 22:26:18 +0000 "Luck, Tony" <[email protected]> wrote:

> > Memory fails me. Why do some architectures (arm, arm64, x86_64) want
> > huge_pmd_[un]share() while other architectures (ia64, tile, mips,
> > powerpc, metag, sh, s390) do not?
>
> Potentially laziness/ignorance-of-feature? It looks like this feature started on x86_64 and then spread
> to arm*.

Yes. In 3212b535f200c85b5a6 Steve Capper (ARM person) hoisted the code
out of x86 into generic, then made arm use it.

We're not (I'm not) very good about letting arch people know about such
things. I wonder how to fix that; does linux-arch work?

2015-04-24 15:46:35

by Steve Capper

[permalink] [raw]
Subject: Re: [PATCH] mm/hugetlb: reduce arch dependent code about huge_pmd_unshare

Hi,

On 23 April 2015 at 23:41, Andrew Morton <[email protected]> wrote:
> On Thu, 23 Apr 2015 22:26:18 +0000 "Luck, Tony" <[email protected]> wrote:
>
>> > Memory fails me. Why do some architectures (arm, arm64, x86_64) want
>> > huge_pmd_[un]share() while other architectures (ia64, tile, mips,
>> > powerpc, metag, sh, s390) do not?
>>
>> Potentially laziness/ignorance-of-feature? It looks like this feature started on x86_64 and then spread
>> to arm*.
>
> Yes. In 3212b535f200c85b5a6 Steve Capper (ARM person) hoisted the code
> out of x86 into generic, then made arm use it.

I tested the pmd sharing code that x86 had and it worked well on ARM
too so I bundled it in when I generalised some of the huge page code.
I didn't know enough about the other architectures to enable it for
them, so played things safe by leaving it disabled for them.
Looking at this patch, I could have done that more cleanly though.

>
> We're not (I'm not) very good about letting arch people know about such
> things. I wonder how to fix that; does linux-arch work?
>

linux-arch is working for me, maybe a good idea to CC in some arch
maintainers too.

Cheers,
--
Steve