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#include <linux/pagemap.h>
17#include <linux/tracepoint-defs.h>
18
19
20
21
22
23
24
25#define GFP_RECLAIM_MASK (__GFP_RECLAIM|__GFP_HIGH|__GFP_IO|__GFP_FS|\
26 __GFP_NOWARN|__GFP_RETRY_MAYFAIL|__GFP_NOFAIL|\
27 __GFP_NORETRY|__GFP_MEMALLOC|__GFP_NOMEMALLOC|\
28 __GFP_ATOMIC)
29
30
31#define GFP_BOOT_MASK (__GFP_BITS_MASK & ~(__GFP_RECLAIM|__GFP_IO|__GFP_FS))
32
33
34#define GFP_CONSTRAINT_MASK (__GFP_HARDWALL|__GFP_THISNODE)
35
36
37#define GFP_SLAB_BUG_MASK (__GFP_DMA32|__GFP_HIGHMEM|~__GFP_BITS_MASK)
38
39void page_writeback_init(void);
40
41vm_fault_t do_swap_page(struct vm_fault *vmf);
42
43void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
44 unsigned long floor, unsigned long ceiling);
45
46static inline bool can_madv_dontneed_vma(struct vm_area_struct *vma)
47{
48 return !(vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP));
49}
50
51void unmap_page_range(struct mmu_gather *tlb,
52 struct vm_area_struct *vma,
53 unsigned long addr, unsigned long end,
54 struct zap_details *details);
55
56extern unsigned int __do_page_cache_readahead(struct address_space *mapping,
57 struct file *filp, pgoff_t offset, unsigned long nr_to_read,
58 unsigned long lookahead_size);
59
60
61
62
63static inline unsigned long ra_submit(struct file_ra_state *ra,
64 struct address_space *mapping, struct file *filp)
65{
66 return __do_page_cache_readahead(mapping, filp,
67 ra->start, ra->size, ra->async_size);
68}
69
70
71
72
73
74static inline void set_page_refcounted(struct page *page)
75{
76 VM_BUG_ON_PAGE(PageTail(page), page);
77 VM_BUG_ON_PAGE(page_ref_count(page), page);
78 set_page_count(page, 1);
79}
80
81extern unsigned long highest_memmap_pfn;
82
83
84
85
86
87#define MAX_RECLAIM_RETRIES 16
88
89
90
91
92extern int isolate_lru_page(struct page *page);
93extern void putback_lru_page(struct page *page);
94
95
96
97
98extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117struct alloc_context {
118 struct zonelist *zonelist;
119 nodemask_t *nodemask;
120 struct zoneref *preferred_zoneref;
121 int migratetype;
122 enum zone_type high_zoneidx;
123 bool spread_dirty_pages;
124};
125
126#define ac_classzone_idx(ac) zonelist_zone_idx(ac->preferred_zoneref)
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145static inline unsigned long
146__find_buddy_pfn(unsigned long page_pfn, unsigned int order)
147{
148 return page_pfn ^ (1 << order);
149}
150
151extern struct page *__pageblock_pfn_to_page(unsigned long start_pfn,
152 unsigned long end_pfn, struct zone *zone);
153
154static inline struct page *pageblock_pfn_to_page(unsigned long start_pfn,
155 unsigned long end_pfn, struct zone *zone)
156{
157 if (zone->contiguous)
158 return pfn_to_page(start_pfn);
159
160 return __pageblock_pfn_to_page(start_pfn, end_pfn, zone);
161}
162
163extern int __isolate_free_page(struct page *page, unsigned int order);
164extern void memblock_free_pages(struct page *page, unsigned long pfn,
165 unsigned int order);
166extern void prep_compound_page(struct page *page, unsigned int order);
167extern void post_alloc_hook(struct page *page, unsigned int order,
168 gfp_t gfp_flags);
169extern int user_min_free_kbytes;
170
171#if defined CONFIG_COMPACTION || defined CONFIG_CMA
172
173
174
175
176
177
178
179
180
181
182
183struct compact_control {
184 struct list_head freepages;
185 struct list_head migratepages;
186 struct zone *zone;
187 unsigned long nr_freepages;
188 unsigned long nr_migratepages;
189 unsigned long total_migrate_scanned;
190 unsigned long total_free_scanned;
191 unsigned long free_pfn;
192 unsigned long migrate_pfn;
193 unsigned long last_migrated_pfn;
194 const gfp_t gfp_mask;
195 int order;
196 int migratetype;
197 const unsigned int alloc_flags;
198 const int classzone_idx;
199 enum migrate_mode mode;
200 bool ignore_skip_hint;
201 bool no_set_skip_hint;
202 bool ignore_block_suitable;
203 bool direct_compaction;
204 bool whole_zone;
205 bool contended;
206 bool finishing_block;
207};
208
209unsigned long
210isolate_freepages_range(struct compact_control *cc,
211 unsigned long start_pfn, unsigned long end_pfn);
212unsigned long
213isolate_migratepages_range(struct compact_control *cc,
214 unsigned long low_pfn, unsigned long end_pfn);
215int find_suitable_fallback(struct free_area *area, unsigned int order,
216 int migratetype, bool only_stealable, bool *can_steal);
217
218#endif
219
220
221
222
223
224
225
226
227
228static inline unsigned int page_order(struct page *page)
229{
230
231 return page_private(page);
232}
233
234
235
236
237
238
239
240
241
242
243
244
245#define page_order_unsafe(page) READ_ONCE(page_private(page))
246
247static inline bool is_cow_mapping(vm_flags_t flags)
248{
249 return (flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
250}
251
252
253
254
255
256
257
258
259static inline bool is_exec_mapping(vm_flags_t flags)
260{
261 return (flags & (VM_EXEC | VM_WRITE | VM_STACK)) == VM_EXEC;
262}
263
264
265
266
267
268
269
270static inline bool is_stack_mapping(vm_flags_t flags)
271{
272 return (flags & VM_STACK) == VM_STACK;
273}
274
275
276
277
278static inline bool is_data_mapping(vm_flags_t flags)
279{
280 return (flags & (VM_WRITE | VM_SHARED | VM_STACK)) == VM_WRITE;
281}
282
283
284void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
285 struct vm_area_struct *prev, struct rb_node *rb_parent);
286
287#ifdef CONFIG_MMU
288extern long populate_vma_page_range(struct vm_area_struct *vma,
289 unsigned long start, unsigned long end, int *nonblocking);
290extern void munlock_vma_pages_range(struct vm_area_struct *vma,
291 unsigned long start, unsigned long end);
292static inline void munlock_vma_pages_all(struct vm_area_struct *vma)
293{
294 munlock_vma_pages_range(vma, vma->vm_start, vma->vm_end);
295}
296
297
298
299
300extern void mlock_vma_page(struct page *page);
301extern unsigned int munlock_vma_page(struct page *page);
302
303
304
305
306
307
308
309
310
311
312extern void clear_page_mlock(struct page *page);
313
314
315
316
317
318
319static inline void mlock_migrate_page(struct page *newpage, struct page *page)
320{
321 if (TestClearPageMlocked(page)) {
322 int nr_pages = hpage_nr_pages(page);
323
324
325 __mod_zone_page_state(page_zone(page), NR_MLOCK, -nr_pages);
326 SetPageMlocked(newpage);
327 __mod_zone_page_state(page_zone(newpage), NR_MLOCK, nr_pages);
328 }
329}
330
331extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
332
333
334
335
336static inline unsigned long
337__vma_address(struct page *page, struct vm_area_struct *vma)
338{
339 pgoff_t pgoff = page_to_pgoff(page);
340 return vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
341}
342
343static inline unsigned long
344vma_address(struct page *page, struct vm_area_struct *vma)
345{
346 unsigned long start, end;
347
348 start = __vma_address(page, vma);
349 end = start + PAGE_SIZE * (hpage_nr_pages(page) - 1);
350
351
352 VM_BUG_ON_VMA(end < vma->vm_start || start >= vma->vm_end, vma);
353
354 return max(start, vma->vm_start);
355}
356
357#else
358static inline void clear_page_mlock(struct page *page) { }
359static inline void mlock_vma_page(struct page *page) { }
360static inline void mlock_migrate_page(struct page *new, struct page *old) { }
361
362#endif
363
364
365
366
367
368
369static inline struct page *mem_map_offset(struct page *base, int offset)
370{
371 if (unlikely(offset >= MAX_ORDER_NR_PAGES))
372 return nth_page(base, offset);
373 return base + offset;
374}
375
376
377
378
379
380static inline struct page *mem_map_next(struct page *iter,
381 struct page *base, int offset)
382{
383 if (unlikely((offset & (MAX_ORDER_NR_PAGES - 1)) == 0)) {
384 unsigned long pfn = page_to_pfn(base) + offset;
385 if (!pfn_valid(pfn))
386 return NULL;
387 return pfn_to_page(pfn);
388 }
389 return iter + 1;
390}
391
392
393enum mminit_level {
394 MMINIT_WARNING,
395 MMINIT_VERIFY,
396 MMINIT_TRACE
397};
398
399#ifdef CONFIG_DEBUG_MEMORY_INIT
400
401extern int mminit_loglevel;
402
403#define mminit_dprintk(level, prefix, fmt, arg...) \
404do { \
405 if (level < mminit_loglevel) { \
406 if (level <= MMINIT_WARNING) \
407 pr_warn("mminit::" prefix " " fmt, ##arg); \
408 else \
409 printk(KERN_DEBUG "mminit::" prefix " " fmt, ##arg); \
410 } \
411} while (0)
412
413extern void mminit_verify_pageflags_layout(void);
414extern void mminit_verify_zonelist(void);
415#else
416
417static inline void mminit_dprintk(enum mminit_level level,
418 const char *prefix, const char *fmt, ...)
419{
420}
421
422static inline void mminit_verify_pageflags_layout(void)
423{
424}
425
426static inline void mminit_verify_zonelist(void)
427{
428}
429#endif
430
431
432#if defined(CONFIG_SPARSEMEM)
433extern void mminit_validate_memmodel_limits(unsigned long *start_pfn,
434 unsigned long *end_pfn);
435#else
436static inline void mminit_validate_memmodel_limits(unsigned long *start_pfn,
437 unsigned long *end_pfn)
438{
439}
440#endif
441
442#define NODE_RECLAIM_NOSCAN -2
443#define NODE_RECLAIM_FULL -1
444#define NODE_RECLAIM_SOME 0
445#define NODE_RECLAIM_SUCCESS 1
446
447#ifdef CONFIG_NUMA
448extern int node_reclaim(struct pglist_data *, gfp_t, unsigned int);
449#else
450static inline int node_reclaim(struct pglist_data *pgdat, gfp_t mask,
451 unsigned int order)
452{
453 return NODE_RECLAIM_NOSCAN;
454}
455#endif
456
457extern int hwpoison_filter(struct page *p);
458
459extern u32 hwpoison_filter_dev_major;
460extern u32 hwpoison_filter_dev_minor;
461extern u64 hwpoison_filter_flags_mask;
462extern u64 hwpoison_filter_flags_value;
463extern u64 hwpoison_filter_memcg;
464extern u32 hwpoison_filter_enable;
465
466extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long,
467 unsigned long, unsigned long,
468 unsigned long, unsigned long);
469
470extern void set_pageblock_order(void);
471unsigned long reclaim_clean_pages_from_list(struct zone *zone,
472 struct list_head *page_list);
473
474#define ALLOC_WMARK_MIN WMARK_MIN
475#define ALLOC_WMARK_LOW WMARK_LOW
476#define ALLOC_WMARK_HIGH WMARK_HIGH
477#define ALLOC_NO_WATERMARKS 0x04
478
479
480#define ALLOC_WMARK_MASK (ALLOC_NO_WATERMARKS-1)
481
482
483
484
485
486
487#ifdef CONFIG_MMU
488#define ALLOC_OOM 0x08
489#else
490#define ALLOC_OOM ALLOC_NO_WATERMARKS
491#endif
492
493#define ALLOC_HARDER 0x10
494#define ALLOC_HIGH 0x20
495#define ALLOC_CPUSET 0x40
496#define ALLOC_CMA 0x80
497#ifdef CONFIG_ZONE_DMA32
498#define ALLOC_NOFRAGMENT 0x100
499#else
500#define ALLOC_NOFRAGMENT 0x0
501#endif
502#define ALLOC_KSWAPD 0x200
503
504enum ttu_flags;
505struct tlbflush_unmap_batch;
506
507
508
509
510
511
512extern struct workqueue_struct *mm_percpu_wq;
513
514#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
515void try_to_unmap_flush(void);
516void try_to_unmap_flush_dirty(void);
517void flush_tlb_batched_pending(struct mm_struct *mm);
518#else
519static inline void try_to_unmap_flush(void)
520{
521}
522static inline void try_to_unmap_flush_dirty(void)
523{
524}
525static inline void flush_tlb_batched_pending(struct mm_struct *mm)
526{
527}
528#endif
529
530extern const struct trace_print_flags pageflag_names[];
531extern const struct trace_print_flags vmaflag_names[];
532extern const struct trace_print_flags gfpflag_names[];
533
534static inline bool is_migrate_highatomic(enum migratetype migratetype)
535{
536 return migratetype == MIGRATE_HIGHATOMIC;
537}
538
539static inline bool is_migrate_highatomic_page(struct page *page)
540{
541 return get_pageblock_migratetype(page) == MIGRATE_HIGHATOMIC;
542}
543
544void setup_zone_pageset(struct zone *zone);
545extern struct page *alloc_new_node_page(struct page *page, unsigned long node);
546#endif
547