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