internal.h 7.3 KB

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