1 /* internal.h: mm/ internal definitions
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 #ifndef __MM_INTERNAL_H
12 #define __MM_INTERNAL_H
17 void free_pgtables(struct mmu_gather
*tlb
, struct vm_area_struct
*start_vma
,
18 unsigned long floor
, unsigned long ceiling
);
20 static inline void set_page_count(struct page
*page
, int v
)
22 atomic_set(&page
->_count
, v
);
25 extern int __do_page_cache_readahead(struct address_space
*mapping
,
26 struct file
*filp
, pgoff_t offset
, unsigned long nr_to_read
,
27 unsigned long lookahead_size
);
30 * Submit IO for the read-ahead request in file_ra_state.
32 static inline unsigned long ra_submit(struct file_ra_state
*ra
,
33 struct address_space
*mapping
, struct file
*filp
)
35 return __do_page_cache_readahead(mapping
, filp
,
36 ra
->start
, ra
->size
, ra
->async_size
);
40 * Turn a non-refcounted page (->_count == 0) into refcounted with
43 static inline void set_page_refcounted(struct page
*page
)
45 VM_BUG_ON(PageTail(page
));
46 VM_BUG_ON(atomic_read(&page
->_count
));
47 set_page_count(page
, 1);
50 static inline void __get_page_tail_foll(struct page
*page
,
54 * If we're getting a tail page, the elevated page->_count is
55 * required only in the head page and we will elevate the head
56 * page->_count and tail page->_mapcount.
58 * We elevate page_tail->_mapcount for tail pages to force
59 * page_tail->_count to be zero at all times to avoid getting
60 * false positives from get_page_unless_zero() with
61 * speculative page access (like in
62 * page_cache_get_speculative()) on tail pages.
64 VM_BUG_ON(atomic_read(&page
->first_page
->_count
) <= 0);
65 VM_BUG_ON(atomic_read(&page
->_count
) != 0);
66 VM_BUG_ON(page_mapcount(page
) < 0);
68 atomic_inc(&page
->first_page
->_count
);
69 atomic_inc(&page
->_mapcount
);
73 * This is meant to be called as the FOLL_GET operation of
74 * follow_page() and it must be called while holding the proper PT
75 * lock while the pte (or pmd_trans_huge) is still mapping the page.
77 static inline void get_page_foll(struct page
*page
)
79 if (unlikely(PageTail(page
)))
81 * This is safe only because
82 * __split_huge_page_refcount() can't run under
83 * get_page_foll() because we hold the proper PT lock.
85 __get_page_tail_foll(page
, true);
88 * Getting a normal page or the head of a compound page
89 * requires to already have an elevated page->_count.
91 VM_BUG_ON(atomic_read(&page
->_count
) <= 0);
92 atomic_inc(&page
->_count
);
96 extern unsigned long highest_memmap_pfn
;
101 extern int isolate_lru_page(struct page
*page
);
102 extern void putback_lru_page(struct page
*page
);
103 extern bool zone_reclaimable(struct zone
*zone
);
108 extern pmd_t
*mm_find_pmd(struct mm_struct
*mm
, unsigned long address
);
113 extern void __free_pages_bootmem(struct page
*page
, unsigned int order
);
114 extern void prep_compound_page(struct page
*page
, unsigned long order
);
115 #ifdef CONFIG_MEMORY_FAILURE
116 extern bool is_free_buddy_page(struct page
*page
);
119 #if defined CONFIG_COMPACTION || defined CONFIG_CMA
125 * compact_control is used to track pages being migrated and the free pages
126 * they are being migrated to during memory compaction. The free_pfn starts
127 * at the end of a zone and migrate_pfn begins at the start. Movable pages
128 * are moved to the end of a zone during a compaction run and the run
129 * completes when free_pfn <= migrate_pfn
131 struct compact_control
{
132 struct list_head freepages
; /* List of free pages to migrate to */
133 struct list_head migratepages
; /* List of pages being migrated */
134 unsigned long nr_freepages
; /* Number of isolated free pages */
135 unsigned long nr_migratepages
; /* Number of pages to migrate */
136 unsigned long free_pfn
; /* isolate_freepages search base */
137 unsigned long migrate_pfn
; /* isolate_migratepages search base */
138 enum migrate_mode mode
; /* Async or sync migration mode */
139 bool ignore_skip_hint
; /* Scan blocks even if marked skip */
140 bool finished_update_free
; /* True when the zone cached pfns are
141 * no longer being updated
143 bool finished_update_migrate
;
145 int order
; /* order a direct compactor needs */
146 int migratetype
; /* MOVABLE, RECLAIMABLE etc */
148 bool contended
; /* True if a lock was contended, or
149 * need_resched() true during async
155 isolate_freepages_range(struct compact_control
*cc
,
156 unsigned long start_pfn
, unsigned long end_pfn
);
158 isolate_migratepages_range(struct zone
*zone
, struct compact_control
*cc
,
159 unsigned long low_pfn
, unsigned long end_pfn
, bool unevictable
);
164 * function for dealing with page's order in buddy system.
165 * zone->lock is already acquired when we use these.
166 * So, we don't need atomic page->flags operations here.
168 static inline unsigned long page_order(struct page
*page
)
170 /* PageBuddy() must be checked by the caller */
171 return page_private(page
);
175 void __vma_link_list(struct mm_struct
*mm
, struct vm_area_struct
*vma
,
176 struct vm_area_struct
*prev
, struct rb_node
*rb_parent
);
179 extern long __mlock_vma_pages_range(struct vm_area_struct
*vma
,
180 unsigned long start
, unsigned long end
, int *nonblocking
);
181 extern void munlock_vma_pages_range(struct vm_area_struct
*vma
,
182 unsigned long start
, unsigned long end
);
183 static inline void munlock_vma_pages_all(struct vm_area_struct
*vma
)
185 munlock_vma_pages_range(vma
, vma
->vm_start
, vma
->vm_end
);
189 * Called only in fault path, to determine if a new page is being
190 * mapped into a LOCKED vma. If it is, mark page as mlocked.
192 static inline int mlocked_vma_newpage(struct vm_area_struct
*vma
,
195 VM_BUG_ON(PageLRU(page
));
197 if (likely((vma
->vm_flags
& (VM_LOCKED
| VM_SPECIAL
)) != VM_LOCKED
))
200 if (!TestSetPageMlocked(page
)) {
201 mod_zone_page_state(page_zone(page
), NR_MLOCK
,
202 hpage_nr_pages(page
));
203 count_vm_event(UNEVICTABLE_PGMLOCKED
);
209 * must be called with vma's mmap_sem held for read or write, and page locked.
211 extern void mlock_vma_page(struct page
*page
);
212 extern unsigned int munlock_vma_page(struct page
*page
);
215 * Clear the page's PageMlocked(). This can be useful in a situation where
216 * we want to unconditionally remove a page from the pagecache -- e.g.,
217 * on truncation or freeing.
219 * It is legal to call this function for any page, mlocked or not.
220 * If called for a page that is still mapped by mlocked vmas, all we do
221 * is revert to lazy LRU behaviour -- semantics are not broken.
223 extern void clear_page_mlock(struct page
*page
);
226 * mlock_migrate_page - called only from migrate_page_copy() to
227 * migrate the Mlocked page flag; update statistics.
229 static inline void mlock_migrate_page(struct page
*newpage
, struct page
*page
)
231 if (TestClearPageMlocked(page
)) {
233 int nr_pages
= hpage_nr_pages(page
);
235 local_irq_save(flags
);
236 __mod_zone_page_state(page_zone(page
), NR_MLOCK
, -nr_pages
);
237 SetPageMlocked(newpage
);
238 __mod_zone_page_state(page_zone(newpage
), NR_MLOCK
, nr_pages
);
239 local_irq_restore(flags
);
243 extern pmd_t
maybe_pmd_mkwrite(pmd_t pmd
, struct vm_area_struct
*vma
);
245 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
246 extern unsigned long vma_address(struct page
*page
,
247 struct vm_area_struct
*vma
);
249 #else /* !CONFIG_MMU */
250 static inline int mlocked_vma_newpage(struct vm_area_struct
*v
, struct page
*p
)
254 static inline void clear_page_mlock(struct page
*page
) { }
255 static inline void mlock_vma_page(struct page
*page
) { }
256 static inline void mlock_migrate_page(struct page
*new, struct page
*old
) { }
258 #endif /* !CONFIG_MMU */
261 * Return the mem_map entry representing the 'offset' subpage within
262 * the maximally aligned gigantic page 'base'. Handle any discontiguity
263 * in the mem_map at MAX_ORDER_NR_PAGES boundaries.
265 static inline struct page
*mem_map_offset(struct page
*base
, int offset
)
267 if (unlikely(offset
>= MAX_ORDER_NR_PAGES
))
268 return pfn_to_page(page_to_pfn(base
) + offset
);
269 return base
+ offset
;
273 * Iterator over all subpages within the maximally aligned gigantic
274 * page 'base'. Handle any discontiguity in the mem_map.
276 static inline struct page
*mem_map_next(struct page
*iter
,
277 struct page
*base
, int offset
)
279 if (unlikely((offset
& (MAX_ORDER_NR_PAGES
- 1)) == 0)) {
280 unsigned long pfn
= page_to_pfn(base
) + offset
;
283 return pfn_to_page(pfn
);
289 * FLATMEM and DISCONTIGMEM configurations use alloc_bootmem_node,
290 * so all functions starting at paging_init should be marked __init
291 * in those cases. SPARSEMEM, however, allows for memory hotplug,
292 * and alloc_bootmem_node is not used.
294 #ifdef CONFIG_SPARSEMEM
295 #define __paginginit __meminit
297 #define __paginginit __init
300 /* Memory initialisation debug and verification */
307 #ifdef CONFIG_DEBUG_MEMORY_INIT
309 extern int mminit_loglevel
;
311 #define mminit_dprintk(level, prefix, fmt, arg...) \
313 if (level < mminit_loglevel) { \
314 printk(level <= MMINIT_WARNING ? KERN_WARNING : KERN_DEBUG); \
315 printk(KERN_CONT "mminit::" prefix " " fmt, ##arg); \
319 extern void mminit_verify_pageflags_layout(void);
320 extern void mminit_verify_page_links(struct page
*page
,
321 enum zone_type zone
, unsigned long nid
, unsigned long pfn
);
322 extern void mminit_verify_zonelist(void);
326 static inline void mminit_dprintk(enum mminit_level level
,
327 const char *prefix
, const char *fmt
, ...)
331 static inline void mminit_verify_pageflags_layout(void)
335 static inline void mminit_verify_page_links(struct page
*page
,
336 enum zone_type zone
, unsigned long nid
, unsigned long pfn
)
340 static inline void mminit_verify_zonelist(void)
343 #endif /* CONFIG_DEBUG_MEMORY_INIT */
345 /* mminit_validate_memmodel_limits is independent of CONFIG_DEBUG_MEMORY_INIT */
346 #if defined(CONFIG_SPARSEMEM)
347 extern void mminit_validate_memmodel_limits(unsigned long *start_pfn
,
348 unsigned long *end_pfn
);
350 static inline void mminit_validate_memmodel_limits(unsigned long *start_pfn
,
351 unsigned long *end_pfn
)
354 #endif /* CONFIG_SPARSEMEM */
356 #define ZONE_RECLAIM_NOSCAN -2
357 #define ZONE_RECLAIM_FULL -1
358 #define ZONE_RECLAIM_SOME 0
359 #define ZONE_RECLAIM_SUCCESS 1
361 extern int hwpoison_filter(struct page
*p
);
363 extern u32 hwpoison_filter_dev_major
;
364 extern u32 hwpoison_filter_dev_minor
;
365 extern u64 hwpoison_filter_flags_mask
;
366 extern u64 hwpoison_filter_flags_value
;
367 extern u64 hwpoison_filter_memcg
;
368 extern u32 hwpoison_filter_enable
;
370 extern unsigned long vm_mmap_pgoff(struct file
*, unsigned long,
371 unsigned long, unsigned long,
372 unsigned long, unsigned long);
374 extern void set_pageblock_order(void);
375 unsigned long reclaim_clean_pages_from_list(struct zone
*zone
,
376 struct list_head
*page_list
);
377 /* The ALLOC_WMARK bits are used as an index to zone->watermark */
378 #define ALLOC_WMARK_MIN WMARK_MIN
379 #define ALLOC_WMARK_LOW WMARK_LOW
380 #define ALLOC_WMARK_HIGH WMARK_HIGH
381 #define ALLOC_NO_WATERMARKS 0x04 /* don't check watermarks at all */
383 /* Mask to get the watermark bits */
384 #define ALLOC_WMARK_MASK (ALLOC_NO_WATERMARKS-1)
386 #define ALLOC_HARDER 0x10 /* try to alloc harder */
387 #define ALLOC_HIGH 0x20 /* __GFP_HIGH set */
388 #define ALLOC_CPUSET 0x40 /* check for correct cpuset */
389 #define ALLOC_CMA 0x80 /* allow allocations from CMA areas */
390 #define ALLOC_FAIR 0x100 /* fair zone allocation */
392 #endif /* __MM_INTERNAL_H */