internal.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* internal.h: mm/ internal definitions
  2. *
  3. * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  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.
  10. */
  11. #ifndef __MM_INTERNAL_H
  12. #define __MM_INTERNAL_H
  13. #include <linux/mm.h>
  14. void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
  15. unsigned long floor, unsigned long ceiling);
  16. static inline void set_page_count(struct page *page, int v)
  17. {
  18. atomic_set(&page->_count, v);
  19. }
  20. /*
  21. * Turn a non-refcounted page (->_count == 0) into refcounted with
  22. * a count of one.
  23. */
  24. static inline void set_page_refcounted(struct page *page)
  25. {
  26. VM_BUG_ON(PageTail(page));
  27. VM_BUG_ON(atomic_read(&page->_count));
  28. set_page_count(page, 1);
  29. }
  30. static inline void __put_page(struct page *page)
  31. {
  32. atomic_dec(&page->_count);
  33. }
  34. extern unsigned long highest_memmap_pfn;
  35. #ifdef CONFIG_SMP
  36. extern int putback_active_lru_page(struct zone *zone, struct page *page);
  37. #else
  38. static inline int putback_active_lru_page(struct zone *zone, struct page *page)
  39. {
  40. return 0;
  41. }
  42. #endif
  43. /*
  44. * in mm/vmscan.c:
  45. */
  46. extern int isolate_lru_page(struct page *page);
  47. extern void putback_lru_page(struct page *page);
  48. /*
  49. * in mm/page_alloc.c
  50. */
  51. extern void __free_pages_bootmem(struct page *page, unsigned int order);
  52. extern void prep_compound_page(struct page *page, unsigned long order);
  53. #ifdef CONFIG_MEMORY_FAILURE
  54. extern bool is_free_buddy_page(struct page *page);
  55. #endif
  56. /*
  57. * function for dealing with page's order in buddy system.
  58. * zone->lock is already acquired when we use these.
  59. * So, we don't need atomic page->flags operations here.
  60. */
  61. static inline unsigned long page_order(struct page *page)
  62. {
  63. /* PageBuddy() must be checked by the caller */
  64. return page_private(page);
  65. }
  66. #ifdef CONFIG_MMU
  67. extern long mlock_vma_pages_range(struct vm_area_struct *vma,
  68. unsigned long start, unsigned long end);
  69. extern void munlock_vma_pages_range(struct vm_area_struct *vma,
  70. unsigned long start, unsigned long end);
  71. static inline void munlock_vma_pages_all(struct vm_area_struct *vma)
  72. {
  73. munlock_vma_pages_range(vma, vma->vm_start, vma->vm_end);
  74. }
  75. /*
  76. * Called only in fault path via page_evictable() for a new page
  77. * to determine if it's being mapped into a LOCKED vma.
  78. * If so, mark page as mlocked.
  79. */
  80. static inline int is_mlocked_vma(struct vm_area_struct *vma, struct page *page)
  81. {
  82. VM_BUG_ON(PageLRU(page));
  83. if (likely((vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) != VM_LOCKED))
  84. return 0;
  85. if (!TestSetPageMlocked(page)) {
  86. inc_zone_page_state(page, NR_MLOCK);
  87. count_vm_event(UNEVICTABLE_PGMLOCKED);
  88. }
  89. return 1;
  90. }
  91. /*
  92. * must be called with vma's mmap_sem held for read or write, and page locked.
  93. */
  94. extern void mlock_vma_page(struct page *page);
  95. extern void munlock_vma_page(struct page *page);
  96. /*
  97. * Clear the page's PageMlocked(). This can be useful in a situation where
  98. * we want to unconditionally remove a page from the pagecache -- e.g.,
  99. * on truncation or freeing.
  100. *
  101. * It is legal to call this function for any page, mlocked or not.
  102. * If called for a page that is still mapped by mlocked vmas, all we do
  103. * is revert to lazy LRU behaviour -- semantics are not broken.
  104. */
  105. extern void __clear_page_mlock(struct page *page);
  106. static inline void clear_page_mlock(struct page *page)
  107. {
  108. if (unlikely(TestClearPageMlocked(page)))
  109. __clear_page_mlock(page);
  110. }
  111. /*
  112. * mlock_migrate_page - called only from migrate_page_copy() to
  113. * migrate the Mlocked page flag; update statistics.
  114. */
  115. static inline void mlock_migrate_page(struct page *newpage, struct page *page)
  116. {
  117. if (TestClearPageMlocked(page)) {
  118. unsigned long flags;
  119. local_irq_save(flags);
  120. __dec_zone_page_state(page, NR_MLOCK);
  121. SetPageMlocked(newpage);
  122. __inc_zone_page_state(newpage, NR_MLOCK);
  123. local_irq_restore(flags);
  124. }
  125. }
  126. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  127. extern unsigned long vma_address(struct page *page,
  128. struct vm_area_struct *vma);
  129. #endif
  130. #else /* !CONFIG_MMU */
  131. static inline int is_mlocked_vma(struct vm_area_struct *v, struct page *p)
  132. {
  133. return 0;
  134. }
  135. static inline void clear_page_mlock(struct page *page) { }
  136. static inline void mlock_vma_page(struct page *page) { }
  137. static inline void mlock_migrate_page(struct page *new, struct page *old) { }
  138. #endif /* !CONFIG_MMU */
  139. /*
  140. * Return the mem_map entry representing the 'offset' subpage within
  141. * the maximally aligned gigantic page 'base'. Handle any discontiguity
  142. * in the mem_map at MAX_ORDER_NR_PAGES boundaries.
  143. */
  144. static inline struct page *mem_map_offset(struct page *base, int offset)
  145. {
  146. if (unlikely(offset >= MAX_ORDER_NR_PAGES))
  147. return pfn_to_page(page_to_pfn(base) + offset);
  148. return base + offset;
  149. }
  150. /*
  151. * Iterator over all subpages withing the maximally aligned gigantic
  152. * page 'base'. Handle any discontiguity in the mem_map.
  153. */
  154. static inline struct page *mem_map_next(struct page *iter,
  155. struct page *base, int offset)
  156. {
  157. if (unlikely((offset & (MAX_ORDER_NR_PAGES - 1)) == 0)) {
  158. unsigned long pfn = page_to_pfn(base) + offset;
  159. if (!pfn_valid(pfn))
  160. return NULL;
  161. return pfn_to_page(pfn);
  162. }
  163. return iter + 1;
  164. }
  165. /*
  166. * FLATMEM and DISCONTIGMEM configurations use alloc_bootmem_node,
  167. * so all functions starting at paging_init should be marked __init
  168. * in those cases. SPARSEMEM, however, allows for memory hotplug,
  169. * and alloc_bootmem_node is not used.
  170. */
  171. #ifdef CONFIG_SPARSEMEM
  172. #define __paginginit __meminit
  173. #else
  174. #define __paginginit __init
  175. #endif
  176. /* Memory initialisation debug and verification */
  177. enum mminit_level {
  178. MMINIT_WARNING,
  179. MMINIT_VERIFY,
  180. MMINIT_TRACE
  181. };
  182. #ifdef CONFIG_DEBUG_MEMORY_INIT
  183. extern int mminit_loglevel;
  184. #define mminit_dprintk(level, prefix, fmt, arg...) \
  185. do { \
  186. if (level < mminit_loglevel) { \
  187. printk(level <= MMINIT_WARNING ? KERN_WARNING : KERN_DEBUG); \
  188. printk(KERN_CONT "mminit::" prefix " " fmt, ##arg); \
  189. } \
  190. } while (0)
  191. extern void mminit_verify_pageflags_layout(void);
  192. extern void mminit_verify_page_links(struct page *page,
  193. enum zone_type zone, unsigned long nid, unsigned long pfn);
  194. extern void mminit_verify_zonelist(void);
  195. #else
  196. static inline void mminit_dprintk(enum mminit_level level,
  197. const char *prefix, const char *fmt, ...)
  198. {
  199. }
  200. static inline void mminit_verify_pageflags_layout(void)
  201. {
  202. }
  203. static inline void mminit_verify_page_links(struct page *page,
  204. enum zone_type zone, unsigned long nid, unsigned long pfn)
  205. {
  206. }
  207. static inline void mminit_verify_zonelist(void)
  208. {
  209. }
  210. #endif /* CONFIG_DEBUG_MEMORY_INIT */
  211. /* mminit_validate_memmodel_limits is independent of CONFIG_DEBUG_MEMORY_INIT */
  212. #if defined(CONFIG_SPARSEMEM)
  213. extern void mminit_validate_memmodel_limits(unsigned long *start_pfn,
  214. unsigned long *end_pfn);
  215. #else
  216. static inline void mminit_validate_memmodel_limits(unsigned long *start_pfn,
  217. unsigned long *end_pfn)
  218. {
  219. }
  220. #endif /* CONFIG_SPARSEMEM */
  221. int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
  222. unsigned long start, int len, unsigned int foll_flags,
  223. struct page **pages, struct vm_area_struct **vmas,
  224. int *nonblocking);
  225. #define ZONE_RECLAIM_NOSCAN -2
  226. #define ZONE_RECLAIM_FULL -1
  227. #define ZONE_RECLAIM_SOME 0
  228. #define ZONE_RECLAIM_SUCCESS 1
  229. #endif
  230. extern int hwpoison_filter(struct page *p);
  231. extern u32 hwpoison_filter_dev_major;
  232. extern u32 hwpoison_filter_dev_minor;
  233. extern u64 hwpoison_filter_flags_mask;
  234. extern u64 hwpoison_filter_flags_value;
  235. extern u64 hwpoison_filter_memcg;
  236. extern u32 hwpoison_filter_enable;