Skip to content

Commit bd5e88a

Browse files
committed
mm,thp: reduce ifdef'ery for THP in generic code
- pgtable-generic.c: Fold individual #ifdef for each helper into a top level #ifdef. Makes code more readable - Converted the stub helpers for !THP to BUILD_BUG() vs. runtime BUG() Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Link: http://lkml.kernel.org/r/20151009133450.GA8597@node Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
1 parent 52585bc commit bd5e88a

2 files changed

Lines changed: 33 additions & 28 deletions

File tree

‎include/asm-generic/pgtable.h‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,19 @@ extern int ptep_set_access_flags(struct vm_area_struct *vma,
3030
#endif
3131

3232
#ifndef __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
33+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
3334
extern int pmdp_set_access_flags(struct vm_area_struct *vma,
3435
unsigned long address, pmd_t *pmdp,
3536
pmd_t entry, int dirty);
37+
#else
38+
static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
39+
unsigned long address, pmd_t *pmdp,
40+
pmd_t entry, int dirty)
41+
{
42+
BUILD_BUG();
43+
return 0;
44+
}
45+
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
3646
#endif
3747

3848
#ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
@@ -64,12 +74,12 @@ static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
6474
set_pmd_at(vma->vm_mm, address, pmdp, pmd_mkold(pmd));
6575
return r;
6676
}
67-
#else /* CONFIG_TRANSPARENT_HUGEPAGE */
77+
#else
6878
static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
6979
unsigned long address,
7080
pmd_t *pmdp)
7181
{
72-
BUG();
82+
BUILD_BUG();
7383
return 0;
7484
}
7585
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
@@ -81,8 +91,21 @@ int ptep_clear_flush_young(struct vm_area_struct *vma,
8191
#endif
8292

8393
#ifndef __HAVE_ARCH_PMDP_CLEAR_YOUNG_FLUSH
84-
int pmdp_clear_flush_young(struct vm_area_struct *vma,
85-
unsigned long address, pmd_t *pmdp);
94+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
95+
extern int pmdp_clear_flush_young(struct vm_area_struct *vma,
96+
unsigned long address, pmd_t *pmdp);
97+
#else
98+
/*
99+
* Despite relevant to THP only, this API is called from generic rmap code
100+
* under PageTransHuge(), hence needs a dummy implementation for !THP
101+
*/
102+
static inline int pmdp_clear_flush_young(struct vm_area_struct *vma,
103+
unsigned long address, pmd_t *pmdp)
104+
{
105+
BUILD_BUG();
106+
return 0;
107+
}
108+
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
86109
#endif
87110

88111
#ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR
@@ -175,11 +198,11 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
175198
pmd_t old_pmd = *pmdp;
176199
set_pmd_at(mm, address, pmdp, pmd_wrprotect(old_pmd));
177200
}
178-
#else /* CONFIG_TRANSPARENT_HUGEPAGE */
201+
#else
179202
static inline void pmdp_set_wrprotect(struct mm_struct *mm,
180203
unsigned long address, pmd_t *pmdp)
181204
{
182-
BUG();
205+
BUILD_BUG();
183206
}
184207
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
185208
#endif
@@ -248,7 +271,7 @@ static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b)
248271
#else /* CONFIG_TRANSPARENT_HUGEPAGE */
249272
static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b)
250273
{
251-
BUG();
274+
BUILD_BUG();
252275
return 0;
253276
}
254277
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */

‎mm/pgtable-generic.c‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,20 @@ pte_t ptep_clear_flush(struct vm_area_struct *vma, unsigned long address,
8282
}
8383
#endif
8484

85+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
86+
8587
#ifndef __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
8688
int pmdp_set_access_flags(struct vm_area_struct *vma,
8789
unsigned long address, pmd_t *pmdp,
8890
pmd_t entry, int dirty)
8991
{
90-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
9192
int changed = !pmd_same(*pmdp, entry);
9293
VM_BUG_ON(address & ~HPAGE_PMD_MASK);
9394
if (changed) {
9495
set_pmd_at(vma->vm_mm, address, pmdp, entry);
9596
flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
9697
}
9798
return changed;
98-
#else /* CONFIG_TRANSPARENT_HUGEPAGE */
99-
BUG();
100-
return 0;
101-
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
10299
}
103100
#endif
104101

@@ -107,11 +104,7 @@ int pmdp_clear_flush_young(struct vm_area_struct *vma,
107104
unsigned long address, pmd_t *pmdp)
108105
{
109106
int young;
110-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
111107
VM_BUG_ON(address & ~HPAGE_PMD_MASK);
112-
#else
113-
BUG();
114-
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
115108
young = pmdp_test_and_clear_young(vma, address, pmdp);
116109
if (young)
117110
flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
@@ -120,7 +113,6 @@ int pmdp_clear_flush_young(struct vm_area_struct *vma,
120113
#endif
121114

122115
#ifndef __HAVE_ARCH_PMDP_HUGE_CLEAR_FLUSH
123-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
124116
pmd_t pmdp_huge_clear_flush(struct vm_area_struct *vma, unsigned long address,
125117
pmd_t *pmdp)
126118
{
@@ -131,11 +123,9 @@ pmd_t pmdp_huge_clear_flush(struct vm_area_struct *vma, unsigned long address,
131123
flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
132124
return pmd;
133125
}
134-
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
135126
#endif
136127

137128
#ifndef __HAVE_ARCH_PMDP_SPLITTING_FLUSH
138-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
139129
void pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address,
140130
pmd_t *pmdp)
141131
{
@@ -145,11 +135,9 @@ void pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address,
145135
/* tlb flush only to serialize against gup-fast */
146136
flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
147137
}
148-
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
149138
#endif
150139

151140
#ifndef __HAVE_ARCH_PGTABLE_DEPOSIT
152-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
153141
void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
154142
pgtable_t pgtable)
155143
{
@@ -162,11 +150,9 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
162150
list_add(&pgtable->lru, &pmd_huge_pte(mm, pmdp)->lru);
163151
pmd_huge_pte(mm, pmdp) = pgtable;
164152
}
165-
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
166153
#endif
167154

168155
#ifndef __HAVE_ARCH_PGTABLE_WITHDRAW
169-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
170156
/* no "address" argument so destroys page coloring of some arch */
171157
pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
172158
{
@@ -185,23 +171,19 @@ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
185171
}
186172
return pgtable;
187173
}
188-
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
189174
#endif
190175

191176
#ifndef __HAVE_ARCH_PMDP_INVALIDATE
192-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
193177
void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
194178
pmd_t *pmdp)
195179
{
196180
pmd_t entry = *pmdp;
197181
set_pmd_at(vma->vm_mm, address, pmdp, pmd_mknotpresent(entry));
198182
flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
199183
}
200-
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
201184
#endif
202185

203186
#ifndef pmdp_collapse_flush
204-
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
205187
pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long address,
206188
pmd_t *pmdp)
207189
{
@@ -217,5 +199,5 @@ pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, unsigned long address,
217199
flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
218200
return pmd;
219201
}
220-
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
221202
#endif
203+
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */

0 commit comments

Comments
 (0)