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 #include <linux/swap.h>
15 #include <linux/rmap.h>
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)
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 enum reclaim_invoker {
38 ALL,
39 KSWAPD,
40 ZSWAPD,
41 DIRECT_RECLAIM,
42 NODE_RECLAIM,
43 SOFT_LIMIT,
44 RCC_RECLAIM,
45 FILE_RECLAIM,
46 ANON_RECLAIM
47 };
48
49 struct scan_control {
50 /* How many pages shrink_list() should reclaim */
51 unsigned long nr_to_reclaim;
52
53 /*
54 * Nodemask of nodes allowed by the caller. If NULL, all nodes
55 * are scanned.
56 */
57 nodemask_t *nodemask;
58
59 /*
60 * The memory cgroup that hit its limit and as a result is the
61 * primary target of this reclaim invocation.
62 */
63 struct mem_cgroup *target_mem_cgroup;
64
65 /*
66 * Scan pressure balancing between anon and file LRUs
67 */
68 unsigned long anon_cost;
69 unsigned long file_cost;
70
71 /* Can active pages be deactivated as part of reclaim? */
72 #define DEACTIVATE_ANON 1
73 #define DEACTIVATE_FILE 2
74 unsigned int may_deactivate:2;
75 unsigned int force_deactivate:1;
76 unsigned int skipped_deactivate:1;
77
78 /* Writepage batching in laptop mode; RECLAIM_WRITE */
79 unsigned int may_writepage:1;
80
81 /* Can mapped pages be reclaimed? */
82 unsigned int may_unmap:1;
83
84 /* Can pages be swapped as part of reclaim? */
85 unsigned int may_swap:1;
86
87 /*
88 * Cgroups are not reclaimed below their configured memory.low,
89 * unless we threaten to OOM. If any cgroups are skipped due to
90 * memory.low and nothing was reclaimed, go back for memory.low.
91 */
92 unsigned int memcg_low_reclaim:1;
93 unsigned int memcg_low_skipped:1;
94
95 unsigned int hibernation_mode:1;
96
97 /* One of the zones is ready for compaction */
98 unsigned int compaction_ready:1;
99
100 /* There is easily reclaimable cold cache in the current node */
101 unsigned int cache_trim_mode:1;
102
103 /* The file pages on the current node are dangerously low */
104 unsigned int file_is_tiny:1;
105
106 /* Allocation order */
107 s8 order;
108
109 /* Scan (total_size >> priority) pages at once */
110 s8 priority;
111
112 /* The highest zone to isolate pages for reclaim from */
113 s8 reclaim_idx;
114
115 /* This context's GFP mask */
116 gfp_t gfp_mask;
117
118 /* Incremented by the number of inactive pages that were scanned */
119 unsigned long nr_scanned;
120
121 /* Number of pages freed so far during a call to shrink_zones() */
122 unsigned long nr_reclaimed;
123
124 struct {
125 unsigned int dirty;
126 unsigned int unqueued_dirty;
127 unsigned int congested;
128 unsigned int writeback;
129 unsigned int immediate;
130 unsigned int file_taken;
131 unsigned int taken;
132 } nr;
133
134 enum reclaim_invoker invoker;
135 u32 isolate_count;
136 unsigned long nr_scanned_anon;
137 unsigned long nr_scanned_file;
138 unsigned long nr_reclaimed_anon;
139 unsigned long nr_reclaimed_file;
140
141 /* for recording the reclaimed slab by now */
142 struct reclaim_state reclaim_state;
143 };
144
145 enum scan_balance {
146 SCAN_EQUAL,
147 SCAN_FRACT,
148 SCAN_ANON,
149 SCAN_FILE,
150 };
151
152 void page_writeback_init(void);
153
154 vm_fault_t do_swap_page(struct vm_fault *vmf);
155
156 void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
157 unsigned long floor, unsigned long ceiling);
158
can_madv_lru_vma(struct vm_area_struct * vma)159 static inline bool can_madv_lru_vma(struct vm_area_struct *vma)
160 {
161 return !(vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP));
162 }
163
164 void unmap_page_range(struct mmu_gather *tlb,
165 struct vm_area_struct *vma,
166 unsigned long addr, unsigned long end,
167 struct zap_details *details);
168
169 void do_page_cache_ra(struct readahead_control *, unsigned long nr_to_read,
170 unsigned long lookahead_size);
171 void force_page_cache_ra(struct readahead_control *, struct file_ra_state *,
172 unsigned long nr);
force_page_cache_readahead(struct address_space * mapping,struct file * file,pgoff_t index,unsigned long nr_to_read)173 static inline void force_page_cache_readahead(struct address_space *mapping,
174 struct file *file, pgoff_t index, unsigned long nr_to_read)
175 {
176 DEFINE_READAHEAD(ractl, file, mapping, index);
177 force_page_cache_ra(&ractl, &file->f_ra, nr_to_read);
178 }
179
180 struct page *find_get_entry(struct address_space *mapping, pgoff_t index);
181 struct page *find_lock_entry(struct address_space *mapping, pgoff_t index);
182
183 /**
184 * page_evictable - test whether a page is evictable
185 * @page: the page to test
186 *
187 * Test whether page is evictable--i.e., should be placed on active/inactive
188 * lists vs unevictable list.
189 *
190 * Reasons page might not be evictable:
191 * (1) page's mapping marked unevictable
192 * (2) page is part of an mlocked VMA
193 *
194 */
page_evictable(struct page * page)195 static inline bool page_evictable(struct page *page)
196 {
197 bool ret;
198
199 /* Prevent address_space of inode and swap cache from being freed */
200 rcu_read_lock();
201 ret = !mapping_unevictable(page_mapping(page)) && !PageMlocked(page);
202 rcu_read_unlock();
203 return ret;
204 }
205
206 /*
207 * Turn a non-refcounted page (->_refcount == 0) into refcounted with
208 * a count of one.
209 */
set_page_refcounted(struct page * page)210 static inline void set_page_refcounted(struct page *page)
211 {
212 VM_BUG_ON_PAGE(PageTail(page), page);
213 VM_BUG_ON_PAGE(page_ref_count(page), page);
214 set_page_count(page, 1);
215 }
216
217 extern unsigned long highest_memmap_pfn;
218
219 /*
220 * Maximum number of reclaim retries without progress before the OOM
221 * killer is consider the only way forward.
222 */
223 #define MAX_RECLAIM_RETRIES 16
224
225 /*
226 * in mm/vmscan.c:
227 */
228 extern int isolate_lru_page(struct page *page);
229 extern void putback_lru_page(struct page *page);
230 extern unsigned int shrink_page_list(struct list_head *page_list, struct pglist_data *pgdat,
231 struct scan_control *sc, struct reclaim_stat *stat, bool ignore_references);
232 extern unsigned long isolate_lru_pages(unsigned long nr_to_scan, struct lruvec *lruvec,
233 struct list_head *dst, unsigned long *nr_scanned, struct scan_control *sc,
234 enum lru_list lru);
235 extern unsigned move_pages_to_lru(struct lruvec *lruvec, struct list_head *list);
236 extern void shrink_active_list(unsigned long nr_to_scan, struct lruvec *lruvec,
237 struct scan_control *sc, enum lru_list lru);
238 extern unsigned long shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
239 struct scan_control *sc, enum lru_list lru);
240 extern void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc);
241
242 /*
243 * in mm/rmap.c:
244 */
245 extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
246
247 /*
248 * in mm/page_alloc.c
249 */
250
251 /*
252 * Structure for holding the mostly immutable allocation parameters passed
253 * between functions involved in allocations, including the alloc_pages*
254 * family of functions.
255 *
256 * nodemask, migratetype and highest_zoneidx are initialized only once in
257 * __alloc_pages_nodemask() and then never change.
258 *
259 * zonelist, preferred_zone and highest_zoneidx are set first in
260 * __alloc_pages_nodemask() for the fast path, and might be later changed
261 * in __alloc_pages_slowpath(). All other functions pass the whole structure
262 * by a const pointer.
263 */
264 struct alloc_context {
265 struct zonelist *zonelist;
266 nodemask_t *nodemask;
267 struct zoneref *preferred_zoneref;
268 int migratetype;
269
270 /*
271 * highest_zoneidx represents highest usable zone index of
272 * the allocation request. Due to the nature of the zone,
273 * memory on lower zone than the highest_zoneidx will be
274 * protected by lowmem_reserve[highest_zoneidx].
275 *
276 * highest_zoneidx is also used by reclaim/compaction to limit
277 * the target zone since higher zone than this index cannot be
278 * usable for this allocation request.
279 */
280 enum zone_type highest_zoneidx;
281 bool spread_dirty_pages;
282 };
283
284 /*
285 * Locate the struct page for both the matching buddy in our
286 * pair (buddy1) and the combined O(n+1) page they form (page).
287 *
288 * 1) Any buddy B1 will have an order O twin B2 which satisfies
289 * the following equation:
290 * B2 = B1 ^ (1 << O)
291 * For example, if the starting buddy (buddy2) is #8 its order
292 * 1 buddy is #10:
293 * B2 = 8 ^ (1 << 1) = 8 ^ 2 = 10
294 *
295 * 2) Any buddy B will have an order O+1 parent P which
296 * satisfies the following equation:
297 * P = B & ~(1 << O)
298 *
299 * Assumption: *_mem_map is contiguous at least up to MAX_ORDER
300 */
301 static inline unsigned long
__find_buddy_pfn(unsigned long page_pfn,unsigned int order)302 __find_buddy_pfn(unsigned long page_pfn, unsigned int order)
303 {
304 return page_pfn ^ (1 << order);
305 }
306
307 extern struct page *__pageblock_pfn_to_page(unsigned long start_pfn,
308 unsigned long end_pfn, struct zone *zone);
309
pageblock_pfn_to_page(unsigned long start_pfn,unsigned long end_pfn,struct zone * zone)310 static inline struct page *pageblock_pfn_to_page(unsigned long start_pfn,
311 unsigned long end_pfn, struct zone *zone)
312 {
313 if (zone->contiguous)
314 return pfn_to_page(start_pfn);
315
316 return __pageblock_pfn_to_page(start_pfn, end_pfn, zone);
317 }
318
319 extern int __isolate_free_page(struct page *page, unsigned int order);
320 extern void __putback_isolated_page(struct page *page, unsigned int order,
321 int mt);
322 extern void memblock_free_pages(struct page *page, unsigned long pfn,
323 unsigned int order);
324 extern void __free_pages_core(struct page *page, unsigned int order);
325 extern void prep_compound_page(struct page *page, unsigned int order);
326 extern void post_alloc_hook(struct page *page, unsigned int order,
327 gfp_t gfp_flags);
328 extern int user_min_free_kbytes;
329
330 extern void zone_pcp_update(struct zone *zone);
331 extern void zone_pcp_reset(struct zone *zone);
332
333 #if defined CONFIG_COMPACTION || defined CONFIG_CMA
334
335 /*
336 * in mm/compaction.c
337 */
338 /*
339 * compact_control is used to track pages being migrated and the free pages
340 * they are being migrated to during memory compaction. The free_pfn starts
341 * at the end of a zone and migrate_pfn begins at the start. Movable pages
342 * are moved to the end of a zone during a compaction run and the run
343 * completes when free_pfn <= migrate_pfn
344 */
345 struct compact_control {
346 struct list_head freepages; /* List of free pages to migrate to */
347 struct list_head migratepages; /* List of pages being migrated */
348 unsigned int nr_freepages; /* Number of isolated free pages */
349 unsigned int nr_migratepages; /* Number of pages to migrate */
350 unsigned long free_pfn; /* isolate_freepages search base */
351 unsigned long migrate_pfn; /* isolate_migratepages search base */
352 unsigned long fast_start_pfn; /* a pfn to start linear scan from */
353 struct zone *zone;
354 unsigned long total_migrate_scanned;
355 unsigned long total_free_scanned;
356 unsigned short fast_search_fail;/* failures to use free list searches */
357 short search_order; /* order to start a fast search at */
358 const gfp_t gfp_mask; /* gfp mask of a direct compactor */
359 int order; /* order a direct compactor needs */
360 int migratetype; /* migratetype of direct compactor */
361 const unsigned int alloc_flags; /* alloc flags of a direct compactor */
362 const int highest_zoneidx; /* zone index of a direct compactor */
363 enum migrate_mode mode; /* Async or sync migration mode */
364 bool ignore_skip_hint; /* Scan blocks even if marked skip */
365 bool no_set_skip_hint; /* Don't mark blocks for skipping */
366 bool ignore_block_suitable; /* Scan blocks considered unsuitable */
367 bool direct_compaction; /* False from kcompactd or /proc/... */
368 bool proactive_compaction; /* kcompactd proactive compaction */
369 bool whole_zone; /* Whole zone should/has been scanned */
370 bool contended; /* Signal lock or sched contention */
371 bool rescan; /* Rescanning the same pageblock */
372 bool alloc_contig; /* alloc_contig_range allocation */
373 };
374
375 /*
376 * Used in direct compaction when a page should be taken from the freelists
377 * immediately when one is created during the free path.
378 */
379 struct capture_control {
380 struct compact_control *cc;
381 struct page *page;
382 };
383
384 unsigned long
385 isolate_freepages_range(struct compact_control *cc,
386 unsigned long start_pfn, unsigned long end_pfn);
387 unsigned long
388 isolate_migratepages_range(struct compact_control *cc,
389 unsigned long low_pfn, unsigned long end_pfn);
390 int find_suitable_fallback(struct free_area *area, unsigned int order,
391 int migratetype, bool only_stealable, bool *can_steal);
392
393 #endif
394
395 /*
396 * This function returns the order of a free page in the buddy system. In
397 * general, page_zone(page)->lock must be held by the caller to prevent the
398 * page from being allocated in parallel and returning garbage as the order.
399 * If a caller does not hold page_zone(page)->lock, it must guarantee that the
400 * page cannot be allocated or merged in parallel. Alternatively, it must
401 * handle invalid values gracefully, and use buddy_order_unsafe() below.
402 */
buddy_order(struct page * page)403 static inline unsigned int buddy_order(struct page *page)
404 {
405 /* PageBuddy() must be checked by the caller */
406 return page_private(page);
407 }
408
409 /*
410 * Like buddy_order(), but for callers who cannot afford to hold the zone lock.
411 * PageBuddy() should be checked first by the caller to minimize race window,
412 * and invalid values must be handled gracefully.
413 *
414 * READ_ONCE is used so that if the caller assigns the result into a local
415 * variable and e.g. tests it for valid range before using, the compiler cannot
416 * decide to remove the variable and inline the page_private(page) multiple
417 * times, potentially observing different values in the tests and the actual
418 * use of the result.
419 */
420 #define buddy_order_unsafe(page) READ_ONCE(page_private(page))
421
is_cow_mapping(vm_flags_t flags)422 static inline bool is_cow_mapping(vm_flags_t flags)
423 {
424 return (flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
425 }
426
427 /*
428 * These three helpers classifies VMAs for virtual memory accounting.
429 */
430
431 /*
432 * Executable code area - executable, not writable, not stack
433 */
is_exec_mapping(vm_flags_t flags)434 static inline bool is_exec_mapping(vm_flags_t flags)
435 {
436 return (flags & (VM_EXEC | VM_WRITE | VM_STACK)) == VM_EXEC;
437 }
438
439 /*
440 * Stack area - atomatically grows in one direction
441 *
442 * VM_GROWSUP / VM_GROWSDOWN VMAs are always private anonymous:
443 * do_mmap() forbids all other combinations.
444 */
is_stack_mapping(vm_flags_t flags)445 static inline bool is_stack_mapping(vm_flags_t flags)
446 {
447 return (flags & VM_STACK) == VM_STACK;
448 }
449
450 /*
451 * Data area - private, writable, not stack
452 */
is_data_mapping(vm_flags_t flags)453 static inline bool is_data_mapping(vm_flags_t flags)
454 {
455 return (flags & (VM_WRITE | VM_SHARED | VM_STACK)) == VM_WRITE;
456 }
457
458 /* mm/util.c */
459 void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
460 struct vm_area_struct *prev);
461 void __vma_unlink_list(struct mm_struct *mm, struct vm_area_struct *vma);
462
463 #ifdef CONFIG_MMU
464 extern long populate_vma_page_range(struct vm_area_struct *vma,
465 unsigned long start, unsigned long end, int *nonblocking);
466 extern void munlock_vma_pages_range(struct vm_area_struct *vma,
467 unsigned long start, unsigned long end);
munlock_vma_pages_all(struct vm_area_struct * vma)468 static inline void munlock_vma_pages_all(struct vm_area_struct *vma)
469 {
470 munlock_vma_pages_range(vma, vma->vm_start, vma->vm_end);
471 }
472
473 /*
474 * must be called with vma's mmap_lock held for read or write, and page locked.
475 */
476 extern void mlock_vma_page(struct page *page);
477 extern unsigned int munlock_vma_page(struct page *page);
478
479 /*
480 * Clear the page's PageMlocked(). This can be useful in a situation where
481 * we want to unconditionally remove a page from the pagecache -- e.g.,
482 * on truncation or freeing.
483 *
484 * It is legal to call this function for any page, mlocked or not.
485 * If called for a page that is still mapped by mlocked vmas, all we do
486 * is revert to lazy LRU behaviour -- semantics are not broken.
487 */
488 extern void clear_page_mlock(struct page *page);
489
490 /*
491 * mlock_migrate_page - called only from migrate_misplaced_transhuge_page()
492 * (because that does not go through the full procedure of migration ptes):
493 * to migrate the Mlocked page flag; update statistics.
494 */
mlock_migrate_page(struct page * newpage,struct page * page)495 static inline void mlock_migrate_page(struct page *newpage, struct page *page)
496 {
497 if (TestClearPageMlocked(page)) {
498 int nr_pages = thp_nr_pages(page);
499
500 /* Holding pmd lock, no change in irq context: __mod is safe */
501 __mod_zone_page_state(page_zone(page), NR_MLOCK, -nr_pages);
502 SetPageMlocked(newpage);
503 __mod_zone_page_state(page_zone(newpage), NR_MLOCK, nr_pages);
504 }
505 }
506
507 extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
508
509 /*
510 * At what user virtual address is page expected in vma?
511 * Returns -EFAULT if all of the page is outside the range of vma.
512 * If page is a compound head, the entire compound page is considered.
513 */
514 static inline unsigned long
vma_address(struct page * page,struct vm_area_struct * vma)515 vma_address(struct page *page, struct vm_area_struct *vma)
516 {
517 pgoff_t pgoff;
518 unsigned long address;
519
520 VM_BUG_ON_PAGE(PageKsm(page), page); /* KSM page->index unusable */
521 pgoff = page_to_pgoff(page);
522 if (pgoff >= vma->vm_pgoff) {
523 address = vma->vm_start +
524 ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
525 /* Check for address beyond vma (or wrapped through 0?) */
526 if (address < vma->vm_start || address >= vma->vm_end)
527 address = -EFAULT;
528 } else if (PageHead(page) &&
529 pgoff + compound_nr(page) - 1 >= vma->vm_pgoff) {
530 /* Test above avoids possibility of wrap to 0 on 32-bit */
531 address = vma->vm_start;
532 } else {
533 address = -EFAULT;
534 }
535 return address;
536 }
537
538 /*
539 * Then at what user virtual address will none of the page be found in vma?
540 * Assumes that vma_address() already returned a good starting address.
541 * If page is a compound head, the entire compound page is considered.
542 */
543 static inline unsigned long
vma_address_end(struct page * page,struct vm_area_struct * vma)544 vma_address_end(struct page *page, struct vm_area_struct *vma)
545 {
546 pgoff_t pgoff;
547 unsigned long address;
548
549 VM_BUG_ON_PAGE(PageKsm(page), page); /* KSM page->index unusable */
550 pgoff = page_to_pgoff(page) + compound_nr(page);
551 address = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
552 /* Check for address beyond vma (or wrapped through 0?) */
553 if (address < vma->vm_start || address > vma->vm_end)
554 address = vma->vm_end;
555 return address;
556 }
557
maybe_unlock_mmap_for_io(struct vm_fault * vmf,struct file * fpin)558 static inline struct file *maybe_unlock_mmap_for_io(struct vm_fault *vmf,
559 struct file *fpin)
560 {
561 int flags = vmf->flags;
562
563 if (fpin)
564 return fpin;
565
566 /*
567 * FAULT_FLAG_RETRY_NOWAIT means we don't want to wait on page locks or
568 * anything, so we only pin the file and drop the mmap_lock if only
569 * FAULT_FLAG_ALLOW_RETRY is set, while this is the first attempt.
570 */
571 if (fault_flag_allow_retry_first(flags) &&
572 !(flags & FAULT_FLAG_RETRY_NOWAIT)) {
573 fpin = get_file(vmf->vma->vm_file);
574 mmap_read_unlock(vmf->vma->vm_mm);
575 }
576 return fpin;
577 }
578
579 #else /* !CONFIG_MMU */
clear_page_mlock(struct page * page)580 static inline void clear_page_mlock(struct page *page) { }
mlock_vma_page(struct page * page)581 static inline void mlock_vma_page(struct page *page) { }
mlock_migrate_page(struct page * new,struct page * old)582 static inline void mlock_migrate_page(struct page *new, struct page *old) { }
583
584 #endif /* !CONFIG_MMU */
585
586 /*
587 * Return the mem_map entry representing the 'offset' subpage within
588 * the maximally aligned gigantic page 'base'. Handle any discontiguity
589 * in the mem_map at MAX_ORDER_NR_PAGES boundaries.
590 */
mem_map_offset(struct page * base,int offset)591 static inline struct page *mem_map_offset(struct page *base, int offset)
592 {
593 if (unlikely(offset >= MAX_ORDER_NR_PAGES))
594 return nth_page(base, offset);
595 return base + offset;
596 }
597
598 /*
599 * Iterator over all subpages within the maximally aligned gigantic
600 * page 'base'. Handle any discontiguity in the mem_map.
601 */
mem_map_next(struct page * iter,struct page * base,int offset)602 static inline struct page *mem_map_next(struct page *iter,
603 struct page *base, int offset)
604 {
605 if (unlikely((offset & (MAX_ORDER_NR_PAGES - 1)) == 0)) {
606 unsigned long pfn = page_to_pfn(base) + offset;
607 if (!pfn_valid(pfn))
608 return NULL;
609 return pfn_to_page(pfn);
610 }
611 return iter + 1;
612 }
613
614 /* Memory initialisation debug and verification */
615 enum mminit_level {
616 MMINIT_WARNING,
617 MMINIT_VERIFY,
618 MMINIT_TRACE
619 };
620
621 #ifdef CONFIG_DEBUG_MEMORY_INIT
622
623 extern int mminit_loglevel;
624
625 #define mminit_dprintk(level, prefix, fmt, arg...) \
626 do { \
627 if (level < mminit_loglevel) { \
628 if (level <= MMINIT_WARNING) \
629 pr_warn("mminit::" prefix " " fmt, ##arg); \
630 else \
631 printk(KERN_DEBUG "mminit::" prefix " " fmt, ##arg); \
632 } \
633 } while (0)
634
635 extern void mminit_verify_pageflags_layout(void);
636 extern void mminit_verify_zonelist(void);
637 #else
638
mminit_dprintk(enum mminit_level level,const char * prefix,const char * fmt,...)639 static inline void mminit_dprintk(enum mminit_level level,
640 const char *prefix, const char *fmt, ...)
641 {
642 }
643
mminit_verify_pageflags_layout(void)644 static inline void mminit_verify_pageflags_layout(void)
645 {
646 }
647
mminit_verify_zonelist(void)648 static inline void mminit_verify_zonelist(void)
649 {
650 }
651 #endif /* CONFIG_DEBUG_MEMORY_INIT */
652
653 /* mminit_validate_memmodel_limits is independent of CONFIG_DEBUG_MEMORY_INIT */
654 #if defined(CONFIG_SPARSEMEM)
655 extern void mminit_validate_memmodel_limits(unsigned long *start_pfn,
656 unsigned long *end_pfn);
657 #else
mminit_validate_memmodel_limits(unsigned long * start_pfn,unsigned long * end_pfn)658 static inline void mminit_validate_memmodel_limits(unsigned long *start_pfn,
659 unsigned long *end_pfn)
660 {
661 }
662 #endif /* CONFIG_SPARSEMEM */
663
664 #define NODE_RECLAIM_NOSCAN -2
665 #define NODE_RECLAIM_FULL -1
666 #define NODE_RECLAIM_SOME 0
667 #define NODE_RECLAIM_SUCCESS 1
668
669 #ifdef CONFIG_NUMA
670 extern int node_reclaim(struct pglist_data *, gfp_t, unsigned int);
671 #else
node_reclaim(struct pglist_data * pgdat,gfp_t mask,unsigned int order)672 static inline int node_reclaim(struct pglist_data *pgdat, gfp_t mask,
673 unsigned int order)
674 {
675 return NODE_RECLAIM_NOSCAN;
676 }
677 #endif
678
679 extern int hwpoison_filter(struct page *p);
680
681 extern u32 hwpoison_filter_dev_major;
682 extern u32 hwpoison_filter_dev_minor;
683 extern u64 hwpoison_filter_flags_mask;
684 extern u64 hwpoison_filter_flags_value;
685 extern u64 hwpoison_filter_memcg;
686 extern u32 hwpoison_filter_enable;
687
688 extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long,
689 unsigned long, unsigned long,
690 unsigned long, unsigned long);
691
692 extern void set_pageblock_order(void);
693 unsigned int reclaim_clean_pages_from_list(struct zone *zone,
694 struct list_head *page_list);
695 /* The ALLOC_WMARK bits are used as an index to zone->watermark */
696 #define ALLOC_WMARK_MIN WMARK_MIN
697 #define ALLOC_WMARK_LOW WMARK_LOW
698 #define ALLOC_WMARK_HIGH WMARK_HIGH
699 #define ALLOC_NO_WATERMARKS 0x04 /* don't check watermarks at all */
700
701 /* Mask to get the watermark bits */
702 #define ALLOC_WMARK_MASK (ALLOC_NO_WATERMARKS-1)
703
704 /*
705 * Only MMU archs have async oom victim reclaim - aka oom_reaper so we
706 * cannot assume a reduced access to memory reserves is sufficient for
707 * !MMU
708 */
709 #ifdef CONFIG_MMU
710 #define ALLOC_OOM 0x08
711 #else
712 #define ALLOC_OOM ALLOC_NO_WATERMARKS
713 #endif
714
715 #define ALLOC_HARDER 0x10 /* try to alloc harder */
716 #define ALLOC_HIGH 0x20 /* __GFP_HIGH set */
717 #define ALLOC_CPUSET 0x40 /* check for correct cpuset */
718 #define ALLOC_CMA 0x80 /* allow allocations from CMA areas */
719 #ifdef CONFIG_ZONE_DMA32
720 #define ALLOC_NOFRAGMENT 0x100 /* avoid mixing pageblock types */
721 #else
722 #define ALLOC_NOFRAGMENT 0x0
723 #endif
724 #define ALLOC_KSWAPD 0x800 /* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */
725
726 enum ttu_flags;
727 struct tlbflush_unmap_batch;
728
729
730 /*
731 * only for MM internal work items which do not depend on
732 * any allocations or locks which might depend on allocations
733 */
734 extern struct workqueue_struct *mm_percpu_wq;
735
736 #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
737 void try_to_unmap_flush(void);
738 void try_to_unmap_flush_dirty(void);
739 void flush_tlb_batched_pending(struct mm_struct *mm);
740 #else
try_to_unmap_flush(void)741 static inline void try_to_unmap_flush(void)
742 {
743 }
try_to_unmap_flush_dirty(void)744 static inline void try_to_unmap_flush_dirty(void)
745 {
746 }
flush_tlb_batched_pending(struct mm_struct * mm)747 static inline void flush_tlb_batched_pending(struct mm_struct *mm)
748 {
749 }
750 #endif /* CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH */
751
752 extern const struct trace_print_flags pageflag_names[];
753 extern const struct trace_print_flags vmaflag_names[];
754 extern const struct trace_print_flags gfpflag_names[];
755
is_migrate_highatomic(enum migratetype migratetype)756 static inline bool is_migrate_highatomic(enum migratetype migratetype)
757 {
758 return migratetype == MIGRATE_HIGHATOMIC;
759 }
760
is_migrate_highatomic_page(struct page * page)761 static inline bool is_migrate_highatomic_page(struct page *page)
762 {
763 return get_pageblock_migratetype(page) == MIGRATE_HIGHATOMIC;
764 }
765
766 void setup_zone_pageset(struct zone *zone);
767
768 struct migration_target_control {
769 int nid; /* preferred node id */
770 nodemask_t *nmask;
771 gfp_t gfp_mask;
772 };
773
774 #endif /* __MM_INTERNAL_H */
775