]> git.ipfire.org Git - people/ms/linux.git/commitdiff
mm/hugetlb: reduce arch dependent code around follow_huge_*
authorNaoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Wed, 11 Feb 2015 23:25:15 +0000 (15:25 -0800)
committerJiri Slaby <jslaby@suse.cz>
Mon, 16 Mar 2015 10:09:27 +0000 (11:09 +0100)
commit 61f77eda9bbf0d2e922197ed2dcf88638a639ce5 upstream.

Currently we have many duplicates in definitions around
follow_huge_addr(), follow_huge_pmd(), and follow_huge_pud(), so this
patch tries to remove the m.  The basic idea is to put the default
implementation for these functions in mm/hugetlb.c as weak symbols
(regardless of CONFIG_ARCH_WANT_GENERAL_HUGETL B), and to implement
arch-specific code only when the arch needs it.

For follow_huge_addr(), only powerpc and ia64 have their own
implementation, and in all other architectures this function just returns
ERR_PTR(-EINVAL).  So this patch sets returning ERR_PTR(-EINVAL) as
default.

As for follow_huge_(pmd|pud)(), if (pmd|pud)_huge() is implemented to
always return 0 in your architecture (like in ia64 or sparc,) it's never
called (the callsite is optimized away) no matter how implemented it is.
So in such architectures, we don't need arch-specific implementation.

In some architecture (like mips, s390 and tile,) their current
arch-specific follow_huge_(pmd|pud)() are effectively identical with the
common code, so this patch lets these architecture use the common code.

One exception is metag, where pmd_huge() could return non-zero but it
expects follow_huge_pmd() to always return NULL.  This means that we need
arch-specific implementation which returns NULL.  This behavior looks
strange to me (because non-zero pmd_huge() implies that the architecture
supports PMD-based hugepage, so follow_huge_pmd() can/should return some
relevant value,) but that's beyond this cleanup patch, so let's keep it.

Justification of non-trivial changes:
- in s390, follow_huge_pmd() checks !MACHINE_HAS_HPAGE at first, and this
  patch removes the check. This is OK because we can assume MACHINE_HAS_HPAGE
  is true when follow_huge_pmd() can be called (note that pmd_huge() has
  the same check and always returns 0 for !MACHINE_HAS_HPAGE.)
- in s390 and mips, we use HPAGE_MASK instead of PMD_MASK as done in common
  code. This patch forces these archs use PMD_MASK, but it's OK because
  they are identical in both archs.
  In s390, both of HPAGE_SHIFT and PMD_SHIFT are 20.
  In mips, HPAGE_SHIFT is defined as (PAGE_SHIFT + PAGE_SHIFT - 3) and
  PMD_SHIFT is define as (PAGE_SHIFT + PAGE_SHIFT + PTE_ORDER - 3), but
  PTE_ORDER is always 0, so these are identical.

Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Acked-by: Hugh Dickins <hughd@google.com>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Rik van Riel <riel@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Luiz Capitulino <lcapitulino@redhat.com>
Cc: Nishanth Aravamudan <nacc@linux.vnet.ibm.com>
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: Steve Capper <steve.capper@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
12 files changed:
arch/arm/mm/hugetlbpage.c
arch/arm64/mm/hugetlbpage.c
arch/ia64/mm/hugetlbpage.c
arch/metag/mm/hugetlbpage.c
arch/mips/mm/hugetlbpage.c
arch/powerpc/mm/hugetlbpage.c
arch/s390/mm/hugetlbpage.c
arch/sh/mm/hugetlbpage.c
arch/sparc/mm/hugetlbpage.c
arch/tile/mm/hugetlbpage.c
arch/x86/mm/hugetlbpage.c
mm/hugetlb.c

index 66781bf34077cb540a67f845eeeb919c2decfc4e..c724124150934f3a196a1437f85abebc7c355bf4 100644 (file)
  * of type casting from pmd_t * to pte_t *.
  */
 
-struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
-                             int write)
-{
-       return ERR_PTR(-EINVAL);
-}
-
 int pud_huge(pud_t pud)
 {
        return 0;
index 023747bf4dd7dd2025a17c3fc44244aa1b0f7b00..2de9d2e59d96808325829a37bca559c2ddb48a1c 100644 (file)
@@ -38,12 +38,6 @@ int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
 }
 #endif
 
-struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
-                             int write)
-{
-       return ERR_PTR(-EINVAL);
-}
-
 int pmd_huge(pmd_t pmd)
 {
        return !(pmd_val(pmd) & PMD_TABLE_BIT);
index 76069c18ee42c186edf37c680ee78249d553b4fc..52b7604b5215f899b0820bf6741618b5bc774dfa 100644 (file)
@@ -114,12 +114,6 @@ int pud_huge(pud_t pud)
        return 0;
 }
 
-struct page *
-follow_huge_pmd(struct mm_struct *mm, unsigned long address, pmd_t *pmd, int write)
-{
-       return NULL;
-}
-
 void hugetlb_free_pgd_range(struct mmu_gather *tlb,
                        unsigned long addr, unsigned long end,
                        unsigned long floor, unsigned long ceiling)
index 3c52fa6d0f8e24030294fecacc26498f5de9ffe5..7450814276596de336b3788ebee15175089e70e7 100644 (file)
@@ -94,12 +94,6 @@ int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
        return 0;
 }
 
-struct page *follow_huge_addr(struct mm_struct *mm,
-                             unsigned long address, int write)
-{
-       return ERR_PTR(-EINVAL);
-}
-
 int pmd_huge(pmd_t pmd)
 {
        return pmd_page_shift(pmd) > PAGE_SHIFT;
index a7fee0dfb7a9daaeb67616804f00cac7365d778f..e656e7f61e653ea1330649c03f7630f0d9c179bd 100644 (file)
@@ -69,12 +69,6 @@ int is_aligned_hugepage_range(unsigned long addr, unsigned long len)
        return 0;
 }
 
-struct page *
-follow_huge_addr(struct mm_struct *mm, unsigned long address, int write)
-{
-       return ERR_PTR(-EINVAL);
-}
-
 int pmd_huge(pmd_t pmd)
 {
        return (pmd_val(pmd) & _PAGE_HUGE) != 0;
@@ -84,15 +78,3 @@ int pud_huge(pud_t pud)
 {
        return (pud_val(pud) & _PAGE_HUGE) != 0;
 }
-
-struct page *
-follow_huge_pmd(struct mm_struct *mm, unsigned long address,
-               pmd_t *pmd, int write)
-{
-       struct page *page;
-
-       page = pte_page(*(pte_t *)pmd);
-       if (page)
-               page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
-       return page;
-}
index 834ca8eb38f202e01c5151fdb56b13197ed6acc8..fc2427323414f9fbc69d1c60ad9d4a5eca3567a3 100644 (file)
@@ -706,6 +706,14 @@ follow_huge_pmd(struct mm_struct *mm, unsigned long address,
        return NULL;
 }
 
+struct page *
+follow_huge_pud(struct mm_struct *mm, unsigned long address,
+               pud_t *pud, int write)
+{
+       BUG();
+       return NULL;
+}
+
 static unsigned long hugepte_addr_end(unsigned long addr, unsigned long end,
                                      unsigned long sz)
 {
index 248445f92604efff09a5188352c3e6fba1248bb0..99a68d579828a28399ef18335d9e02fb7451bdc0 100644 (file)
@@ -204,12 +204,6 @@ int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
        return 0;
 }
 
-struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
-                             int write)
-{
-       return ERR_PTR(-EINVAL);
-}
-
 int pmd_huge(pmd_t pmd)
 {
        if (!MACHINE_HAS_HPAGE)
@@ -222,17 +216,3 @@ int pud_huge(pud_t pud)
 {
        return 0;
 }
-
-struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
-                            pmd_t *pmdp, int write)
-{
-       struct page *page;
-
-       if (!MACHINE_HAS_HPAGE)
-               return NULL;
-
-       page = pmd_page(*pmdp);
-       if (page)
-               page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
-       return page;
-}
index d7762349ea4869be1b40898a5ae7e6ff8e79c6aa..534bc978af8a58f069709cfc95f5f8c02a1a1a50 100644 (file)
@@ -67,12 +67,6 @@ int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
        return 0;
 }
 
-struct page *follow_huge_addr(struct mm_struct *mm,
-                             unsigned long address, int write)
-{
-       return ERR_PTR(-EINVAL);
-}
-
 int pmd_huge(pmd_t pmd)
 {
        return 0;
@@ -82,9 +76,3 @@ int pud_huge(pud_t pud)
 {
        return 0;
 }
-
-struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
-                            pmd_t *pmd, int write)
-{
-       return NULL;
-}
index 8545f62fa62cfdef192179c3fb9a85776ed6687b..d941cd024f22e3b7cc1ec7b2578a71b39a1475ab 100644 (file)
@@ -216,12 +216,6 @@ pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
        return entry;
 }
 
-struct page *follow_huge_addr(struct mm_struct *mm,
-                             unsigned long address, int write)
-{
-       return ERR_PTR(-EINVAL);
-}
-
 int pmd_huge(pmd_t pmd)
 {
        return 0;
@@ -231,9 +225,3 @@ int pud_huge(pud_t pud)
 {
        return 0;
 }
-
-struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
-                            pmd_t *pmd, int write)
-{
-       return NULL;
-}
index e514899e1100319dc83fe69530f1aad67b17ceea..8a00c7b7b862b0b8f1be655129d5e6e89721b936 100644 (file)
@@ -150,12 +150,6 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
        return NULL;
 }
 
-struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
-                             int write)
-{
-       return ERR_PTR(-EINVAL);
-}
-
 int pmd_huge(pmd_t pmd)
 {
        return !!(pmd_val(pmd) & _PAGE_HUGE_PAGE);
@@ -166,28 +160,6 @@ int pud_huge(pud_t pud)
        return !!(pud_val(pud) & _PAGE_HUGE_PAGE);
 }
 
-struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
-                            pmd_t *pmd, int write)
-{
-       struct page *page;
-
-       page = pte_page(*(pte_t *)pmd);
-       if (page)
-               page += ((address & ~PMD_MASK) >> PAGE_SHIFT);
-       return page;
-}
-
-struct page *follow_huge_pud(struct mm_struct *mm, unsigned long address,
-                            pud_t *pud, int write)
-{
-       struct page *page;
-
-       page = pte_page(*(pte_t *)pud);
-       if (page)
-               page += ((address & ~PUD_MASK) >> PAGE_SHIFT);
-       return page;
-}
-
 int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
 {
        return 0;
index e473dbe45c0f15b043c744dcd02c6f040d5510d5..9d80a1b5dc8669a47f3edcf09f9b1523bd5a5e37 100644 (file)
@@ -52,20 +52,8 @@ int pud_huge(pud_t pud)
        return 0;
 }
 
-struct page *
-follow_huge_pmd(struct mm_struct *mm, unsigned long address,
-               pmd_t *pmd, int write)
-{
-       return NULL;
-}
 #else
 
-struct page *
-follow_huge_addr(struct mm_struct *mm, unsigned long address, int write)
-{
-       return ERR_PTR(-EINVAL);
-}
-
 /*
  * pmd_huge() returns 1 if @pmd is hugetlb related entry, that is normal
  * hugetlb entry or non-present (migration or hwpoisoned) hugetlb entry.
index 33193ab3dbd37c308761fe920f5ee0455282b317..ef1fbe317213196756e1669a2a41dc6be88d8af3 100644 (file)
@@ -3478,7 +3478,20 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
        return (pte_t *) pmd;
 }
 
-struct page *
+#endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */
+
+/*
+ * These functions are overwritable if your architecture needs its own
+ * behavior.
+ */
+struct page * __weak
+follow_huge_addr(struct mm_struct *mm, unsigned long address,
+                             int write)
+{
+       return ERR_PTR(-EINVAL);
+}
+
+struct page * __weak
 follow_huge_pmd(struct mm_struct *mm, unsigned long address,
                pmd_t *pmd, int write)
 {
@@ -3492,7 +3505,7 @@ follow_huge_pmd(struct mm_struct *mm, unsigned long address,
        return page;
 }
 
-struct page *
+struct page * __weak
 follow_huge_pud(struct mm_struct *mm, unsigned long address,
                pud_t *pud, int write)
 {
@@ -3504,19 +3517,6 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
        return page;
 }
 
-#else /* !CONFIG_ARCH_WANT_GENERAL_HUGETLB */
-
-/* Can be overriden by architectures */
-__attribute__((weak)) struct page *
-follow_huge_pud(struct mm_struct *mm, unsigned long address,
-              pud_t *pud, int write)
-{
-       BUG();
-       return NULL;
-}
-
-#endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */
-
 #ifdef CONFIG_MEMORY_FAILURE
 
 /* Should be called in hugetlb_lock */