iomap: use mapping_seek_hole_data
[linux-block.git] / mm / internal.h
CommitLineData
2874c5fd 1/* SPDX-License-Identifier: GPL-2.0-or-later */
1da177e4
LT
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)
1da177e4 6 */
0f8053a5
NP
7#ifndef __MM_INTERNAL_H
8#define __MM_INTERNAL_H
9
29f175d1 10#include <linux/fs.h>
0f8053a5 11#include <linux/mm.h>
e9b61f19 12#include <linux/pagemap.h>
edf14cdb 13#include <linux/tracepoint-defs.h>
1da177e4 14
dd56b046
MG
15/*
16 * The set of flags that only affect watermark checking and reclaim
17 * behaviour. This is used by the MM to obey the caller constraints
18 * about IO, FS and watermark checking while ignoring placement
19 * hints such as HIGHMEM usage.
20 */
21#define GFP_RECLAIM_MASK (__GFP_RECLAIM|__GFP_HIGH|__GFP_IO|__GFP_FS|\
dcda9b04 22 __GFP_NOWARN|__GFP_RETRY_MAYFAIL|__GFP_NOFAIL|\
e838a45f
MG
23 __GFP_NORETRY|__GFP_MEMALLOC|__GFP_NOMEMALLOC|\
24 __GFP_ATOMIC)
dd56b046
MG
25
26/* The GFP flags allowed during early boot */
27#define GFP_BOOT_MASK (__GFP_BITS_MASK & ~(__GFP_RECLAIM|__GFP_IO|__GFP_FS))
28
29/* Control allocation cpuset and node placement constraints */
30#define GFP_CONSTRAINT_MASK (__GFP_HARDWALL|__GFP_THISNODE)
31
32/* Do not use these with a slab allocator */
33#define GFP_SLAB_BUG_MASK (__GFP_DMA32|__GFP_HIGHMEM|~__GFP_BITS_MASK)
34
62906027
NP
35void page_writeback_init(void);
36
2b740303 37vm_fault_t do_swap_page(struct vm_fault *vmf);
8a966ed7 38
42b77728
JB
39void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
40 unsigned long floor, unsigned long ceiling);
41
9c276cc6 42static inline bool can_madv_lru_vma(struct vm_area_struct *vma)
23519073
KS
43{
44 return !(vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP));
45}
46
aac45363
MH
47void unmap_page_range(struct mmu_gather *tlb,
48 struct vm_area_struct *vma,
49 unsigned long addr, unsigned long end,
50 struct zap_details *details);
51
7b3df3b9
DH
52void do_page_cache_ra(struct readahead_control *, unsigned long nr_to_read,
53 unsigned long lookahead_size);
b1647dc0
DH
54void force_page_cache_ra(struct readahead_control *, struct file_ra_state *,
55 unsigned long nr);
7b3df3b9
DH
56static inline void force_page_cache_readahead(struct address_space *mapping,
57 struct file *file, pgoff_t index, unsigned long nr_to_read)
58{
59 DEFINE_READAHEAD(ractl, file, mapping, index);
b1647dc0 60 force_page_cache_ra(&ractl, &file->f_ra, nr_to_read);
7b3df3b9 61}
29f175d1 62
1eb6234e
YS
63/**
64 * page_evictable - test whether a page is evictable
65 * @page: the page to test
66 *
67 * Test whether page is evictable--i.e., should be placed on active/inactive
68 * lists vs unevictable list.
69 *
70 * Reasons page might not be evictable:
71 * (1) page's mapping marked unevictable
72 * (2) page is part of an mlocked VMA
73 *
74 */
75static inline bool page_evictable(struct page *page)
76{
77 bool ret;
78
79 /* Prevent address_space of inode and swap cache from being freed */
80 rcu_read_lock();
81 ret = !mapping_unevictable(page_mapping(page)) && !PageMlocked(page);
82 rcu_read_unlock();
83 return ret;
84}
85
7835e98b 86/*
0139aa7b 87 * Turn a non-refcounted page (->_refcount == 0) into refcounted with
7835e98b
NP
88 * a count of one.
89 */
90static inline void set_page_refcounted(struct page *page)
91{
309381fe 92 VM_BUG_ON_PAGE(PageTail(page), page);
fe896d18 93 VM_BUG_ON_PAGE(page_ref_count(page), page);
77a8a788 94 set_page_count(page, 1);
77a8a788
NP
95}
96
03f6462a
HD
97extern unsigned long highest_memmap_pfn;
98
c73322d0
JW
99/*
100 * Maximum number of reclaim retries without progress before the OOM
101 * killer is consider the only way forward.
102 */
103#define MAX_RECLAIM_RETRIES 16
104
894bc310
LS
105/*
106 * in mm/vmscan.c:
107 */
62695a84 108extern int isolate_lru_page(struct page *page);
894bc310 109extern void putback_lru_page(struct page *page);
62695a84 110
6219049a
BL
111/*
112 * in mm/rmap.c:
113 */
114extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
115
894bc310
LS
116/*
117 * in mm/page_alloc.c
118 */
3c605096 119
1a6d53a1
VB
120/*
121 * Structure for holding the mostly immutable allocation parameters passed
122 * between functions involved in allocations, including the alloc_pages*
123 * family of functions.
124 *
97a225e6 125 * nodemask, migratetype and highest_zoneidx are initialized only once in
1a6d53a1
VB
126 * __alloc_pages_nodemask() and then never change.
127 *
97a225e6 128 * zonelist, preferred_zone and highest_zoneidx are set first in
1a6d53a1 129 * __alloc_pages_nodemask() for the fast path, and might be later changed
68956ccb 130 * in __alloc_pages_slowpath(). All other functions pass the whole structure
1a6d53a1
VB
131 * by a const pointer.
132 */
133struct alloc_context {
134 struct zonelist *zonelist;
135 nodemask_t *nodemask;
c33d6c06 136 struct zoneref *preferred_zoneref;
1a6d53a1 137 int migratetype;
97a225e6
JK
138
139 /*
140 * highest_zoneidx represents highest usable zone index of
141 * the allocation request. Due to the nature of the zone,
142 * memory on lower zone than the highest_zoneidx will be
143 * protected by lowmem_reserve[highest_zoneidx].
144 *
145 * highest_zoneidx is also used by reclaim/compaction to limit
146 * the target zone since higher zone than this index cannot be
147 * usable for this allocation request.
148 */
149 enum zone_type highest_zoneidx;
c9ab0c4f 150 bool spread_dirty_pages;
1a6d53a1
VB
151};
152
3c605096
JK
153/*
154 * Locate the struct page for both the matching buddy in our
155 * pair (buddy1) and the combined O(n+1) page they form (page).
156 *
157 * 1) Any buddy B1 will have an order O twin B2 which satisfies
158 * the following equation:
159 * B2 = B1 ^ (1 << O)
160 * For example, if the starting buddy (buddy2) is #8 its order
161 * 1 buddy is #10:
162 * B2 = 8 ^ (1 << 1) = 8 ^ 2 = 10
163 *
164 * 2) Any buddy B will have an order O+1 parent P which
165 * satisfies the following equation:
166 * P = B & ~(1 << O)
167 *
168 * Assumption: *_mem_map is contiguous at least up to MAX_ORDER
169 */
170static inline unsigned long
76741e77 171__find_buddy_pfn(unsigned long page_pfn, unsigned int order)
3c605096 172{
76741e77 173 return page_pfn ^ (1 << order);
3c605096
JK
174}
175
7cf91a98
JK
176extern struct page *__pageblock_pfn_to_page(unsigned long start_pfn,
177 unsigned long end_pfn, struct zone *zone);
178
179static inline struct page *pageblock_pfn_to_page(unsigned long start_pfn,
180 unsigned long end_pfn, struct zone *zone)
181{
182 if (zone->contiguous)
183 return pfn_to_page(start_pfn);
184
185 return __pageblock_pfn_to_page(start_pfn, end_pfn, zone);
186}
187
3c605096 188extern int __isolate_free_page(struct page *page, unsigned int order);
624f58d8
AD
189extern void __putback_isolated_page(struct page *page, unsigned int order,
190 int mt);
7c2ee349 191extern void memblock_free_pages(struct page *page, unsigned long pfn,
d70ddd7a 192 unsigned int order);
a9cd410a 193extern void __free_pages_core(struct page *page, unsigned int order);
d00181b9 194extern void prep_compound_page(struct page *page, unsigned int order);
46f24fd8
JK
195extern void post_alloc_hook(struct page *page, unsigned int order,
196 gfp_t gfp_flags);
42aa83cb 197extern int user_min_free_kbytes;
20a0307c 198
0966aeb4
MWO
199extern void free_unref_page(struct page *page);
200extern void free_unref_page_list(struct list_head *list);
201
68265390
MG
202extern void zone_pcp_update(struct zone *zone);
203extern void zone_pcp_reset(struct zone *zone);
ec6e8c7e
VB
204extern void zone_pcp_disable(struct zone *zone);
205extern void zone_pcp_enable(struct zone *zone);
68265390 206
ff9543fd
MN
207#if defined CONFIG_COMPACTION || defined CONFIG_CMA
208
209/*
210 * in mm/compaction.c
211 */
212/*
213 * compact_control is used to track pages being migrated and the free pages
214 * they are being migrated to during memory compaction. The free_pfn starts
215 * at the end of a zone and migrate_pfn begins at the start. Movable pages
216 * are moved to the end of a zone during a compaction run and the run
217 * completes when free_pfn <= migrate_pfn
218 */
219struct compact_control {
220 struct list_head freepages; /* List of free pages to migrate to */
221 struct list_head migratepages; /* List of pages being migrated */
c5fbd937
MG
222 unsigned int nr_freepages; /* Number of isolated free pages */
223 unsigned int nr_migratepages; /* Number of pages to migrate */
ff9543fd
MN
224 unsigned long free_pfn; /* isolate_freepages search base */
225 unsigned long migrate_pfn; /* isolate_migratepages search base */
70b44595 226 unsigned long fast_start_pfn; /* a pfn to start linear scan from */
c5943b9c
MG
227 struct zone *zone;
228 unsigned long total_migrate_scanned;
229 unsigned long total_free_scanned;
dbe2d4e4
MG
230 unsigned short fast_search_fail;/* failures to use free list searches */
231 short search_order; /* order to start a fast search at */
f25ba6dc
VB
232 const gfp_t gfp_mask; /* gfp mask of a direct compactor */
233 int order; /* order a direct compactor needs */
d39773a0 234 int migratetype; /* migratetype of direct compactor */
f25ba6dc 235 const unsigned int alloc_flags; /* alloc flags of a direct compactor */
97a225e6 236 const int highest_zoneidx; /* zone index of a direct compactor */
e0b9daeb 237 enum migrate_mode mode; /* Async or sync migration mode */
bb13ffeb 238 bool ignore_skip_hint; /* Scan blocks even if marked skip */
2583d671 239 bool no_set_skip_hint; /* Don't mark blocks for skipping */
9f7e3387 240 bool ignore_block_suitable; /* Scan blocks considered unsuitable */
accf6242 241 bool direct_compaction; /* False from kcompactd or /proc/... */
facdaa91 242 bool proactive_compaction; /* kcompactd proactive compaction */
06ed2998 243 bool whole_zone; /* Whole zone should/has been scanned */
c3486f53 244 bool contended; /* Signal lock or sched contention */
804d3121 245 bool rescan; /* Rescanning the same pageblock */
b06eda09 246 bool alloc_contig; /* alloc_contig_range allocation */
ff9543fd
MN
247};
248
5e1f0f09
MG
249/*
250 * Used in direct compaction when a page should be taken from the freelists
251 * immediately when one is created during the free path.
252 */
253struct capture_control {
254 struct compact_control *cc;
255 struct page *page;
256};
257
ff9543fd 258unsigned long
bb13ffeb
MG
259isolate_freepages_range(struct compact_control *cc,
260 unsigned long start_pfn, unsigned long end_pfn);
ff9543fd 261unsigned long
edc2ca61
VB
262isolate_migratepages_range(struct compact_control *cc,
263 unsigned long low_pfn, unsigned long end_pfn);
2149cdae
JK
264int find_suitable_fallback(struct free_area *area, unsigned int order,
265 int migratetype, bool only_stealable, bool *can_steal);
ff9543fd
MN
266
267#endif
0f8053a5 268
48f13bf3 269/*
6c14466c
MG
270 * This function returns the order of a free page in the buddy system. In
271 * general, page_zone(page)->lock must be held by the caller to prevent the
272 * page from being allocated in parallel and returning garbage as the order.
273 * If a caller does not hold page_zone(page)->lock, it must guarantee that the
99c0fd5e 274 * page cannot be allocated or merged in parallel. Alternatively, it must
ab130f91 275 * handle invalid values gracefully, and use buddy_order_unsafe() below.
48f13bf3 276 */
ab130f91 277static inline unsigned int buddy_order(struct page *page)
48f13bf3 278{
572438f9 279 /* PageBuddy() must be checked by the caller */
48f13bf3
MG
280 return page_private(page);
281}
b5a0e011 282
99c0fd5e 283/*
ab130f91 284 * Like buddy_order(), but for callers who cannot afford to hold the zone lock.
99c0fd5e
VB
285 * PageBuddy() should be checked first by the caller to minimize race window,
286 * and invalid values must be handled gracefully.
287 *
4db0c3c2 288 * READ_ONCE is used so that if the caller assigns the result into a local
99c0fd5e
VB
289 * variable and e.g. tests it for valid range before using, the compiler cannot
290 * decide to remove the variable and inline the page_private(page) multiple
291 * times, potentially observing different values in the tests and the actual
292 * use of the result.
293 */
ab130f91 294#define buddy_order_unsafe(page) READ_ONCE(page_private(page))
99c0fd5e 295
4bbd4c77
KS
296static inline bool is_cow_mapping(vm_flags_t flags)
297{
298 return (flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
299}
300
30bdbb78
KK
301/*
302 * These three helpers classifies VMAs for virtual memory accounting.
303 */
304
305/*
306 * Executable code area - executable, not writable, not stack
307 */
d977d56c
KK
308static inline bool is_exec_mapping(vm_flags_t flags)
309{
30bdbb78 310 return (flags & (VM_EXEC | VM_WRITE | VM_STACK)) == VM_EXEC;
d977d56c
KK
311}
312
30bdbb78
KK
313/*
314 * Stack area - atomatically grows in one direction
315 *
316 * VM_GROWSUP / VM_GROWSDOWN VMAs are always private anonymous:
317 * do_mmap() forbids all other combinations.
318 */
d977d56c
KK
319static inline bool is_stack_mapping(vm_flags_t flags)
320{
30bdbb78 321 return (flags & VM_STACK) == VM_STACK;
d977d56c
KK
322}
323
30bdbb78
KK
324/*
325 * Data area - private, writable, not stack
326 */
d977d56c
KK
327static inline bool is_data_mapping(vm_flags_t flags)
328{
30bdbb78 329 return (flags & (VM_WRITE | VM_SHARED | VM_STACK)) == VM_WRITE;
d977d56c
KK
330}
331
6038def0
NK
332/* mm/util.c */
333void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
aba6dfb7 334 struct vm_area_struct *prev);
1b9fc5b2 335void __vma_unlink_list(struct mm_struct *mm, struct vm_area_struct *vma);
6038def0 336
af8e3354 337#ifdef CONFIG_MMU
fc05f566 338extern long populate_vma_page_range(struct vm_area_struct *vma,
cea10a19 339 unsigned long start, unsigned long end, int *nonblocking);
af8e3354
HD
340extern void munlock_vma_pages_range(struct vm_area_struct *vma,
341 unsigned long start, unsigned long end);
342static inline void munlock_vma_pages_all(struct vm_area_struct *vma)
343{
344 munlock_vma_pages_range(vma, vma->vm_start, vma->vm_end);
345}
346
b291f000 347/*
c1e8d7c6 348 * must be called with vma's mmap_lock held for read or write, and page locked.
b291f000
NP
349 */
350extern void mlock_vma_page(struct page *page);
ff6a6da6 351extern unsigned int munlock_vma_page(struct page *page);
b291f000
NP
352
353/*
354 * Clear the page's PageMlocked(). This can be useful in a situation where
355 * we want to unconditionally remove a page from the pagecache -- e.g.,
356 * on truncation or freeing.
357 *
358 * It is legal to call this function for any page, mlocked or not.
359 * If called for a page that is still mapped by mlocked vmas, all we do
360 * is revert to lazy LRU behaviour -- semantics are not broken.
361 */
e6c509f8 362extern void clear_page_mlock(struct page *page);
b291f000
NP
363
364/*
51afb12b
HD
365 * mlock_migrate_page - called only from migrate_misplaced_transhuge_page()
366 * (because that does not go through the full procedure of migration ptes):
367 * to migrate the Mlocked page flag; update statistics.
b291f000
NP
368 */
369static inline void mlock_migrate_page(struct page *newpage, struct page *page)
370{
5344b7e6 371 if (TestClearPageMlocked(page)) {
6c357848 372 int nr_pages = thp_nr_pages(page);
5344b7e6 373
51afb12b 374 /* Holding pmd lock, no change in irq context: __mod is safe */
b32967ff 375 __mod_zone_page_state(page_zone(page), NR_MLOCK, -nr_pages);
b291f000 376 SetPageMlocked(newpage);
b32967ff 377 __mod_zone_page_state(page_zone(newpage), NR_MLOCK, nr_pages);
5344b7e6 378 }
b291f000
NP
379}
380
f55e1014 381extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
b32967ff 382
e9b61f19
KS
383/*
384 * At what user virtual address is page expected in @vma?
385 */
386static inline unsigned long
387__vma_address(struct page *page, struct vm_area_struct *vma)
388{
389 pgoff_t pgoff = page_to_pgoff(page);
390 return vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
391}
392
393static inline unsigned long
394vma_address(struct page *page, struct vm_area_struct *vma)
395{
a8fa41ad
KS
396 unsigned long start, end;
397
398 start = __vma_address(page, vma);
af3bbc12 399 end = start + thp_size(page) - PAGE_SIZE;
e9b61f19
KS
400
401 /* page should be within @vma mapping range */
a8fa41ad 402 VM_BUG_ON_VMA(end < vma->vm_start || start >= vma->vm_end, vma);
e9b61f19 403
a8fa41ad 404 return max(start, vma->vm_start);
e9b61f19
KS
405}
406
89b15332
JW
407static inline struct file *maybe_unlock_mmap_for_io(struct vm_fault *vmf,
408 struct file *fpin)
409{
410 int flags = vmf->flags;
411
412 if (fpin)
413 return fpin;
414
415 /*
416 * FAULT_FLAG_RETRY_NOWAIT means we don't want to wait on page locks or
c1e8d7c6 417 * anything, so we only pin the file and drop the mmap_lock if only
4064b982 418 * FAULT_FLAG_ALLOW_RETRY is set, while this is the first attempt.
89b15332 419 */
4064b982
PX
420 if (fault_flag_allow_retry_first(flags) &&
421 !(flags & FAULT_FLAG_RETRY_NOWAIT)) {
89b15332 422 fpin = get_file(vmf->vma->vm_file);
d8ed45c5 423 mmap_read_unlock(vmf->vma->vm_mm);
89b15332
JW
424 }
425 return fpin;
426}
427
af8e3354 428#else /* !CONFIG_MMU */
b291f000
NP
429static inline void clear_page_mlock(struct page *page) { }
430static inline void mlock_vma_page(struct page *page) { }
431static inline void mlock_migrate_page(struct page *new, struct page *old) { }
432
af8e3354 433#endif /* !CONFIG_MMU */
894bc310 434
69d177c2
AW
435/*
436 * Return the mem_map entry representing the 'offset' subpage within
437 * the maximally aligned gigantic page 'base'. Handle any discontiguity
438 * in the mem_map at MAX_ORDER_NR_PAGES boundaries.
439 */
440static inline struct page *mem_map_offset(struct page *base, int offset)
441{
442 if (unlikely(offset >= MAX_ORDER_NR_PAGES))
bc7f84c0 443 return nth_page(base, offset);
69d177c2
AW
444 return base + offset;
445}
446
447/*
25985edc 448 * Iterator over all subpages within the maximally aligned gigantic
69d177c2
AW
449 * page 'base'. Handle any discontiguity in the mem_map.
450 */
451static inline struct page *mem_map_next(struct page *iter,
452 struct page *base, int offset)
453{
454 if (unlikely((offset & (MAX_ORDER_NR_PAGES - 1)) == 0)) {
455 unsigned long pfn = page_to_pfn(base) + offset;
456 if (!pfn_valid(pfn))
457 return NULL;
458 return pfn_to_page(pfn);
459 }
460 return iter + 1;
461}
462
6b74ab97
MG
463/* Memory initialisation debug and verification */
464enum mminit_level {
465 MMINIT_WARNING,
466 MMINIT_VERIFY,
467 MMINIT_TRACE
468};
469
470#ifdef CONFIG_DEBUG_MEMORY_INIT
471
472extern int mminit_loglevel;
473
474#define mminit_dprintk(level, prefix, fmt, arg...) \
475do { \
476 if (level < mminit_loglevel) { \
fc5199d1 477 if (level <= MMINIT_WARNING) \
1170532b 478 pr_warn("mminit::" prefix " " fmt, ##arg); \
fc5199d1
RV
479 else \
480 printk(KERN_DEBUG "mminit::" prefix " " fmt, ##arg); \
6b74ab97
MG
481 } \
482} while (0)
483
708614e6 484extern void mminit_verify_pageflags_layout(void);
68ad8df4 485extern void mminit_verify_zonelist(void);
6b74ab97
MG
486#else
487
488static inline void mminit_dprintk(enum mminit_level level,
489 const char *prefix, const char *fmt, ...)
490{
491}
492
708614e6
MG
493static inline void mminit_verify_pageflags_layout(void)
494{
495}
496
68ad8df4
MG
497static inline void mminit_verify_zonelist(void)
498{
499}
6b74ab97 500#endif /* CONFIG_DEBUG_MEMORY_INIT */
2dbb51c4
MG
501
502/* mminit_validate_memmodel_limits is independent of CONFIG_DEBUG_MEMORY_INIT */
503#if defined(CONFIG_SPARSEMEM)
504extern void mminit_validate_memmodel_limits(unsigned long *start_pfn,
505 unsigned long *end_pfn);
506#else
507static inline void mminit_validate_memmodel_limits(unsigned long *start_pfn,
508 unsigned long *end_pfn)
509{
510}
511#endif /* CONFIG_SPARSEMEM */
512
a5f5f91d
MG
513#define NODE_RECLAIM_NOSCAN -2
514#define NODE_RECLAIM_FULL -1
515#define NODE_RECLAIM_SOME 0
516#define NODE_RECLAIM_SUCCESS 1
7c116f2b 517
8b09549c
WY
518#ifdef CONFIG_NUMA
519extern int node_reclaim(struct pglist_data *, gfp_t, unsigned int);
520#else
521static inline int node_reclaim(struct pglist_data *pgdat, gfp_t mask,
522 unsigned int order)
523{
524 return NODE_RECLAIM_NOSCAN;
525}
526#endif
527
31d3d348
WF
528extern int hwpoison_filter(struct page *p);
529
7c116f2b
WF
530extern u32 hwpoison_filter_dev_major;
531extern u32 hwpoison_filter_dev_minor;
478c5ffc
WF
532extern u64 hwpoison_filter_flags_mask;
533extern u64 hwpoison_filter_flags_value;
4fd466eb 534extern u64 hwpoison_filter_memcg;
1bfe5feb 535extern u32 hwpoison_filter_enable;
eb36c587 536
dc0ef0df 537extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long,
eb36c587 538 unsigned long, unsigned long,
9fbeb5ab 539 unsigned long, unsigned long);
ca57df79
XQ
540
541extern void set_pageblock_order(void);
730ec8c0 542unsigned int reclaim_clean_pages_from_list(struct zone *zone,
02c6de8d 543 struct list_head *page_list);
d95ea5d1
BZ
544/* The ALLOC_WMARK bits are used as an index to zone->watermark */
545#define ALLOC_WMARK_MIN WMARK_MIN
546#define ALLOC_WMARK_LOW WMARK_LOW
547#define ALLOC_WMARK_HIGH WMARK_HIGH
548#define ALLOC_NO_WATERMARKS 0x04 /* don't check watermarks at all */
549
550/* Mask to get the watermark bits */
551#define ALLOC_WMARK_MASK (ALLOC_NO_WATERMARKS-1)
552
cd04ae1e
MH
553/*
554 * Only MMU archs have async oom victim reclaim - aka oom_reaper so we
555 * cannot assume a reduced access to memory reserves is sufficient for
556 * !MMU
557 */
558#ifdef CONFIG_MMU
559#define ALLOC_OOM 0x08
560#else
561#define ALLOC_OOM ALLOC_NO_WATERMARKS
562#endif
563
6bb15450
MG
564#define ALLOC_HARDER 0x10 /* try to alloc harder */
565#define ALLOC_HIGH 0x20 /* __GFP_HIGH set */
566#define ALLOC_CPUSET 0x40 /* check for correct cpuset */
567#define ALLOC_CMA 0x80 /* allow allocations from CMA areas */
568#ifdef CONFIG_ZONE_DMA32
569#define ALLOC_NOFRAGMENT 0x100 /* avoid mixing pageblock types */
570#else
571#define ALLOC_NOFRAGMENT 0x0
572#endif
736838e9 573#define ALLOC_KSWAPD 0x800 /* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */
d95ea5d1 574
72b252ae
MG
575enum ttu_flags;
576struct tlbflush_unmap_batch;
577
ce612879
MH
578
579/*
580 * only for MM internal work items which do not depend on
581 * any allocations or locks which might depend on allocations
582 */
583extern struct workqueue_struct *mm_percpu_wq;
584
72b252ae
MG
585#ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
586void try_to_unmap_flush(void);
d950c947 587void try_to_unmap_flush_dirty(void);
3ea27719 588void flush_tlb_batched_pending(struct mm_struct *mm);
72b252ae
MG
589#else
590static inline void try_to_unmap_flush(void)
591{
592}
d950c947
MG
593static inline void try_to_unmap_flush_dirty(void)
594{
595}
3ea27719
MG
596static inline void flush_tlb_batched_pending(struct mm_struct *mm)
597{
598}
72b252ae 599#endif /* CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH */
edf14cdb
VB
600
601extern const struct trace_print_flags pageflag_names[];
602extern const struct trace_print_flags vmaflag_names[];
603extern const struct trace_print_flags gfpflag_names[];
604
a6ffdc07
XQ
605static inline bool is_migrate_highatomic(enum migratetype migratetype)
606{
607 return migratetype == MIGRATE_HIGHATOMIC;
608}
609
610static inline bool is_migrate_highatomic_page(struct page *page)
611{
612 return get_pageblock_migratetype(page) == MIGRATE_HIGHATOMIC;
613}
614
72675e13 615void setup_zone_pageset(struct zone *zone);
19fc7bed
JK
616
617struct migration_target_control {
618 int nid; /* preferred node id */
619 nodemask_t *nmask;
620 gfp_t gfp_mask;
621};
622
db971418 623#endif /* __MM_INTERNAL_H */