aboutsummaryrefslogtreecommitdiffstats
path: root/mm/hugetlb.c
diff options
context:
space:
mode:
authorNaoya Horiguchi <n-horiguchi@ah.jp.nec.com>2015-02-11 18:25:15 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-11 20:06:01 -0500
commit61f77eda9bbf0d2e922197ed2dcf88638a639ce5 (patch)
tree4ca42137ea20cf5c48379a87cc0811050f124ee8 /mm/hugetlb.c
parentcfc511557945812280699a92f171ddd2d254aca6 (diff)
mm/hugetlb: reduce arch dependent code around follow_huge_*
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>
Diffstat (limited to 'mm/hugetlb.c')
-rw-r--r--mm/hugetlb.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index be0e5d0db5ec..f533d336e569 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3660,7 +3660,20 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
3660 return (pte_t *) pmd; 3660 return (pte_t *) pmd;
3661} 3661}
3662 3662
3663struct page * 3663#endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */
3664
3665/*
3666 * These functions are overwritable if your architecture needs its own
3667 * behavior.
3668 */
3669struct page * __weak
3670follow_huge_addr(struct mm_struct *mm, unsigned long address,
3671 int write)
3672{
3673 return ERR_PTR(-EINVAL);
3674}
3675
3676struct page * __weak
3664follow_huge_pmd(struct mm_struct *mm, unsigned long address, 3677follow_huge_pmd(struct mm_struct *mm, unsigned long address,
3665 pmd_t *pmd, int write) 3678 pmd_t *pmd, int write)
3666{ 3679{
@@ -3672,7 +3685,7 @@ follow_huge_pmd(struct mm_struct *mm, unsigned long address,
3672 return page; 3685 return page;
3673} 3686}
3674 3687
3675struct page * 3688struct page * __weak
3676follow_huge_pud(struct mm_struct *mm, unsigned long address, 3689follow_huge_pud(struct mm_struct *mm, unsigned long address,
3677 pud_t *pud, int write) 3690 pud_t *pud, int write)
3678{ 3691{
@@ -3684,19 +3697,6 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
3684 return page; 3697 return page;
3685} 3698}
3686 3699
3687#else /* !CONFIG_ARCH_WANT_GENERAL_HUGETLB */
3688
3689/* Can be overriden by architectures */
3690struct page * __weak
3691follow_huge_pud(struct mm_struct *mm, unsigned long address,
3692 pud_t *pud, int write)
3693{
3694 BUG();
3695 return NULL;
3696}
3697
3698#endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */
3699
3700#ifdef CONFIG_MEMORY_FAILURE 3700#ifdef CONFIG_MEMORY_FAILURE
3701 3701
3702/* Should be called in hugetlb_lock */ 3702/* Should be called in hugetlb_lock */