1
2
3
4
5
6
7
8
9
10
11#ifndef __MM_INTERNAL_H
12#define __MM_INTERNAL_H
13
14#include <linux/fs.h>
15#include <linux/mm.h>
16
17void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
18 unsigned long floor, unsigned long ceiling);
19
20static inline void set_page_count(struct page *page, int v)
21{
22 atomic_set(&page->_count, v);
23}
24
25extern int __do_page_cache_readahead(struct address_space *mapping,
26 struct file *filp, pgoff_t offset, unsigned long nr_to_read,
27 unsigned long lookahead_size);
28
29
30
31
32static inline unsigned long ra_submit(struct file_ra_state *ra,
33 struct address_space *mapping, struct file *filp)
34{
35 return __do_page_cache_readahead(mapping, filp,
36 ra->start, ra->size, ra->async_size);
37}
38
39
40
41
42
43static inline void set_page_refcounted(struct page *page)
44{
45 VM_BUG_ON_PAGE(PageTail(page), page);
46 VM_BUG_ON_PAGE(atomic_read(&page->_count), page);
47 set_page_count(page, 1);
48}
49
50static inline void __get_page_tail_foll(struct page *page,
51 bool get_page_head)
52{
53
54
55
56
57
58
59
60
61
62
63
64 VM_BUG_ON_PAGE(atomic_read(&page->first_page->_count) <= 0, page);
65 if (get_page_head)
66 atomic_inc(&page->first_page->_count);
67 get_huge_page_tail(page);
68}
69
70
71
72
73
74
75static inline void get_page_foll(struct page *page)
76{
77 if (unlikely(PageTail(page)))
78
79
80
81
82
83 __get_page_tail_foll(page, true);
84 else {
85
86
87
88
89 VM_BUG_ON_PAGE(atomic_read(&page->_count) <= 0, page);
90 atomic_inc(&page->_count);
91 }
92}
93
94extern unsigned long highest_memmap_pfn;
95
96
97
98
99extern int isolate_lru_page(struct page *page);
100extern void putback_lru_page(struct page *page);
101extern bool zone_reclaimable(struct zone *zone);
102
103
104
105
106extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125struct alloc_context {
126 struct zonelist *zonelist;
127 nodemask_t *nodemask;
128 struct zone *preferred_zone;
129 int classzone_idx;
130 int migratetype;
131 enum zone_type high_zoneidx;
132};
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151static inline unsigned long
152__find_buddy_index(unsigned long page_idx, unsigned int order)
153{
154 return page_idx ^ (1 << order);
155}
156
157extern int __isolate_free_page(struct page *page, unsigned int order);
158extern void __free_pages_bootmem(struct page *page, unsigned int order);
159extern void prep_compound_page(struct page *page, unsigned long order);
160#ifdef CONFIG_MEMORY_FAILURE
161extern bool is_free_buddy_page(struct page *page);
162#endif
163extern int user_min_free_kbytes;
164
165#if defined CONFIG_COMPACTION || defined CONFIG_CMA
166
167
168
169
170
171
172
173
174
175
176
177struct compact_control {
178 struct list_head freepages;
179 struct list_head migratepages;
180 unsigned long nr_freepages;
181 unsigned long nr_migratepages;
182 unsigned long free_pfn;
183 unsigned long migrate_pfn;
184 enum migrate_mode mode;
185 bool ignore_skip_hint;
186 int order;
187 const gfp_t gfp_mask;
188 const int alloc_flags;
189 const int classzone_idx;
190 struct zone *zone;
191 int contended;
192
193
194
195};
196
197unsigned long
198isolate_freepages_range(struct compact_control *cc,
199 unsigned long start_pfn, unsigned long end_pfn);
200unsigned long
201isolate_migratepages_range(struct compact_control *cc,
202 unsigned long low_pfn, unsigned long end_pfn);
203int find_suitable_fallback(struct free_area *area, unsigned int order,
204 int migratetype, bool only_stealable, bool *can_steal);
205
206#endif
207
208
209
210
211
212
213
214
215
216static inline unsigned long page_order(struct page *page)
217{
218
219 return page_private(page);
220}
221
222
223
224
225
226
227
228
229
230
231
232
233#define page_order_unsafe(page) READ_ONCE(page_private(page))
234
235static inline bool is_cow_mapping(vm_flags_t flags)
236{
237 return (flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
238}
239
240
241void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
242 struct vm_area_struct *prev, struct rb_node *rb_parent);
243
244#ifdef CONFIG_MMU
245extern long populate_vma_page_range(struct vm_area_struct *vma,
246 unsigned long start, unsigned long end, int *nonblocking);
247extern void munlock_vma_pages_range(struct vm_area_struct *vma,
248 unsigned long start, unsigned long end);
249static inline void munlock_vma_pages_all(struct vm_area_struct *vma)
250{
251 munlock_vma_pages_range(vma, vma->vm_start, vma->vm_end);
252}
253
254
255
256
257extern void mlock_vma_page(struct page *page);
258extern unsigned int munlock_vma_page(struct page *page);
259
260
261
262
263
264
265
266
267
268
269extern void clear_page_mlock(struct page *page);
270
271
272
273
274
275static inline void mlock_migrate_page(struct page *newpage, struct page *page)
276{
277 if (TestClearPageMlocked(page)) {
278 unsigned long flags;
279 int nr_pages = hpage_nr_pages(page);
280
281 local_irq_save(flags);
282 __mod_zone_page_state(page_zone(page), NR_MLOCK, -nr_pages);
283 SetPageMlocked(newpage);
284 __mod_zone_page_state(page_zone(newpage), NR_MLOCK, nr_pages);
285 local_irq_restore(flags);
286 }
287}
288
289extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
290
291#ifdef CONFIG_TRANSPARENT_HUGEPAGE
292extern unsigned long vma_address(struct page *page,
293 struct vm_area_struct *vma);
294#endif
295#else
296static inline void clear_page_mlock(struct page *page) { }
297static inline void mlock_vma_page(struct page *page) { }
298static inline void mlock_migrate_page(struct page *new, struct page *old) { }
299
300#endif
301
302
303
304
305
306
307static inline struct page *mem_map_offset(struct page *base, int offset)
308{
309 if (unlikely(offset >= MAX_ORDER_NR_PAGES))
310 return nth_page(base, offset);
311 return base + offset;
312}
313
314
315
316
317
318static inline struct page *mem_map_next(struct page *iter,
319 struct page *base, int offset)
320{
321 if (unlikely((offset & (MAX_ORDER_NR_PAGES - 1)) == 0)) {
322 unsigned long pfn = page_to_pfn(base) + offset;
323 if (!pfn_valid(pfn))
324 return NULL;
325 return pfn_to_page(pfn);
326 }
327 return iter + 1;
328}
329
330
331
332
333
334
335
336#ifdef CONFIG_SPARSEMEM
337#define __paginginit __meminit
338#else
339#define __paginginit __init
340#endif
341
342
343enum mminit_level {
344 MMINIT_WARNING,
345 MMINIT_VERIFY,
346 MMINIT_TRACE
347};
348
349#ifdef CONFIG_DEBUG_MEMORY_INIT
350
351extern int mminit_loglevel;
352
353#define mminit_dprintk(level, prefix, fmt, arg...) \
354do { \
355 if (level < mminit_loglevel) { \
356 if (level <= MMINIT_WARNING) \
357 printk(KERN_WARNING "mminit::" prefix " " fmt, ##arg); \
358 else \
359 printk(KERN_DEBUG "mminit::" prefix " " fmt, ##arg); \
360 } \
361} while (0)
362
363extern void mminit_verify_pageflags_layout(void);
364extern void mminit_verify_page_links(struct page *page,
365 enum zone_type zone, unsigned long nid, unsigned long pfn);
366extern void mminit_verify_zonelist(void);
367
368#else
369
370static inline void mminit_dprintk(enum mminit_level level,
371 const char *prefix, const char *fmt, ...)
372{
373}
374
375static inline void mminit_verify_pageflags_layout(void)
376{
377}
378
379static inline void mminit_verify_page_links(struct page *page,
380 enum zone_type zone, unsigned long nid, unsigned long pfn)
381{
382}
383
384static inline void mminit_verify_zonelist(void)
385{
386}
387#endif
388
389
390#if defined(CONFIG_SPARSEMEM)
391extern void mminit_validate_memmodel_limits(unsigned long *start_pfn,
392 unsigned long *end_pfn);
393#else
394static inline void mminit_validate_memmodel_limits(unsigned long *start_pfn,
395 unsigned long *end_pfn)
396{
397}
398#endif
399
400#define ZONE_RECLAIM_NOSCAN -2
401#define ZONE_RECLAIM_FULL -1
402#define ZONE_RECLAIM_SOME 0
403#define ZONE_RECLAIM_SUCCESS 1
404
405extern int hwpoison_filter(struct page *p);
406
407extern u32 hwpoison_filter_dev_major;
408extern u32 hwpoison_filter_dev_minor;
409extern u64 hwpoison_filter_flags_mask;
410extern u64 hwpoison_filter_flags_value;
411extern u64 hwpoison_filter_memcg;
412extern u32 hwpoison_filter_enable;
413
414extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
415 unsigned long, unsigned long,
416 unsigned long, unsigned long);
417
418extern void set_pageblock_order(void);
419unsigned long reclaim_clean_pages_from_list(struct zone *zone,
420 struct list_head *page_list);
421
422#define ALLOC_WMARK_MIN WMARK_MIN
423#define ALLOC_WMARK_LOW WMARK_LOW
424#define ALLOC_WMARK_HIGH WMARK_HIGH
425#define ALLOC_NO_WATERMARKS 0x04
426
427
428#define ALLOC_WMARK_MASK (ALLOC_NO_WATERMARKS-1)
429
430#define ALLOC_HARDER 0x10
431#define ALLOC_HIGH 0x20
432#define ALLOC_CPUSET 0x40
433#define ALLOC_CMA 0x80
434#define ALLOC_FAIR 0x100
435
436#endif
437