mm/munlock: mlock_page() munlock_page() batch by pagevec
[linux-2.6-microblaze.git] / mm / internal.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* internal.h: mm/ internal definitions
3  *
4  * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
5  * Written by David Howells (dhowells@redhat.com)
6  */
7 #ifndef __MM_INTERNAL_H
8 #define __MM_INTERNAL_H
9
10 #include <linux/fs.h>
11 #include <linux/mm.h>
12 #include <linux/pagemap.h>
13 #include <linux/tracepoint-defs.h>
14
15 struct folio_batch;
16
17 /*
18  * The set of flags that only affect watermark checking and reclaim
19  * behaviour. This is used by the MM to obey the caller constraints
20  * about IO, FS and watermark checking while ignoring placement
21  * hints such as HIGHMEM usage.
22  */
23 #define GFP_RECLAIM_MASK (__GFP_RECLAIM|__GFP_HIGH|__GFP_IO|__GFP_FS|\
24                         __GFP_NOWARN|__GFP_RETRY_MAYFAIL|__GFP_NOFAIL|\
25                         __GFP_NORETRY|__GFP_MEMALLOC|__GFP_NOMEMALLOC|\
26                         __GFP_ATOMIC|__GFP_NOLOCKDEP)
27
28 /* The GFP flags allowed during early boot */
29 #define GFP_BOOT_MASK (__GFP_BITS_MASK & ~(__GFP_RECLAIM|__GFP_IO|__GFP_FS))
30
31 /* Control allocation cpuset and node placement constraints */
32 #define GFP_CONSTRAINT_MASK (__GFP_HARDWALL|__GFP_THISNODE)
33
34 /* Do not use these with a slab allocator */
35 #define GFP_SLAB_BUG_MASK (__GFP_DMA32|__GFP_HIGHMEM|~__GFP_BITS_MASK)
36
37 void page_writeback_init(void);
38
39 static inline void *folio_raw_mapping(struct folio *folio)
40 {
41         unsigned long mapping = (unsigned long)folio->mapping;
42
43         return (void *)(mapping & ~PAGE_MAPPING_FLAGS);
44 }
45
46 void __acct_reclaim_writeback(pg_data_t *pgdat, struct folio *folio,
47                                                 int nr_throttled);
48 static inline void acct_reclaim_writeback(struct folio *folio)
49 {
50         pg_data_t *pgdat = folio_pgdat(folio);
51         int nr_throttled = atomic_read(&pgdat->nr_writeback_throttled);
52
53         if (nr_throttled)
54                 __acct_reclaim_writeback(pgdat, folio, nr_throttled);
55 }
56
57 static inline void wake_throttle_isolated(pg_data_t *pgdat)
58 {
59         wait_queue_head_t *wqh;
60
61         wqh = &pgdat->reclaim_wait[VMSCAN_THROTTLE_ISOLATED];
62         if (waitqueue_active(wqh))
63                 wake_up(wqh);
64 }
65
66 vm_fault_t do_swap_page(struct vm_fault *vmf);
67 void folio_rotate_reclaimable(struct folio *folio);
68 bool __folio_end_writeback(struct folio *folio);
69
70 void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
71                 unsigned long floor, unsigned long ceiling);
72 void pmd_install(struct mm_struct *mm, pmd_t *pmd, pgtable_t *pte);
73
74 struct zap_details;
75 void unmap_page_range(struct mmu_gather *tlb,
76                              struct vm_area_struct *vma,
77                              unsigned long addr, unsigned long end,
78                              struct zap_details *details);
79
80 void do_page_cache_ra(struct readahead_control *, unsigned long nr_to_read,
81                 unsigned long lookahead_size);
82 void force_page_cache_ra(struct readahead_control *, unsigned long nr);
83 static inline void force_page_cache_readahead(struct address_space *mapping,
84                 struct file *file, pgoff_t index, unsigned long nr_to_read)
85 {
86         DEFINE_READAHEAD(ractl, file, &file->f_ra, mapping, index);
87         force_page_cache_ra(&ractl, nr_to_read);
88 }
89
90 unsigned find_lock_entries(struct address_space *mapping, pgoff_t start,
91                 pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices);
92 unsigned find_get_entries(struct address_space *mapping, pgoff_t start,
93                 pgoff_t end, struct folio_batch *fbatch, pgoff_t *indices);
94 void filemap_free_folio(struct address_space *mapping, struct folio *folio);
95 int truncate_inode_folio(struct address_space *mapping, struct folio *folio);
96 bool truncate_inode_partial_folio(struct folio *folio, loff_t start,
97                 loff_t end);
98
99 /**
100  * folio_evictable - Test whether a folio is evictable.
101  * @folio: The folio to test.
102  *
103  * Test whether @folio is evictable -- i.e., should be placed on
104  * active/inactive lists vs unevictable list.
105  *
106  * Reasons folio might not be evictable:
107  * 1. folio's mapping marked unevictable
108  * 2. One of the pages in the folio is part of an mlocked VMA
109  */
110 static inline bool folio_evictable(struct folio *folio)
111 {
112         bool ret;
113
114         /* Prevent address_space of inode and swap cache from being freed */
115         rcu_read_lock();
116         ret = !mapping_unevictable(folio_mapping(folio)) &&
117                         !folio_test_mlocked(folio);
118         rcu_read_unlock();
119         return ret;
120 }
121
122 static inline bool page_evictable(struct page *page)
123 {
124         bool ret;
125
126         /* Prevent address_space of inode and swap cache from being freed */
127         rcu_read_lock();
128         ret = !mapping_unevictable(page_mapping(page)) && !PageMlocked(page);
129         rcu_read_unlock();
130         return ret;
131 }
132
133 /*
134  * Turn a non-refcounted page (->_refcount == 0) into refcounted with
135  * a count of one.
136  */
137 static inline void set_page_refcounted(struct page *page)
138 {
139         VM_BUG_ON_PAGE(PageTail(page), page);
140         VM_BUG_ON_PAGE(page_ref_count(page), page);
141         set_page_count(page, 1);
142 }
143
144 extern unsigned long highest_memmap_pfn;
145
146 /*
147  * Maximum number of reclaim retries without progress before the OOM
148  * killer is consider the only way forward.
149  */
150 #define MAX_RECLAIM_RETRIES 16
151
152 /*
153  * in mm/vmscan.c:
154  */
155 extern int isolate_lru_page(struct page *page);
156 extern void putback_lru_page(struct page *page);
157 extern void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_state reason);
158
159 /*
160  * in mm/rmap.c:
161  */
162 extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
163
164 /*
165  * in mm/page_alloc.c
166  */
167
168 /*
169  * Structure for holding the mostly immutable allocation parameters passed
170  * between functions involved in allocations, including the alloc_pages*
171  * family of functions.
172  *
173  * nodemask, migratetype and highest_zoneidx are initialized only once in
174  * __alloc_pages() and then never change.
175  *
176  * zonelist, preferred_zone and highest_zoneidx are set first in
177  * __alloc_pages() for the fast path, and might be later changed
178  * in __alloc_pages_slowpath(). All other functions pass the whole structure
179  * by a const pointer.
180  */
181 struct alloc_context {
182         struct zonelist *zonelist;
183         nodemask_t *nodemask;
184         struct zoneref *preferred_zoneref;
185         int migratetype;
186
187         /*
188          * highest_zoneidx represents highest usable zone index of
189          * the allocation request. Due to the nature of the zone,
190          * memory on lower zone than the highest_zoneidx will be
191          * protected by lowmem_reserve[highest_zoneidx].
192          *
193          * highest_zoneidx is also used by reclaim/compaction to limit
194          * the target zone since higher zone than this index cannot be
195          * usable for this allocation request.
196          */
197         enum zone_type highest_zoneidx;
198         bool spread_dirty_pages;
199 };
200
201 /*
202  * Locate the struct page for both the matching buddy in our
203  * pair (buddy1) and the combined O(n+1) page they form (page).
204  *
205  * 1) Any buddy B1 will have an order O twin B2 which satisfies
206  * the following equation:
207  *     B2 = B1 ^ (1 << O)
208  * For example, if the starting buddy (buddy2) is #8 its order
209  * 1 buddy is #10:
210  *     B2 = 8 ^ (1 << 1) = 8 ^ 2 = 10
211  *
212  * 2) Any buddy B will have an order O+1 parent P which
213  * satisfies the following equation:
214  *     P = B & ~(1 << O)
215  *
216  * Assumption: *_mem_map is contiguous at least up to MAX_ORDER
217  */
218 static inline unsigned long
219 __find_buddy_pfn(unsigned long page_pfn, unsigned int order)
220 {
221         return page_pfn ^ (1 << order);
222 }
223
224 extern struct page *__pageblock_pfn_to_page(unsigned long start_pfn,
225                                 unsigned long end_pfn, struct zone *zone);
226
227 static inline struct page *pageblock_pfn_to_page(unsigned long start_pfn,
228                                 unsigned long end_pfn, struct zone *zone)
229 {
230         if (zone->contiguous)
231                 return pfn_to_page(start_pfn);
232
233         return __pageblock_pfn_to_page(start_pfn, end_pfn, zone);
234 }
235
236 extern int __isolate_free_page(struct page *page, unsigned int order);
237 extern void __putback_isolated_page(struct page *page, unsigned int order,
238                                     int mt);
239 extern void memblock_free_pages(struct page *page, unsigned long pfn,
240                                         unsigned int order);
241 extern void __free_pages_core(struct page *page, unsigned int order);
242 extern void prep_compound_page(struct page *page, unsigned int order);
243 extern void post_alloc_hook(struct page *page, unsigned int order,
244                                         gfp_t gfp_flags);
245 extern int user_min_free_kbytes;
246
247 extern void free_unref_page(struct page *page, unsigned int order);
248 extern void free_unref_page_list(struct list_head *list);
249
250 extern void zone_pcp_update(struct zone *zone, int cpu_online);
251 extern void zone_pcp_reset(struct zone *zone);
252 extern void zone_pcp_disable(struct zone *zone);
253 extern void zone_pcp_enable(struct zone *zone);
254
255 extern void *memmap_alloc(phys_addr_t size, phys_addr_t align,
256                           phys_addr_t min_addr,
257                           int nid, bool exact_nid);
258
259 #if defined CONFIG_COMPACTION || defined CONFIG_CMA
260
261 /*
262  * in mm/compaction.c
263  */
264 /*
265  * compact_control is used to track pages being migrated and the free pages
266  * they are being migrated to during memory compaction. The free_pfn starts
267  * at the end of a zone and migrate_pfn begins at the start. Movable pages
268  * are moved to the end of a zone during a compaction run and the run
269  * completes when free_pfn <= migrate_pfn
270  */
271 struct compact_control {
272         struct list_head freepages;     /* List of free pages to migrate to */
273         struct list_head migratepages;  /* List of pages being migrated */
274         unsigned int nr_freepages;      /* Number of isolated free pages */
275         unsigned int nr_migratepages;   /* Number of pages to migrate */
276         unsigned long free_pfn;         /* isolate_freepages search base */
277         /*
278          * Acts as an in/out parameter to page isolation for migration.
279          * isolate_migratepages uses it as a search base.
280          * isolate_migratepages_block will update the value to the next pfn
281          * after the last isolated one.
282          */
283         unsigned long migrate_pfn;
284         unsigned long fast_start_pfn;   /* a pfn to start linear scan from */
285         struct zone *zone;
286         unsigned long total_migrate_scanned;
287         unsigned long total_free_scanned;
288         unsigned short fast_search_fail;/* failures to use free list searches */
289         short search_order;             /* order to start a fast search at */
290         const gfp_t gfp_mask;           /* gfp mask of a direct compactor */
291         int order;                      /* order a direct compactor needs */
292         int migratetype;                /* migratetype of direct compactor */
293         const unsigned int alloc_flags; /* alloc flags of a direct compactor */
294         const int highest_zoneidx;      /* zone index of a direct compactor */
295         enum migrate_mode mode;         /* Async or sync migration mode */
296         bool ignore_skip_hint;          /* Scan blocks even if marked skip */
297         bool no_set_skip_hint;          /* Don't mark blocks for skipping */
298         bool ignore_block_suitable;     /* Scan blocks considered unsuitable */
299         bool direct_compaction;         /* False from kcompactd or /proc/... */
300         bool proactive_compaction;      /* kcompactd proactive compaction */
301         bool whole_zone;                /* Whole zone should/has been scanned */
302         bool contended;                 /* Signal lock or sched contention */
303         bool rescan;                    /* Rescanning the same pageblock */
304         bool alloc_contig;              /* alloc_contig_range allocation */
305 };
306
307 /*
308  * Used in direct compaction when a page should be taken from the freelists
309  * immediately when one is created during the free path.
310  */
311 struct capture_control {
312         struct compact_control *cc;
313         struct page *page;
314 };
315
316 unsigned long
317 isolate_freepages_range(struct compact_control *cc,
318                         unsigned long start_pfn, unsigned long end_pfn);
319 int
320 isolate_migratepages_range(struct compact_control *cc,
321                            unsigned long low_pfn, unsigned long end_pfn);
322 #endif
323 int find_suitable_fallback(struct free_area *area, unsigned int order,
324                         int migratetype, bool only_stealable, bool *can_steal);
325
326 /*
327  * This function returns the order of a free page in the buddy system. In
328  * general, page_zone(page)->lock must be held by the caller to prevent the
329  * page from being allocated in parallel and returning garbage as the order.
330  * If a caller does not hold page_zone(page)->lock, it must guarantee that the
331  * page cannot be allocated or merged in parallel. Alternatively, it must
332  * handle invalid values gracefully, and use buddy_order_unsafe() below.
333  */
334 static inline unsigned int buddy_order(struct page *page)
335 {
336         /* PageBuddy() must be checked by the caller */
337         return page_private(page);
338 }
339
340 /*
341  * Like buddy_order(), but for callers who cannot afford to hold the zone lock.
342  * PageBuddy() should be checked first by the caller to minimize race window,
343  * and invalid values must be handled gracefully.
344  *
345  * READ_ONCE is used so that if the caller assigns the result into a local
346  * variable and e.g. tests it for valid range before using, the compiler cannot
347  * decide to remove the variable and inline the page_private(page) multiple
348  * times, potentially observing different values in the tests and the actual
349  * use of the result.
350  */
351 #define buddy_order_unsafe(page)        READ_ONCE(page_private(page))
352
353 /*
354  * These three helpers classifies VMAs for virtual memory accounting.
355  */
356
357 /*
358  * Executable code area - executable, not writable, not stack
359  */
360 static inline bool is_exec_mapping(vm_flags_t flags)
361 {
362         return (flags & (VM_EXEC | VM_WRITE | VM_STACK)) == VM_EXEC;
363 }
364
365 /*
366  * Stack area - automatically grows in one direction
367  *
368  * VM_GROWSUP / VM_GROWSDOWN VMAs are always private anonymous:
369  * do_mmap() forbids all other combinations.
370  */
371 static inline bool is_stack_mapping(vm_flags_t flags)
372 {
373         return (flags & VM_STACK) == VM_STACK;
374 }
375
376 /*
377  * Data area - private, writable, not stack
378  */
379 static inline bool is_data_mapping(vm_flags_t flags)
380 {
381         return (flags & (VM_WRITE | VM_SHARED | VM_STACK)) == VM_WRITE;
382 }
383
384 /* mm/util.c */
385 void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
386                 struct vm_area_struct *prev);
387 void __vma_unlink_list(struct mm_struct *mm, struct vm_area_struct *vma);
388
389 #ifdef CONFIG_MMU
390 void unmap_mapping_folio(struct folio *folio);
391 extern long populate_vma_page_range(struct vm_area_struct *vma,
392                 unsigned long start, unsigned long end, int *locked);
393 extern long faultin_vma_page_range(struct vm_area_struct *vma,
394                                    unsigned long start, unsigned long end,
395                                    bool write, int *locked);
396 extern int mlock_future_check(struct mm_struct *mm, unsigned long flags,
397                               unsigned long len);
398 /*
399  * mlock_vma_page() and munlock_vma_page():
400  * should be called with vma's mmap_lock held for read or write,
401  * under page table lock for the pte/pmd being added or removed.
402  *
403  * mlock is usually called at the end of page_add_*_rmap(),
404  * munlock at the end of page_remove_rmap(); but new anon
405  * pages are managed by lru_cache_add_inactive_or_unevictable()
406  * calling mlock_new_page().
407  *
408  * @compound is used to include pmd mappings of THPs, but filter out
409  * pte mappings of THPs, which cannot be consistently counted: a pte
410  * mapping of the THP head cannot be distinguished by the page alone.
411  */
412 void mlock_page(struct page *page);
413 static inline void mlock_vma_page(struct page *page,
414                         struct vm_area_struct *vma, bool compound)
415 {
416         /* VM_IO check prevents migration from double-counting during mlock */
417         if (unlikely((vma->vm_flags & (VM_LOCKED|VM_IO)) == VM_LOCKED) &&
418             (compound || !PageTransCompound(page)))
419                 mlock_page(page);
420 }
421 void munlock_page(struct page *page);
422 static inline void munlock_vma_page(struct page *page,
423                         struct vm_area_struct *vma, bool compound)
424 {
425         if (unlikely(vma->vm_flags & VM_LOCKED) &&
426             (compound || !PageTransCompound(page)))
427                 munlock_page(page);
428 }
429 void mlock_new_page(struct page *page);
430 bool need_mlock_page_drain(int cpu);
431 void mlock_page_drain(int cpu);
432
433 extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
434
435 /*
436  * At what user virtual address is page expected in vma?
437  * Returns -EFAULT if all of the page is outside the range of vma.
438  * If page is a compound head, the entire compound page is considered.
439  */
440 static inline unsigned long
441 vma_address(struct page *page, struct vm_area_struct *vma)
442 {
443         pgoff_t pgoff;
444         unsigned long address;
445
446         VM_BUG_ON_PAGE(PageKsm(page), page);    /* KSM page->index unusable */
447         pgoff = page_to_pgoff(page);
448         if (pgoff >= vma->vm_pgoff) {
449                 address = vma->vm_start +
450                         ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
451                 /* Check for address beyond vma (or wrapped through 0?) */
452                 if (address < vma->vm_start || address >= vma->vm_end)
453                         address = -EFAULT;
454         } else if (PageHead(page) &&
455                    pgoff + compound_nr(page) - 1 >= vma->vm_pgoff) {
456                 /* Test above avoids possibility of wrap to 0 on 32-bit */
457                 address = vma->vm_start;
458         } else {
459                 address = -EFAULT;
460         }
461         return address;
462 }
463
464 /*
465  * Then at what user virtual address will none of the page be found in vma?
466  * Assumes that vma_address() already returned a good starting address.
467  * If page is a compound head, the entire compound page is considered.
468  */
469 static inline unsigned long
470 vma_address_end(struct page *page, struct vm_area_struct *vma)
471 {
472         pgoff_t pgoff;
473         unsigned long address;
474
475         VM_BUG_ON_PAGE(PageKsm(page), page);    /* KSM page->index unusable */
476         pgoff = page_to_pgoff(page) + compound_nr(page);
477         address = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
478         /* Check for address beyond vma (or wrapped through 0?) */
479         if (address < vma->vm_start || address > vma->vm_end)
480                 address = vma->vm_end;
481         return address;
482 }
483
484 static inline struct file *maybe_unlock_mmap_for_io(struct vm_fault *vmf,
485                                                     struct file *fpin)
486 {
487         int flags = vmf->flags;
488
489         if (fpin)
490                 return fpin;
491
492         /*
493          * FAULT_FLAG_RETRY_NOWAIT means we don't want to wait on page locks or
494          * anything, so we only pin the file and drop the mmap_lock if only
495          * FAULT_FLAG_ALLOW_RETRY is set, while this is the first attempt.
496          */
497         if (fault_flag_allow_retry_first(flags) &&
498             !(flags & FAULT_FLAG_RETRY_NOWAIT)) {
499                 fpin = get_file(vmf->vma->vm_file);
500                 mmap_read_unlock(vmf->vma->vm_mm);
501         }
502         return fpin;
503 }
504 #else /* !CONFIG_MMU */
505 static inline void unmap_mapping_folio(struct folio *folio) { }
506 static inline void mlock_vma_page(struct page *page,
507                         struct vm_area_struct *vma, bool compound) { }
508 static inline void munlock_vma_page(struct page *page,
509                         struct vm_area_struct *vma, bool compound) { }
510 static inline void mlock_new_page(struct page *page) { }
511 static inline bool need_mlock_page_drain(int cpu) { return false; }
512 static inline void mlock_page_drain(int cpu) { }
513 static inline void vunmap_range_noflush(unsigned long start, unsigned long end)
514 {
515 }
516 #endif /* !CONFIG_MMU */
517
518 /*
519  * Return the mem_map entry representing the 'offset' subpage within
520  * the maximally aligned gigantic page 'base'.  Handle any discontiguity
521  * in the mem_map at MAX_ORDER_NR_PAGES boundaries.
522  */
523 static inline struct page *mem_map_offset(struct page *base, int offset)
524 {
525         if (unlikely(offset >= MAX_ORDER_NR_PAGES))
526                 return nth_page(base, offset);
527         return base + offset;
528 }
529
530 /*
531  * Iterator over all subpages within the maximally aligned gigantic
532  * page 'base'.  Handle any discontiguity in the mem_map.
533  */
534 static inline struct page *mem_map_next(struct page *iter,
535                                                 struct page *base, int offset)
536 {
537         if (unlikely((offset & (MAX_ORDER_NR_PAGES - 1)) == 0)) {
538                 unsigned long pfn = page_to_pfn(base) + offset;
539                 if (!pfn_valid(pfn))
540                         return NULL;
541                 return pfn_to_page(pfn);
542         }
543         return iter + 1;
544 }
545
546 /* Memory initialisation debug and verification */
547 enum mminit_level {
548         MMINIT_WARNING,
549         MMINIT_VERIFY,
550         MMINIT_TRACE
551 };
552
553 #ifdef CONFIG_DEBUG_MEMORY_INIT
554
555 extern int mminit_loglevel;
556
557 #define mminit_dprintk(level, prefix, fmt, arg...) \
558 do { \
559         if (level < mminit_loglevel) { \
560                 if (level <= MMINIT_WARNING) \
561                         pr_warn("mminit::" prefix " " fmt, ##arg);      \
562                 else \
563                         printk(KERN_DEBUG "mminit::" prefix " " fmt, ##arg); \
564         } \
565 } while (0)
566
567 extern void mminit_verify_pageflags_layout(void);
568 extern void mminit_verify_zonelist(void);
569 #else
570
571 static inline void mminit_dprintk(enum mminit_level level,
572                                 const char *prefix, const char *fmt, ...)
573 {
574 }
575
576 static inline void mminit_verify_pageflags_layout(void)
577 {
578 }
579
580 static inline void mminit_verify_zonelist(void)
581 {
582 }
583 #endif /* CONFIG_DEBUG_MEMORY_INIT */
584
585 /* mminit_validate_memmodel_limits is independent of CONFIG_DEBUG_MEMORY_INIT */
586 #if defined(CONFIG_SPARSEMEM)
587 extern void mminit_validate_memmodel_limits(unsigned long *start_pfn,
588                                 unsigned long *end_pfn);
589 #else
590 static inline void mminit_validate_memmodel_limits(unsigned long *start_pfn,
591                                 unsigned long *end_pfn)
592 {
593 }
594 #endif /* CONFIG_SPARSEMEM */
595
596 #define NODE_RECLAIM_NOSCAN     -2
597 #define NODE_RECLAIM_FULL       -1
598 #define NODE_RECLAIM_SOME       0
599 #define NODE_RECLAIM_SUCCESS    1
600
601 #ifdef CONFIG_NUMA
602 extern int node_reclaim(struct pglist_data *, gfp_t, unsigned int);
603 extern int find_next_best_node(int node, nodemask_t *used_node_mask);
604 #else
605 static inline int node_reclaim(struct pglist_data *pgdat, gfp_t mask,
606                                 unsigned int order)
607 {
608         return NODE_RECLAIM_NOSCAN;
609 }
610 static inline int find_next_best_node(int node, nodemask_t *used_node_mask)
611 {
612         return NUMA_NO_NODE;
613 }
614 #endif
615
616 extern int hwpoison_filter(struct page *p);
617
618 extern u32 hwpoison_filter_dev_major;
619 extern u32 hwpoison_filter_dev_minor;
620 extern u64 hwpoison_filter_flags_mask;
621 extern u64 hwpoison_filter_flags_value;
622 extern u64 hwpoison_filter_memcg;
623 extern u32 hwpoison_filter_enable;
624
625 extern unsigned long  __must_check vm_mmap_pgoff(struct file *, unsigned long,
626         unsigned long, unsigned long,
627         unsigned long, unsigned long);
628
629 extern void set_pageblock_order(void);
630 unsigned int reclaim_clean_pages_from_list(struct zone *zone,
631                                             struct list_head *page_list);
632 /* The ALLOC_WMARK bits are used as an index to zone->watermark */
633 #define ALLOC_WMARK_MIN         WMARK_MIN
634 #define ALLOC_WMARK_LOW         WMARK_LOW
635 #define ALLOC_WMARK_HIGH        WMARK_HIGH
636 #define ALLOC_NO_WATERMARKS     0x04 /* don't check watermarks at all */
637
638 /* Mask to get the watermark bits */
639 #define ALLOC_WMARK_MASK        (ALLOC_NO_WATERMARKS-1)
640
641 /*
642  * Only MMU archs have async oom victim reclaim - aka oom_reaper so we
643  * cannot assume a reduced access to memory reserves is sufficient for
644  * !MMU
645  */
646 #ifdef CONFIG_MMU
647 #define ALLOC_OOM               0x08
648 #else
649 #define ALLOC_OOM               ALLOC_NO_WATERMARKS
650 #endif
651
652 #define ALLOC_HARDER             0x10 /* try to alloc harder */
653 #define ALLOC_HIGH               0x20 /* __GFP_HIGH set */
654 #define ALLOC_CPUSET             0x40 /* check for correct cpuset */
655 #define ALLOC_CMA                0x80 /* allow allocations from CMA areas */
656 #ifdef CONFIG_ZONE_DMA32
657 #define ALLOC_NOFRAGMENT        0x100 /* avoid mixing pageblock types */
658 #else
659 #define ALLOC_NOFRAGMENT          0x0
660 #endif
661 #define ALLOC_KSWAPD            0x800 /* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */
662
663 enum ttu_flags;
664 struct tlbflush_unmap_batch;
665
666
667 /*
668  * only for MM internal work items which do not depend on
669  * any allocations or locks which might depend on allocations
670  */
671 extern struct workqueue_struct *mm_percpu_wq;
672
673 #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
674 void try_to_unmap_flush(void);
675 void try_to_unmap_flush_dirty(void);
676 void flush_tlb_batched_pending(struct mm_struct *mm);
677 #else
678 static inline void try_to_unmap_flush(void)
679 {
680 }
681 static inline void try_to_unmap_flush_dirty(void)
682 {
683 }
684 static inline void flush_tlb_batched_pending(struct mm_struct *mm)
685 {
686 }
687 #endif /* CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH */
688
689 extern const struct trace_print_flags pageflag_names[];
690 extern const struct trace_print_flags vmaflag_names[];
691 extern const struct trace_print_flags gfpflag_names[];
692
693 static inline bool is_migrate_highatomic(enum migratetype migratetype)
694 {
695         return migratetype == MIGRATE_HIGHATOMIC;
696 }
697
698 static inline bool is_migrate_highatomic_page(struct page *page)
699 {
700         return get_pageblock_migratetype(page) == MIGRATE_HIGHATOMIC;
701 }
702
703 void setup_zone_pageset(struct zone *zone);
704
705 struct migration_target_control {
706         int nid;                /* preferred node id */
707         nodemask_t *nmask;
708         gfp_t gfp_mask;
709 };
710
711 /*
712  * mm/vmalloc.c
713  */
714 #ifdef CONFIG_MMU
715 int vmap_pages_range_noflush(unsigned long addr, unsigned long end,
716                 pgprot_t prot, struct page **pages, unsigned int page_shift);
717 #else
718 static inline
719 int vmap_pages_range_noflush(unsigned long addr, unsigned long end,
720                 pgprot_t prot, struct page **pages, unsigned int page_shift)
721 {
722         return -EINVAL;
723 }
724 #endif
725
726 void vunmap_range_noflush(unsigned long start, unsigned long end);
727
728 int numa_migrate_prep(struct page *page, struct vm_area_struct *vma,
729                       unsigned long addr, int page_nid, int *flags);
730
731 #endif  /* __MM_INTERNAL_H */