internal.h 6.8 KB

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