mm.h 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275
  1. #ifndef _LINUX_MM_H
  2. #define _LINUX_MM_H
  3. #include <linux/errno.h>
  4. #ifdef __KERNEL__
  5. #include <linux/mmdebug.h>
  6. #include <linux/gfp.h>
  7. #include <linux/bug.h>
  8. #include <linux/list.h>
  9. #include <linux/mmzone.h>
  10. #include <linux/rbtree.h>
  11. #include <linux/atomic.h>
  12. #include <linux/debug_locks.h>
  13. #include <linux/mm_types.h>
  14. #include <linux/range.h>
  15. #include <linux/pfn.h>
  16. #include <linux/bit_spinlock.h>
  17. #include <linux/shrinker.h>
  18. #include <linux/resource.h>
  19. #include <linux/page_ext.h>
  20. struct mempolicy;
  21. struct anon_vma;
  22. struct anon_vma_chain;
  23. struct file_ra_state;
  24. struct user_struct;
  25. struct writeback_control;
  26. struct bdi_writeback;
  27. #ifndef CONFIG_NEED_MULTIPLE_NODES /* Don't use mapnrs, do it properly */
  28. extern unsigned long max_mapnr;
  29. static inline void set_max_mapnr(unsigned long limit)
  30. {
  31. max_mapnr = limit;
  32. }
  33. #else
  34. static inline void set_max_mapnr(unsigned long limit) { }
  35. #endif
  36. extern unsigned long totalram_pages;
  37. extern void * high_memory;
  38. extern int page_cluster;
  39. #ifdef CONFIG_SYSCTL
  40. extern int sysctl_legacy_va_layout;
  41. #else
  42. #define sysctl_legacy_va_layout 0
  43. #endif
  44. #include <asm/page.h>
  45. #include <asm/pgtable.h>
  46. #include <asm/processor.h>
  47. #ifndef __pa_symbol
  48. #define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
  49. #endif
  50. /*
  51. * To prevent common memory management code establishing
  52. * a zero page mapping on a read fault.
  53. * This macro should be defined within <asm/pgtable.h>.
  54. * s390 does this to prevent multiplexing of hardware bits
  55. * related to the physical page in case of virtualization.
  56. */
  57. #ifndef mm_forbids_zeropage
  58. #define mm_forbids_zeropage(X) (0)
  59. #endif
  60. extern unsigned long sysctl_user_reserve_kbytes;
  61. extern unsigned long sysctl_admin_reserve_kbytes;
  62. extern int sysctl_overcommit_memory;
  63. extern int sysctl_overcommit_ratio;
  64. extern unsigned long sysctl_overcommit_kbytes;
  65. extern int overcommit_ratio_handler(struct ctl_table *, int, void __user *,
  66. size_t *, loff_t *);
  67. extern int overcommit_kbytes_handler(struct ctl_table *, int, void __user *,
  68. size_t *, loff_t *);
  69. #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
  70. /* to align the pointer to the (next) page boundary */
  71. #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
  72. /* test whether an address (unsigned long or pointer) is aligned to PAGE_SIZE */
  73. #define PAGE_ALIGNED(addr) IS_ALIGNED((unsigned long)addr, PAGE_SIZE)
  74. /*
  75. * Linux kernel virtual memory manager primitives.
  76. * The idea being to have a "virtual" mm in the same way
  77. * we have a virtual fs - giving a cleaner interface to the
  78. * mm details, and allowing different kinds of memory mappings
  79. * (from shared memory to executable loading to arbitrary
  80. * mmap() functions).
  81. */
  82. extern struct kmem_cache *vm_area_cachep;
  83. #ifndef CONFIG_MMU
  84. extern struct rb_root nommu_region_tree;
  85. extern struct rw_semaphore nommu_region_sem;
  86. extern unsigned int kobjsize(const void *objp);
  87. #endif
  88. /*
  89. * vm_flags in vm_area_struct, see mm_types.h.
  90. */
  91. #define VM_NONE 0x00000000
  92. #define VM_READ 0x00000001 /* currently active flags */
  93. #define VM_WRITE 0x00000002
  94. #define VM_EXEC 0x00000004
  95. #define VM_SHARED 0x00000008
  96. /* mprotect() hardcodes VM_MAYREAD >> 4 == VM_READ, and so for r/w/x bits. */
  97. #define VM_MAYREAD 0x00000010 /* limits for mprotect() etc */
  98. #define VM_MAYWRITE 0x00000020
  99. #define VM_MAYEXEC 0x00000040
  100. #define VM_MAYSHARE 0x00000080
  101. #define VM_GROWSDOWN 0x00000100 /* general info on the segment */
  102. #define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page", just pure PFN */
  103. #define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */
  104. #define VM_LOCKED 0x00002000
  105. #define VM_IO 0x00004000 /* Memory mapped I/O or similar */
  106. /* Used by sys_madvise() */
  107. #define VM_SEQ_READ 0x00008000 /* App will access data sequentially */
  108. #define VM_RAND_READ 0x00010000 /* App will not benefit from clustered reads */
  109. #define VM_DONTCOPY 0x00020000 /* Do not copy this vma on fork */
  110. #define VM_DONTEXPAND 0x00040000 /* Cannot expand with mremap() */
  111. #define VM_ACCOUNT 0x00100000 /* Is a VM accounted object */
  112. #define VM_NORESERVE 0x00200000 /* should the VM suppress accounting */
  113. #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
  114. #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
  115. #define VM_ARCH_2 0x02000000
  116. #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
  117. #ifdef CONFIG_MEM_SOFT_DIRTY
  118. # define VM_SOFTDIRTY 0x08000000 /* Not soft dirty clean area */
  119. #else
  120. # define VM_SOFTDIRTY 0
  121. #endif
  122. #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
  123. #define VM_HUGEPAGE 0x20000000 /* MADV_HUGEPAGE marked this vma */
  124. #define VM_NOHUGEPAGE 0x40000000 /* MADV_NOHUGEPAGE marked this vma */
  125. #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
  126. #if defined(CONFIG_X86)
  127. # define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */
  128. #elif defined(CONFIG_PPC)
  129. # define VM_SAO VM_ARCH_1 /* Strong Access Ordering (powerpc) */
  130. #elif defined(CONFIG_PARISC)
  131. # define VM_GROWSUP VM_ARCH_1
  132. #elif defined(CONFIG_METAG)
  133. # define VM_GROWSUP VM_ARCH_1
  134. #elif defined(CONFIG_IA64)
  135. # define VM_GROWSUP VM_ARCH_1
  136. #elif !defined(CONFIG_MMU)
  137. # define VM_MAPPED_COPY VM_ARCH_1 /* T if mapped copy of data (nommu mmap) */
  138. #endif
  139. #if defined(CONFIG_X86)
  140. /* MPX specific bounds table or bounds directory */
  141. # define VM_MPX VM_ARCH_2
  142. #endif
  143. #ifndef VM_GROWSUP
  144. # define VM_GROWSUP VM_NONE
  145. #endif
  146. /* Bits set in the VMA until the stack is in its final location */
  147. #define VM_STACK_INCOMPLETE_SETUP (VM_RAND_READ | VM_SEQ_READ)
  148. #ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */
  149. #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
  150. #endif
  151. #ifdef CONFIG_STACK_GROWSUP
  152. #define VM_STACK_FLAGS (VM_GROWSUP | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)
  153. #else
  154. #define VM_STACK_FLAGS (VM_GROWSDOWN | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)
  155. #endif
  156. /*
  157. * Special vmas that are non-mergable, non-mlock()able.
  158. * Note: mm/huge_memory.c VM_NO_THP depends on this definition.
  159. */
  160. #define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP)
  161. /* This mask defines which mm->def_flags a process can inherit its parent */
  162. #define VM_INIT_DEF_MASK VM_NOHUGEPAGE
  163. /*
  164. * mapping from the currently active vm_flags protection bits (the
  165. * low four bits) to a page protection mask..
  166. */
  167. extern pgprot_t protection_map[16];
  168. #define FAULT_FLAG_WRITE 0x01 /* Fault was a write access */
  169. #define FAULT_FLAG_MKWRITE 0x02 /* Fault was mkwrite of existing pte */
  170. #define FAULT_FLAG_ALLOW_RETRY 0x04 /* Retry fault if blocking */
  171. #define FAULT_FLAG_RETRY_NOWAIT 0x08 /* Don't drop mmap_sem and wait when retrying */
  172. #define FAULT_FLAG_KILLABLE 0x10 /* The fault task is in SIGKILL killable region */
  173. #define FAULT_FLAG_TRIED 0x20 /* Second try */
  174. #define FAULT_FLAG_USER 0x40 /* The fault originated in userspace */
  175. /*
  176. * vm_fault is filled by the the pagefault handler and passed to the vma's
  177. * ->fault function. The vma's ->fault is responsible for returning a bitmask
  178. * of VM_FAULT_xxx flags that give details about how the fault was handled.
  179. *
  180. * pgoff should be used in favour of virtual_address, if possible.
  181. */
  182. struct vm_fault {
  183. unsigned int flags; /* FAULT_FLAG_xxx flags */
  184. pgoff_t pgoff; /* Logical page offset based on vma */
  185. void __user *virtual_address; /* Faulting virtual address */
  186. struct page *cow_page; /* Handler may choose to COW */
  187. struct page *page; /* ->fault handlers should return a
  188. * page here, unless VM_FAULT_NOPAGE
  189. * is set (which is also implied by
  190. * VM_FAULT_ERROR).
  191. */
  192. /* for ->map_pages() only */
  193. pgoff_t max_pgoff; /* map pages for offset from pgoff till
  194. * max_pgoff inclusive */
  195. pte_t *pte; /* pte entry associated with ->pgoff */
  196. };
  197. /*
  198. * These are the virtual MM functions - opening of an area, closing and
  199. * unmapping it (needed to keep files on disk up-to-date etc), pointer
  200. * to the functions called when a no-page or a wp-page exception occurs.
  201. */
  202. struct vm_operations_struct {
  203. void (*open)(struct vm_area_struct * area);
  204. void (*close)(struct vm_area_struct * area);
  205. int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf);
  206. void (*map_pages)(struct vm_area_struct *vma, struct vm_fault *vmf);
  207. /* notification that a previously read-only page is about to become
  208. * writable, if an error is returned it will cause a SIGBUS */
  209. int (*page_mkwrite)(struct vm_area_struct *vma, struct vm_fault *vmf);
  210. /* same as page_mkwrite when using VM_PFNMAP|VM_MIXEDMAP */
  211. int (*pfn_mkwrite)(struct vm_area_struct *vma, struct vm_fault *vmf);
  212. /* called by access_process_vm when get_user_pages() fails, typically
  213. * for use by special VMAs that can switch between memory and hardware
  214. */
  215. int (*access)(struct vm_area_struct *vma, unsigned long addr,
  216. void *buf, int len, int write);
  217. /* Called by the /proc/PID/maps code to ask the vma whether it
  218. * has a special name. Returning non-NULL will also cause this
  219. * vma to be dumped unconditionally. */
  220. const char *(*name)(struct vm_area_struct *vma);
  221. #ifdef CONFIG_NUMA
  222. /*
  223. * set_policy() op must add a reference to any non-NULL @new mempolicy
  224. * to hold the policy upon return. Caller should pass NULL @new to
  225. * remove a policy and fall back to surrounding context--i.e. do not
  226. * install a MPOL_DEFAULT policy, nor the task or system default
  227. * mempolicy.
  228. */
  229. int (*set_policy)(struct vm_area_struct *vma, struct mempolicy *new);
  230. /*
  231. * get_policy() op must add reference [mpol_get()] to any policy at
  232. * (vma,addr) marked as MPOL_SHARED. The shared policy infrastructure
  233. * in mm/mempolicy.c will do this automatically.
  234. * get_policy() must NOT add a ref if the policy at (vma,addr) is not
  235. * marked as MPOL_SHARED. vma policies are protected by the mmap_sem.
  236. * If no [shared/vma] mempolicy exists at the addr, get_policy() op
  237. * must return NULL--i.e., do not "fallback" to task or system default
  238. * policy.
  239. */
  240. struct mempolicy *(*get_policy)(struct vm_area_struct *vma,
  241. unsigned long addr);
  242. #endif
  243. /*
  244. * Called by vm_normal_page() for special PTEs to find the
  245. * page for @addr. This is useful if the default behavior
  246. * (using pte_page()) would not find the correct page.
  247. */
  248. struct page *(*find_special_page)(struct vm_area_struct *vma,
  249. unsigned long addr);
  250. };
  251. struct mmu_gather;
  252. struct inode;
  253. #define page_private(page) ((page)->private)
  254. #define set_page_private(page, v) ((page)->private = (v))
  255. /* It's valid only if the page is free path or free_list */
  256. static inline void set_freepage_migratetype(struct page *page, int migratetype)
  257. {
  258. page->index = migratetype;
  259. }
  260. /* It's valid only if the page is free path or free_list */
  261. static inline int get_freepage_migratetype(struct page *page)
  262. {
  263. return page->index;
  264. }
  265. /*
  266. * FIXME: take this include out, include page-flags.h in
  267. * files which need it (119 of them)
  268. */
  269. #include <linux/page-flags.h>
  270. #include <linux/huge_mm.h>
  271. /*
  272. * Methods to modify the page usage count.
  273. *
  274. * What counts for a page usage:
  275. * - cache mapping (page->mapping)
  276. * - private data (page->private)
  277. * - page mapped in a task's page tables, each mapping
  278. * is counted separately
  279. *
  280. * Also, many kernel routines increase the page count before a critical
  281. * routine so they can be sure the page doesn't go away from under them.
  282. */
  283. /*
  284. * Drop a ref, return true if the refcount fell to zero (the page has no users)
  285. */
  286. static inline int put_page_testzero(struct page *page)
  287. {
  288. VM_BUG_ON_PAGE(atomic_read(&page->_count) == 0, page);
  289. return atomic_dec_and_test(&page->_count);
  290. }
  291. /*
  292. * Try to grab a ref unless the page has a refcount of zero, return false if
  293. * that is the case.
  294. * This can be called when MMU is off so it must not access
  295. * any of the virtual mappings.
  296. */
  297. static inline int get_page_unless_zero(struct page *page)
  298. {
  299. return atomic_inc_not_zero(&page->_count);
  300. }
  301. /*
  302. * Try to drop a ref unless the page has a refcount of one, return false if
  303. * that is the case.
  304. * This is to make sure that the refcount won't become zero after this drop.
  305. * This can be called when MMU is off so it must not access
  306. * any of the virtual mappings.
  307. */
  308. static inline int put_page_unless_one(struct page *page)
  309. {
  310. return atomic_add_unless(&page->_count, -1, 1);
  311. }
  312. extern int page_is_ram(unsigned long pfn);
  313. extern int region_is_ram(resource_size_t phys_addr, unsigned long size);
  314. /* Support for virtually mapped pages */
  315. struct page *vmalloc_to_page(const void *addr);
  316. unsigned long vmalloc_to_pfn(const void *addr);
  317. /*
  318. * Determine if an address is within the vmalloc range
  319. *
  320. * On nommu, vmalloc/vfree wrap through kmalloc/kfree directly, so there
  321. * is no special casing required.
  322. */
  323. static inline int is_vmalloc_addr(const void *x)
  324. {
  325. #ifdef CONFIG_MMU
  326. unsigned long addr = (unsigned long)x;
  327. return addr >= VMALLOC_START && addr < VMALLOC_END;
  328. #else
  329. return 0;
  330. #endif
  331. }
  332. #ifdef CONFIG_MMU
  333. extern int is_vmalloc_or_module_addr(const void *x);
  334. #else
  335. static inline int is_vmalloc_or_module_addr(const void *x)
  336. {
  337. return 0;
  338. }
  339. #endif
  340. extern void kvfree(const void *addr);
  341. static inline void compound_lock(struct page *page)
  342. {
  343. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  344. VM_BUG_ON_PAGE(PageSlab(page), page);
  345. bit_spin_lock(PG_compound_lock, &page->flags);
  346. #endif
  347. }
  348. static inline void compound_unlock(struct page *page)
  349. {
  350. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  351. VM_BUG_ON_PAGE(PageSlab(page), page);
  352. bit_spin_unlock(PG_compound_lock, &page->flags);
  353. #endif
  354. }
  355. static inline unsigned long compound_lock_irqsave(struct page *page)
  356. {
  357. unsigned long uninitialized_var(flags);
  358. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  359. local_irq_save(flags);
  360. compound_lock(page);
  361. #endif
  362. return flags;
  363. }
  364. static inline void compound_unlock_irqrestore(struct page *page,
  365. unsigned long flags)
  366. {
  367. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  368. compound_unlock(page);
  369. local_irq_restore(flags);
  370. #endif
  371. }
  372. static inline struct page *compound_head_by_tail(struct page *tail)
  373. {
  374. struct page *head = tail->first_page;
  375. /*
  376. * page->first_page may be a dangling pointer to an old
  377. * compound page, so recheck that it is still a tail
  378. * page before returning.
  379. */
  380. smp_rmb();
  381. if (likely(PageTail(tail)))
  382. return head;
  383. return tail;
  384. }
  385. /*
  386. * Since either compound page could be dismantled asynchronously in THP
  387. * or we access asynchronously arbitrary positioned struct page, there
  388. * would be tail flag race. To handle this race, we should call
  389. * smp_rmb() before checking tail flag. compound_head_by_tail() did it.
  390. */
  391. static inline struct page *compound_head(struct page *page)
  392. {
  393. if (unlikely(PageTail(page)))
  394. return compound_head_by_tail(page);
  395. return page;
  396. }
  397. /*
  398. * If we access compound page synchronously such as access to
  399. * allocated page, there is no need to handle tail flag race, so we can
  400. * check tail flag directly without any synchronization primitive.
  401. */
  402. static inline struct page *compound_head_fast(struct page *page)
  403. {
  404. if (unlikely(PageTail(page)))
  405. return page->first_page;
  406. return page;
  407. }
  408. /*
  409. * The atomic page->_mapcount, starts from -1: so that transitions
  410. * both from it and to it can be tracked, using atomic_inc_and_test
  411. * and atomic_add_negative(-1).
  412. */
  413. static inline void page_mapcount_reset(struct page *page)
  414. {
  415. atomic_set(&(page)->_mapcount, -1);
  416. }
  417. static inline int page_mapcount(struct page *page)
  418. {
  419. VM_BUG_ON_PAGE(PageSlab(page), page);
  420. return atomic_read(&page->_mapcount) + 1;
  421. }
  422. static inline int page_count(struct page *page)
  423. {
  424. return atomic_read(&compound_head(page)->_count);
  425. }
  426. static inline bool __compound_tail_refcounted(struct page *page)
  427. {
  428. return PageAnon(page) && !PageSlab(page) && !PageHeadHuge(page);
  429. }
  430. /*
  431. * This takes a head page as parameter and tells if the
  432. * tail page reference counting can be skipped.
  433. *
  434. * For this to be safe, PageSlab and PageHeadHuge must remain true on
  435. * any given page where they return true here, until all tail pins
  436. * have been released.
  437. */
  438. static inline bool compound_tail_refcounted(struct page *page)
  439. {
  440. VM_BUG_ON_PAGE(!PageHead(page), page);
  441. return __compound_tail_refcounted(page);
  442. }
  443. static inline void get_huge_page_tail(struct page *page)
  444. {
  445. /*
  446. * __split_huge_page_refcount() cannot run from under us.
  447. */
  448. VM_BUG_ON_PAGE(!PageTail(page), page);
  449. VM_BUG_ON_PAGE(page_mapcount(page) < 0, page);
  450. VM_BUG_ON_PAGE(atomic_read(&page->_count) != 0, page);
  451. if (compound_tail_refcounted(page->first_page))
  452. atomic_inc(&page->_mapcount);
  453. }
  454. extern bool __get_page_tail(struct page *page);
  455. static inline void get_page(struct page *page)
  456. {
  457. if (unlikely(PageTail(page)))
  458. if (likely(__get_page_tail(page)))
  459. return;
  460. /*
  461. * Getting a normal page or the head of a compound page
  462. * requires to already have an elevated page->_count.
  463. */
  464. VM_BUG_ON_PAGE(atomic_read(&page->_count) <= 0, page);
  465. atomic_inc(&page->_count);
  466. }
  467. static inline struct page *virt_to_head_page(const void *x)
  468. {
  469. struct page *page = virt_to_page(x);
  470. /*
  471. * We don't need to worry about synchronization of tail flag
  472. * when we call virt_to_head_page() since it is only called for
  473. * already allocated page and this page won't be freed until
  474. * this virt_to_head_page() is finished. So use _fast variant.
  475. */
  476. return compound_head_fast(page);
  477. }
  478. /*
  479. * Setup the page count before being freed into the page allocator for
  480. * the first time (boot or memory hotplug)
  481. */
  482. static inline void init_page_count(struct page *page)
  483. {
  484. atomic_set(&page->_count, 1);
  485. }
  486. void put_page(struct page *page);
  487. void put_pages_list(struct list_head *pages);
  488. void split_page(struct page *page, unsigned int order);
  489. int split_free_page(struct page *page);
  490. /*
  491. * Compound pages have a destructor function. Provide a
  492. * prototype for that function and accessor functions.
  493. * These are _only_ valid on the head of a PG_compound page.
  494. */
  495. static inline void set_compound_page_dtor(struct page *page,
  496. compound_page_dtor *dtor)
  497. {
  498. page[1].compound_dtor = dtor;
  499. }
  500. static inline compound_page_dtor *get_compound_page_dtor(struct page *page)
  501. {
  502. return page[1].compound_dtor;
  503. }
  504. static inline int compound_order(struct page *page)
  505. {
  506. if (!PageHead(page))
  507. return 0;
  508. return page[1].compound_order;
  509. }
  510. static inline void set_compound_order(struct page *page, unsigned long order)
  511. {
  512. page[1].compound_order = order;
  513. }
  514. #ifdef CONFIG_MMU
  515. /*
  516. * Do pte_mkwrite, but only if the vma says VM_WRITE. We do this when
  517. * servicing faults for write access. In the normal case, do always want
  518. * pte_mkwrite. But get_user_pages can cause write faults for mappings
  519. * that do not have writing enabled, when used by access_process_vm.
  520. */
  521. static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma)
  522. {
  523. if (likely(vma->vm_flags & VM_WRITE))
  524. pte = pte_mkwrite(pte);
  525. return pte;
  526. }
  527. void do_set_pte(struct vm_area_struct *vma, unsigned long address,
  528. struct page *page, pte_t *pte, bool write, bool anon);
  529. #endif
  530. /*
  531. * Multiple processes may "see" the same page. E.g. for untouched
  532. * mappings of /dev/null, all processes see the same page full of
  533. * zeroes, and text pages of executables and shared libraries have
  534. * only one copy in memory, at most, normally.
  535. *
  536. * For the non-reserved pages, page_count(page) denotes a reference count.
  537. * page_count() == 0 means the page is free. page->lru is then used for
  538. * freelist management in the buddy allocator.
  539. * page_count() > 0 means the page has been allocated.
  540. *
  541. * Pages are allocated by the slab allocator in order to provide memory
  542. * to kmalloc and kmem_cache_alloc. In this case, the management of the
  543. * page, and the fields in 'struct page' are the responsibility of mm/slab.c
  544. * unless a particular usage is carefully commented. (the responsibility of
  545. * freeing the kmalloc memory is the caller's, of course).
  546. *
  547. * A page may be used by anyone else who does a __get_free_page().
  548. * In this case, page_count still tracks the references, and should only
  549. * be used through the normal accessor functions. The top bits of page->flags
  550. * and page->virtual store page management information, but all other fields
  551. * are unused and could be used privately, carefully. The management of this
  552. * page is the responsibility of the one who allocated it, and those who have
  553. * subsequently been given references to it.
  554. *
  555. * The other pages (we may call them "pagecache pages") are completely
  556. * managed by the Linux memory manager: I/O, buffers, swapping etc.
  557. * The following discussion applies only to them.
  558. *
  559. * A pagecache page contains an opaque `private' member, which belongs to the
  560. * page's address_space. Usually, this is the address of a circular list of
  561. * the page's disk buffers. PG_private must be set to tell the VM to call
  562. * into the filesystem to release these pages.
  563. *
  564. * A page may belong to an inode's memory mapping. In this case, page->mapping
  565. * is the pointer to the inode, and page->index is the file offset of the page,
  566. * in units of PAGE_CACHE_SIZE.
  567. *
  568. * If pagecache pages are not associated with an inode, they are said to be
  569. * anonymous pages. These may become associated with the swapcache, and in that
  570. * case PG_swapcache is set, and page->private is an offset into the swapcache.
  571. *
  572. * In either case (swapcache or inode backed), the pagecache itself holds one
  573. * reference to the page. Setting PG_private should also increment the
  574. * refcount. The each user mapping also has a reference to the page.
  575. *
  576. * The pagecache pages are stored in a per-mapping radix tree, which is
  577. * rooted at mapping->page_tree, and indexed by offset.
  578. * Where 2.4 and early 2.6 kernels kept dirty/clean pages in per-address_space
  579. * lists, we instead now tag pages as dirty/writeback in the radix tree.
  580. *
  581. * All pagecache pages may be subject to I/O:
  582. * - inode pages may need to be read from disk,
  583. * - inode pages which have been modified and are MAP_SHARED may need
  584. * to be written back to the inode on disk,
  585. * - anonymous pages (including MAP_PRIVATE file mappings) which have been
  586. * modified may need to be swapped out to swap space and (later) to be read
  587. * back into memory.
  588. */
  589. /*
  590. * The zone field is never updated after free_area_init_core()
  591. * sets it, so none of the operations on it need to be atomic.
  592. */
  593. /* Page flags: | [SECTION] | [NODE] | ZONE | [LAST_CPUPID] | ... | FLAGS | */
  594. #define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - SECTIONS_WIDTH)
  595. #define NODES_PGOFF (SECTIONS_PGOFF - NODES_WIDTH)
  596. #define ZONES_PGOFF (NODES_PGOFF - ZONES_WIDTH)
  597. #define LAST_CPUPID_PGOFF (ZONES_PGOFF - LAST_CPUPID_WIDTH)
  598. /*
  599. * Define the bit shifts to access each section. For non-existent
  600. * sections we define the shift as 0; that plus a 0 mask ensures
  601. * the compiler will optimise away reference to them.
  602. */
  603. #define SECTIONS_PGSHIFT (SECTIONS_PGOFF * (SECTIONS_WIDTH != 0))
  604. #define NODES_PGSHIFT (NODES_PGOFF * (NODES_WIDTH != 0))
  605. #define ZONES_PGSHIFT (ZONES_PGOFF * (ZONES_WIDTH != 0))
  606. #define LAST_CPUPID_PGSHIFT (LAST_CPUPID_PGOFF * (LAST_CPUPID_WIDTH != 0))
  607. /* NODE:ZONE or SECTION:ZONE is used to ID a zone for the buddy allocator */
  608. #ifdef NODE_NOT_IN_PAGE_FLAGS
  609. #define ZONEID_SHIFT (SECTIONS_SHIFT + ZONES_SHIFT)
  610. #define ZONEID_PGOFF ((SECTIONS_PGOFF < ZONES_PGOFF)? \
  611. SECTIONS_PGOFF : ZONES_PGOFF)
  612. #else
  613. #define ZONEID_SHIFT (NODES_SHIFT + ZONES_SHIFT)
  614. #define ZONEID_PGOFF ((NODES_PGOFF < ZONES_PGOFF)? \
  615. NODES_PGOFF : ZONES_PGOFF)
  616. #endif
  617. #define ZONEID_PGSHIFT (ZONEID_PGOFF * (ZONEID_SHIFT != 0))
  618. #if SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > BITS_PER_LONG - NR_PAGEFLAGS
  619. #error SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > BITS_PER_LONG - NR_PAGEFLAGS
  620. #endif
  621. #define ZONES_MASK ((1UL << ZONES_WIDTH) - 1)
  622. #define NODES_MASK ((1UL << NODES_WIDTH) - 1)
  623. #define SECTIONS_MASK ((1UL << SECTIONS_WIDTH) - 1)
  624. #define LAST_CPUPID_MASK ((1UL << LAST_CPUPID_SHIFT) - 1)
  625. #define ZONEID_MASK ((1UL << ZONEID_SHIFT) - 1)
  626. static inline enum zone_type page_zonenum(const struct page *page)
  627. {
  628. return (page->flags >> ZONES_PGSHIFT) & ZONES_MASK;
  629. }
  630. #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
  631. #define SECTION_IN_PAGE_FLAGS
  632. #endif
  633. /*
  634. * The identification function is mainly used by the buddy allocator for
  635. * determining if two pages could be buddies. We are not really identifying
  636. * the zone since we could be using the section number id if we do not have
  637. * node id available in page flags.
  638. * We only guarantee that it will return the same value for two combinable
  639. * pages in a zone.
  640. */
  641. static inline int page_zone_id(struct page *page)
  642. {
  643. return (page->flags >> ZONEID_PGSHIFT) & ZONEID_MASK;
  644. }
  645. static inline int zone_to_nid(struct zone *zone)
  646. {
  647. #ifdef CONFIG_NUMA
  648. return zone->node;
  649. #else
  650. return 0;
  651. #endif
  652. }
  653. #ifdef NODE_NOT_IN_PAGE_FLAGS
  654. extern int page_to_nid(const struct page *page);
  655. #else
  656. static inline int page_to_nid(const struct page *page)
  657. {
  658. return (page->flags >> NODES_PGSHIFT) & NODES_MASK;
  659. }
  660. #endif
  661. #ifdef CONFIG_NUMA_BALANCING
  662. static inline int cpu_pid_to_cpupid(int cpu, int pid)
  663. {
  664. return ((cpu & LAST__CPU_MASK) << LAST__PID_SHIFT) | (pid & LAST__PID_MASK);
  665. }
  666. static inline int cpupid_to_pid(int cpupid)
  667. {
  668. return cpupid & LAST__PID_MASK;
  669. }
  670. static inline int cpupid_to_cpu(int cpupid)
  671. {
  672. return (cpupid >> LAST__PID_SHIFT) & LAST__CPU_MASK;
  673. }
  674. static inline int cpupid_to_nid(int cpupid)
  675. {
  676. return cpu_to_node(cpupid_to_cpu(cpupid));
  677. }
  678. static inline bool cpupid_pid_unset(int cpupid)
  679. {
  680. return cpupid_to_pid(cpupid) == (-1 & LAST__PID_MASK);
  681. }
  682. static inline bool cpupid_cpu_unset(int cpupid)
  683. {
  684. return cpupid_to_cpu(cpupid) == (-1 & LAST__CPU_MASK);
  685. }
  686. static inline bool __cpupid_match_pid(pid_t task_pid, int cpupid)
  687. {
  688. return (task_pid & LAST__PID_MASK) == cpupid_to_pid(cpupid);
  689. }
  690. #define cpupid_match_pid(task, cpupid) __cpupid_match_pid(task->pid, cpupid)
  691. #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
  692. static inline int page_cpupid_xchg_last(struct page *page, int cpupid)
  693. {
  694. return xchg(&page->_last_cpupid, cpupid & LAST_CPUPID_MASK);
  695. }
  696. static inline int page_cpupid_last(struct page *page)
  697. {
  698. return page->_last_cpupid;
  699. }
  700. static inline void page_cpupid_reset_last(struct page *page)
  701. {
  702. page->_last_cpupid = -1 & LAST_CPUPID_MASK;
  703. }
  704. #else
  705. static inline int page_cpupid_last(struct page *page)
  706. {
  707. return (page->flags >> LAST_CPUPID_PGSHIFT) & LAST_CPUPID_MASK;
  708. }
  709. extern int page_cpupid_xchg_last(struct page *page, int cpupid);
  710. static inline void page_cpupid_reset_last(struct page *page)
  711. {
  712. int cpupid = (1 << LAST_CPUPID_SHIFT) - 1;
  713. page->flags &= ~(LAST_CPUPID_MASK << LAST_CPUPID_PGSHIFT);
  714. page->flags |= (cpupid & LAST_CPUPID_MASK) << LAST_CPUPID_PGSHIFT;
  715. }
  716. #endif /* LAST_CPUPID_NOT_IN_PAGE_FLAGS */
  717. #else /* !CONFIG_NUMA_BALANCING */
  718. static inline int page_cpupid_xchg_last(struct page *page, int cpupid)
  719. {
  720. return page_to_nid(page); /* XXX */
  721. }
  722. static inline int page_cpupid_last(struct page *page)
  723. {
  724. return page_to_nid(page); /* XXX */
  725. }
  726. static inline int cpupid_to_nid(int cpupid)
  727. {
  728. return -1;
  729. }
  730. static inline int cpupid_to_pid(int cpupid)
  731. {
  732. return -1;
  733. }
  734. static inline int cpupid_to_cpu(int cpupid)
  735. {
  736. return -1;
  737. }
  738. static inline int cpu_pid_to_cpupid(int nid, int pid)
  739. {
  740. return -1;
  741. }
  742. static inline bool cpupid_pid_unset(int cpupid)
  743. {
  744. return 1;
  745. }
  746. static inline void page_cpupid_reset_last(struct page *page)
  747. {
  748. }
  749. static inline bool cpupid_match_pid(struct task_struct *task, int cpupid)
  750. {
  751. return false;
  752. }
  753. #endif /* CONFIG_NUMA_BALANCING */
  754. static inline struct zone *page_zone(const struct page *page)
  755. {
  756. return &NODE_DATA(page_to_nid(page))->node_zones[page_zonenum(page)];
  757. }
  758. #ifdef SECTION_IN_PAGE_FLAGS
  759. static inline void set_page_section(struct page *page, unsigned long section)
  760. {
  761. page->flags &= ~(SECTIONS_MASK << SECTIONS_PGSHIFT);
  762. page->flags |= (section & SECTIONS_MASK) << SECTIONS_PGSHIFT;
  763. }
  764. static inline unsigned long page_to_section(const struct page *page)
  765. {
  766. return (page->flags >> SECTIONS_PGSHIFT) & SECTIONS_MASK;
  767. }
  768. #endif
  769. static inline void set_page_zone(struct page *page, enum zone_type zone)
  770. {
  771. page->flags &= ~(ZONES_MASK << ZONES_PGSHIFT);
  772. page->flags |= (zone & ZONES_MASK) << ZONES_PGSHIFT;
  773. }
  774. static inline void set_page_node(struct page *page, unsigned long node)
  775. {
  776. page->flags &= ~(NODES_MASK << NODES_PGSHIFT);
  777. page->flags |= (node & NODES_MASK) << NODES_PGSHIFT;
  778. }
  779. static inline void set_page_links(struct page *page, enum zone_type zone,
  780. unsigned long node, unsigned long pfn)
  781. {
  782. set_page_zone(page, zone);
  783. set_page_node(page, node);
  784. #ifdef SECTION_IN_PAGE_FLAGS
  785. set_page_section(page, pfn_to_section_nr(pfn));
  786. #endif
  787. }
  788. /*
  789. * Some inline functions in vmstat.h depend on page_zone()
  790. */
  791. #include <linux/vmstat.h>
  792. static __always_inline void *lowmem_page_address(const struct page *page)
  793. {
  794. return __va(PFN_PHYS(page_to_pfn(page)));
  795. }
  796. #if defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL)
  797. #define HASHED_PAGE_VIRTUAL
  798. #endif
  799. #if defined(WANT_PAGE_VIRTUAL)
  800. static inline void *page_address(const struct page *page)
  801. {
  802. return page->virtual;
  803. }
  804. static inline void set_page_address(struct page *page, void *address)
  805. {
  806. page->virtual = address;
  807. }
  808. #define page_address_init() do { } while(0)
  809. #endif
  810. #if defined(HASHED_PAGE_VIRTUAL)
  811. void *page_address(const struct page *page);
  812. void set_page_address(struct page *page, void *virtual);
  813. void page_address_init(void);
  814. #endif
  815. #if !defined(HASHED_PAGE_VIRTUAL) && !defined(WANT_PAGE_VIRTUAL)
  816. #define page_address(page) lowmem_page_address(page)
  817. #define set_page_address(page, address) do { } while(0)
  818. #define page_address_init() do { } while(0)
  819. #endif
  820. extern void *page_rmapping(struct page *page);
  821. extern struct anon_vma *page_anon_vma(struct page *page);
  822. extern struct address_space *page_mapping(struct page *page);
  823. extern struct address_space *__page_file_mapping(struct page *);
  824. static inline
  825. struct address_space *page_file_mapping(struct page *page)
  826. {
  827. if (unlikely(PageSwapCache(page)))
  828. return __page_file_mapping(page);
  829. return page->mapping;
  830. }
  831. /*
  832. * Return the pagecache index of the passed page. Regular pagecache pages
  833. * use ->index whereas swapcache pages use ->private
  834. */
  835. static inline pgoff_t page_index(struct page *page)
  836. {
  837. if (unlikely(PageSwapCache(page)))
  838. return page_private(page);
  839. return page->index;
  840. }
  841. extern pgoff_t __page_file_index(struct page *page);
  842. /*
  843. * Return the file index of the page. Regular pagecache pages use ->index
  844. * whereas swapcache pages use swp_offset(->private)
  845. */
  846. static inline pgoff_t page_file_index(struct page *page)
  847. {
  848. if (unlikely(PageSwapCache(page)))
  849. return __page_file_index(page);
  850. return page->index;
  851. }
  852. /*
  853. * Return true if this page is mapped into pagetables.
  854. */
  855. static inline int page_mapped(struct page *page)
  856. {
  857. return atomic_read(&(page)->_mapcount) >= 0;
  858. }
  859. /*
  860. * Return true only if the page has been allocated with
  861. * ALLOC_NO_WATERMARKS and the low watermark was not
  862. * met implying that the system is under some pressure.
  863. */
  864. static inline bool page_is_pfmemalloc(struct page *page)
  865. {
  866. /*
  867. * Page index cannot be this large so this must be
  868. * a pfmemalloc page.
  869. */
  870. return page->index == -1UL;
  871. }
  872. /*
  873. * Only to be called by the page allocator on a freshly allocated
  874. * page.
  875. */
  876. static inline void set_page_pfmemalloc(struct page *page)
  877. {
  878. page->index = -1UL;
  879. }
  880. static inline void clear_page_pfmemalloc(struct page *page)
  881. {
  882. page->index = 0;
  883. }
  884. /*
  885. * Different kinds of faults, as returned by handle_mm_fault().
  886. * Used to decide whether a process gets delivered SIGBUS or
  887. * just gets major/minor fault counters bumped up.
  888. */
  889. #define VM_FAULT_MINOR 0 /* For backwards compat. Remove me quickly. */
  890. #define VM_FAULT_OOM 0x0001
  891. #define VM_FAULT_SIGBUS 0x0002
  892. #define VM_FAULT_MAJOR 0x0004
  893. #define VM_FAULT_WRITE 0x0008 /* Special case for get_user_pages */
  894. #define VM_FAULT_HWPOISON 0x0010 /* Hit poisoned small page */
  895. #define VM_FAULT_HWPOISON_LARGE 0x0020 /* Hit poisoned large page. Index encoded in upper bits */
  896. #define VM_FAULT_SIGSEGV 0x0040
  897. #define VM_FAULT_NOPAGE 0x0100 /* ->fault installed the pte, not return page */
  898. #define VM_FAULT_LOCKED 0x0200 /* ->fault locked the returned page */
  899. #define VM_FAULT_RETRY 0x0400 /* ->fault blocked, must retry */
  900. #define VM_FAULT_FALLBACK 0x0800 /* huge page fault failed, fall back to small */
  901. #define VM_FAULT_HWPOISON_LARGE_MASK 0xf000 /* encodes hpage index for large hwpoison */
  902. #define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV | \
  903. VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE | \
  904. VM_FAULT_FALLBACK)
  905. /* Encode hstate index for a hwpoisoned large page */
  906. #define VM_FAULT_SET_HINDEX(x) ((x) << 12)
  907. #define VM_FAULT_GET_HINDEX(x) (((x) >> 12) & 0xf)
  908. /*
  909. * Can be called by the pagefault handler when it gets a VM_FAULT_OOM.
  910. */
  911. extern void pagefault_out_of_memory(void);
  912. #define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
  913. /*
  914. * Flags passed to show_mem() and show_free_areas() to suppress output in
  915. * various contexts.
  916. */
  917. #define SHOW_MEM_FILTER_NODES (0x0001u) /* disallowed nodes */
  918. extern void show_free_areas(unsigned int flags);
  919. extern bool skip_free_areas_node(unsigned int flags, int nid);
  920. int shmem_zero_setup(struct vm_area_struct *);
  921. #ifdef CONFIG_SHMEM
  922. bool shmem_mapping(struct address_space *mapping);
  923. #else
  924. static inline bool shmem_mapping(struct address_space *mapping)
  925. {
  926. return false;
  927. }
  928. #endif
  929. extern int can_do_mlock(void);
  930. extern int user_shm_lock(size_t, struct user_struct *);
  931. extern void user_shm_unlock(size_t, struct user_struct *);
  932. /*
  933. * Parameter block passed down to zap_pte_range in exceptional cases.
  934. */
  935. struct zap_details {
  936. struct address_space *check_mapping; /* Check page->mapping if set */
  937. pgoff_t first_index; /* Lowest page->index to unmap */
  938. pgoff_t last_index; /* Highest page->index to unmap */
  939. };
  940. struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr,
  941. pte_t pte);
  942. int zap_vma_ptes(struct vm_area_struct *vma, unsigned long address,
  943. unsigned long size);
  944. void zap_page_range(struct vm_area_struct *vma, unsigned long address,
  945. unsigned long size, struct zap_details *);
  946. void unmap_vmas(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
  947. unsigned long start, unsigned long end);
  948. /**
  949. * mm_walk - callbacks for walk_page_range
  950. * @pmd_entry: if set, called for each non-empty PMD (3rd-level) entry
  951. * this handler is required to be able to handle
  952. * pmd_trans_huge() pmds. They may simply choose to
  953. * split_huge_page() instead of handling it explicitly.
  954. * @pte_entry: if set, called for each non-empty PTE (4th-level) entry
  955. * @pte_hole: if set, called for each hole at all levels
  956. * @hugetlb_entry: if set, called for each hugetlb entry
  957. * @test_walk: caller specific callback function to determine whether
  958. * we walk over the current vma or not. A positive returned
  959. * value means "do page table walk over the current vma,"
  960. * and a negative one means "abort current page table walk
  961. * right now." 0 means "skip the current vma."
  962. * @mm: mm_struct representing the target process of page table walk
  963. * @vma: vma currently walked (NULL if walking outside vmas)
  964. * @private: private data for callbacks' usage
  965. *
  966. * (see the comment on walk_page_range() for more details)
  967. */
  968. struct mm_walk {
  969. int (*pmd_entry)(pmd_t *pmd, unsigned long addr,
  970. unsigned long next, struct mm_walk *walk);
  971. int (*pte_entry)(pte_t *pte, unsigned long addr,
  972. unsigned long next, struct mm_walk *walk);
  973. int (*pte_hole)(unsigned long addr, unsigned long next,
  974. struct mm_walk *walk);
  975. int (*hugetlb_entry)(pte_t *pte, unsigned long hmask,
  976. unsigned long addr, unsigned long next,
  977. struct mm_walk *walk);
  978. int (*test_walk)(unsigned long addr, unsigned long next,
  979. struct mm_walk *walk);
  980. struct mm_struct *mm;
  981. struct vm_area_struct *vma;
  982. void *private;
  983. };
  984. int walk_page_range(unsigned long addr, unsigned long end,
  985. struct mm_walk *walk);
  986. int walk_page_vma(struct vm_area_struct *vma, struct mm_walk *walk);
  987. void free_pgd_range(struct mmu_gather *tlb, unsigned long addr,
  988. unsigned long end, unsigned long floor, unsigned long ceiling);
  989. int copy_page_range(struct mm_struct *dst, struct mm_struct *src,
  990. struct vm_area_struct *vma);
  991. void unmap_mapping_range(struct address_space *mapping,
  992. loff_t const holebegin, loff_t const holelen, int even_cows);
  993. int follow_pfn(struct vm_area_struct *vma, unsigned long address,
  994. unsigned long *pfn);
  995. int follow_phys(struct vm_area_struct *vma, unsigned long address,
  996. unsigned int flags, unsigned long *prot, resource_size_t *phys);
  997. int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
  998. void *buf, int len, int write);
  999. static inline void unmap_shared_mapping_range(struct address_space *mapping,
  1000. loff_t const holebegin, loff_t const holelen)
  1001. {
  1002. unmap_mapping_range(mapping, holebegin, holelen, 0);
  1003. }
  1004. extern void truncate_pagecache(struct inode *inode, loff_t new);
  1005. extern void truncate_setsize(struct inode *inode, loff_t newsize);
  1006. void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to);
  1007. void truncate_pagecache_range(struct inode *inode, loff_t offset, loff_t end);
  1008. int truncate_inode_page(struct address_space *mapping, struct page *page);
  1009. int generic_error_remove_page(struct address_space *mapping, struct page *page);
  1010. int invalidate_inode_page(struct page *page);
  1011. #ifdef CONFIG_MMU
  1012. extern int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
  1013. unsigned long address, unsigned int flags);
  1014. extern int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
  1015. unsigned long address, unsigned int fault_flags);
  1016. #else
  1017. static inline int handle_mm_fault(struct mm_struct *mm,
  1018. struct vm_area_struct *vma, unsigned long address,
  1019. unsigned int flags)
  1020. {
  1021. /* should never happen if there's no MMU */
  1022. BUG();
  1023. return VM_FAULT_SIGBUS;
  1024. }
  1025. static inline int fixup_user_fault(struct task_struct *tsk,
  1026. struct mm_struct *mm, unsigned long address,
  1027. unsigned int fault_flags)
  1028. {
  1029. /* should never happen if there's no MMU */
  1030. BUG();
  1031. return -EFAULT;
  1032. }
  1033. #endif
  1034. extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
  1035. extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
  1036. void *buf, int len, int write);
  1037. long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
  1038. unsigned long start, unsigned long nr_pages,
  1039. unsigned int foll_flags, struct page **pages,
  1040. struct vm_area_struct **vmas, int *nonblocking);
  1041. long get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
  1042. unsigned long start, unsigned long nr_pages,
  1043. int write, int force, struct page **pages,
  1044. struct vm_area_struct **vmas);
  1045. long get_user_pages_locked(struct task_struct *tsk, struct mm_struct *mm,
  1046. unsigned long start, unsigned long nr_pages,
  1047. int write, int force, struct page **pages,
  1048. int *locked);
  1049. long __get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
  1050. unsigned long start, unsigned long nr_pages,
  1051. int write, int force, struct page **pages,
  1052. unsigned int gup_flags);
  1053. long get_user_pages_unlocked(struct task_struct *tsk, struct mm_struct *mm,
  1054. unsigned long start, unsigned long nr_pages,
  1055. int write, int force, struct page **pages);
  1056. int get_user_pages_fast(unsigned long start, int nr_pages, int write,
  1057. struct page **pages);
  1058. struct kvec;
  1059. int get_kernel_pages(const struct kvec *iov, int nr_pages, int write,
  1060. struct page **pages);
  1061. int get_kernel_page(unsigned long start, int write, struct page **pages);
  1062. struct page *get_dump_page(unsigned long addr);
  1063. extern int try_to_release_page(struct page * page, gfp_t gfp_mask);
  1064. extern void do_invalidatepage(struct page *page, unsigned int offset,
  1065. unsigned int length);
  1066. int __set_page_dirty_nobuffers(struct page *page);
  1067. int __set_page_dirty_no_writeback(struct page *page);
  1068. int redirty_page_for_writepage(struct writeback_control *wbc,
  1069. struct page *page);
  1070. void account_page_dirtied(struct page *page, struct address_space *mapping,
  1071. struct mem_cgroup *memcg);
  1072. void account_page_cleaned(struct page *page, struct address_space *mapping,
  1073. struct mem_cgroup *memcg, struct bdi_writeback *wb);
  1074. int set_page_dirty(struct page *page);
  1075. int set_page_dirty_lock(struct page *page);
  1076. void cancel_dirty_page(struct page *page);
  1077. int clear_page_dirty_for_io(struct page *page);
  1078. int get_cmdline(struct task_struct *task, char *buffer, int buflen);
  1079. /* Is the vma a continuation of the stack vma above it? */
  1080. static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
  1081. {
  1082. return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
  1083. }
  1084. static inline int stack_guard_page_start(struct vm_area_struct *vma,
  1085. unsigned long addr)
  1086. {
  1087. return (vma->vm_flags & VM_GROWSDOWN) &&
  1088. (vma->vm_start == addr) &&
  1089. !vma_growsdown(vma->vm_prev, addr);
  1090. }
  1091. /* Is the vma a continuation of the stack vma below it? */
  1092. static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
  1093. {
  1094. return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
  1095. }
  1096. static inline int stack_guard_page_end(struct vm_area_struct *vma,
  1097. unsigned long addr)
  1098. {
  1099. return (vma->vm_flags & VM_GROWSUP) &&
  1100. (vma->vm_end == addr) &&
  1101. !vma_growsup(vma->vm_next, addr);
  1102. }
  1103. extern struct task_struct *task_of_stack(struct task_struct *task,
  1104. struct vm_area_struct *vma, bool in_group);
  1105. extern unsigned long move_page_tables(struct vm_area_struct *vma,
  1106. unsigned long old_addr, struct vm_area_struct *new_vma,
  1107. unsigned long new_addr, unsigned long len,
  1108. bool need_rmap_locks);
  1109. extern unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
  1110. unsigned long end, pgprot_t newprot,
  1111. int dirty_accountable, int prot_numa);
  1112. extern int mprotect_fixup(struct vm_area_struct *vma,
  1113. struct vm_area_struct **pprev, unsigned long start,
  1114. unsigned long end, unsigned long newflags);
  1115. /*
  1116. * doesn't attempt to fault and will return short.
  1117. */
  1118. int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
  1119. struct page **pages);
  1120. /*
  1121. * per-process(per-mm_struct) statistics.
  1122. */
  1123. static inline unsigned long get_mm_counter(struct mm_struct *mm, int member)
  1124. {
  1125. long val = atomic_long_read(&mm->rss_stat.count[member]);
  1126. #ifdef SPLIT_RSS_COUNTING
  1127. /*
  1128. * counter is updated in asynchronous manner and may go to minus.
  1129. * But it's never be expected number for users.
  1130. */
  1131. if (val < 0)
  1132. val = 0;
  1133. #endif
  1134. return (unsigned long)val;
  1135. }
  1136. static inline void add_mm_counter(struct mm_struct *mm, int member, long value)
  1137. {
  1138. atomic_long_add(value, &mm->rss_stat.count[member]);
  1139. }
  1140. static inline void inc_mm_counter(struct mm_struct *mm, int member)
  1141. {
  1142. atomic_long_inc(&mm->rss_stat.count[member]);
  1143. }
  1144. static inline void dec_mm_counter(struct mm_struct *mm, int member)
  1145. {
  1146. atomic_long_dec(&mm->rss_stat.count[member]);
  1147. }
  1148. static inline unsigned long get_mm_rss(struct mm_struct *mm)
  1149. {
  1150. return get_mm_counter(mm, MM_FILEPAGES) +
  1151. get_mm_counter(mm, MM_ANONPAGES);
  1152. }
  1153. static inline unsigned long get_mm_hiwater_rss(struct mm_struct *mm)
  1154. {
  1155. return max(mm->hiwater_rss, get_mm_rss(mm));
  1156. }
  1157. static inline unsigned long get_mm_hiwater_vm(struct mm_struct *mm)
  1158. {
  1159. return max(mm->hiwater_vm, mm->total_vm);
  1160. }
  1161. static inline void update_hiwater_rss(struct mm_struct *mm)
  1162. {
  1163. unsigned long _rss = get_mm_rss(mm);
  1164. if ((mm)->hiwater_rss < _rss)
  1165. (mm)->hiwater_rss = _rss;
  1166. }
  1167. static inline void update_hiwater_vm(struct mm_struct *mm)
  1168. {
  1169. if (mm->hiwater_vm < mm->total_vm)
  1170. mm->hiwater_vm = mm->total_vm;
  1171. }
  1172. static inline void reset_mm_hiwater_rss(struct mm_struct *mm)
  1173. {
  1174. mm->hiwater_rss = get_mm_rss(mm);
  1175. }
  1176. static inline void setmax_mm_hiwater_rss(unsigned long *maxrss,
  1177. struct mm_struct *mm)
  1178. {
  1179. unsigned long hiwater_rss = get_mm_hiwater_rss(mm);
  1180. if (*maxrss < hiwater_rss)
  1181. *maxrss = hiwater_rss;
  1182. }
  1183. #if defined(SPLIT_RSS_COUNTING)
  1184. void sync_mm_rss(struct mm_struct *mm);
  1185. #else
  1186. static inline void sync_mm_rss(struct mm_struct *mm)
  1187. {
  1188. }
  1189. #endif
  1190. int vma_wants_writenotify(struct vm_area_struct *vma);
  1191. extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
  1192. spinlock_t **ptl);
  1193. static inline pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr,
  1194. spinlock_t **ptl)
  1195. {
  1196. pte_t *ptep;
  1197. __cond_lock(*ptl, ptep = __get_locked_pte(mm, addr, ptl));
  1198. return ptep;
  1199. }
  1200. #ifdef __PAGETABLE_PUD_FOLDED
  1201. static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
  1202. unsigned long address)
  1203. {
  1204. return 0;
  1205. }
  1206. #else
  1207. int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
  1208. #endif
  1209. #if defined(__PAGETABLE_PMD_FOLDED) || !defined(CONFIG_MMU)
  1210. static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
  1211. unsigned long address)
  1212. {
  1213. return 0;
  1214. }
  1215. static inline void mm_nr_pmds_init(struct mm_struct *mm) {}
  1216. static inline unsigned long mm_nr_pmds(struct mm_struct *mm)
  1217. {
  1218. return 0;
  1219. }
  1220. static inline void mm_inc_nr_pmds(struct mm_struct *mm) {}
  1221. static inline void mm_dec_nr_pmds(struct mm_struct *mm) {}
  1222. #else
  1223. int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
  1224. static inline void mm_nr_pmds_init(struct mm_struct *mm)
  1225. {
  1226. atomic_long_set(&mm->nr_pmds, 0);
  1227. }
  1228. static inline unsigned long mm_nr_pmds(struct mm_struct *mm)
  1229. {
  1230. return atomic_long_read(&mm->nr_pmds);
  1231. }
  1232. static inline void mm_inc_nr_pmds(struct mm_struct *mm)
  1233. {
  1234. atomic_long_inc(&mm->nr_pmds);
  1235. }
  1236. static inline void mm_dec_nr_pmds(struct mm_struct *mm)
  1237. {
  1238. atomic_long_dec(&mm->nr_pmds);
  1239. }
  1240. #endif
  1241. int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
  1242. pmd_t *pmd, unsigned long address);
  1243. int __pte_alloc_kernel(pmd_t *pmd, unsigned long address);
  1244. /*
  1245. * The following ifdef needed to get the 4level-fixup.h header to work.
  1246. * Remove it when 4level-fixup.h has been removed.
  1247. */
  1248. #if defined(CONFIG_MMU) && !defined(__ARCH_HAS_4LEVEL_HACK)
  1249. static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
  1250. {
  1251. return (unlikely(pgd_none(*pgd)) && __pud_alloc(mm, pgd, address))?
  1252. NULL: pud_offset(pgd, address);
  1253. }
  1254. static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
  1255. {
  1256. return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
  1257. NULL: pmd_offset(pud, address);
  1258. }
  1259. #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
  1260. #if USE_SPLIT_PTE_PTLOCKS
  1261. #if ALLOC_SPLIT_PTLOCKS
  1262. void __init ptlock_cache_init(void);
  1263. extern bool ptlock_alloc(struct page *page);
  1264. extern void ptlock_free(struct page *page);
  1265. static inline spinlock_t *ptlock_ptr(struct page *page)
  1266. {
  1267. return page->ptl;
  1268. }
  1269. #else /* ALLOC_SPLIT_PTLOCKS */
  1270. static inline void ptlock_cache_init(void)
  1271. {
  1272. }
  1273. static inline bool ptlock_alloc(struct page *page)
  1274. {
  1275. return true;
  1276. }
  1277. static inline void ptlock_free(struct page *page)
  1278. {
  1279. }
  1280. static inline spinlock_t *ptlock_ptr(struct page *page)
  1281. {
  1282. return &page->ptl;
  1283. }
  1284. #endif /* ALLOC_SPLIT_PTLOCKS */
  1285. static inline spinlock_t *pte_lockptr(struct mm_struct *mm, pmd_t *pmd)
  1286. {
  1287. return ptlock_ptr(pmd_page(*pmd));
  1288. }
  1289. static inline bool ptlock_init(struct page *page)
  1290. {
  1291. /*
  1292. * prep_new_page() initialize page->private (and therefore page->ptl)
  1293. * with 0. Make sure nobody took it in use in between.
  1294. *
  1295. * It can happen if arch try to use slab for page table allocation:
  1296. * slab code uses page->slab_cache and page->first_page (for tail
  1297. * pages), which share storage with page->ptl.
  1298. */
  1299. VM_BUG_ON_PAGE(*(unsigned long *)&page->ptl, page);
  1300. if (!ptlock_alloc(page))
  1301. return false;
  1302. spin_lock_init(ptlock_ptr(page));
  1303. return true;
  1304. }
  1305. /* Reset page->mapping so free_pages_check won't complain. */
  1306. static inline void pte_lock_deinit(struct page *page)
  1307. {
  1308. page->mapping = NULL;
  1309. ptlock_free(page);
  1310. }
  1311. #else /* !USE_SPLIT_PTE_PTLOCKS */
  1312. /*
  1313. * We use mm->page_table_lock to guard all pagetable pages of the mm.
  1314. */
  1315. static inline spinlock_t *pte_lockptr(struct mm_struct *mm, pmd_t *pmd)
  1316. {
  1317. return &mm->page_table_lock;
  1318. }
  1319. static inline void ptlock_cache_init(void) {}
  1320. static inline bool ptlock_init(struct page *page) { return true; }
  1321. static inline void pte_lock_deinit(struct page *page) {}
  1322. #endif /* USE_SPLIT_PTE_PTLOCKS */
  1323. static inline void pgtable_init(void)
  1324. {
  1325. ptlock_cache_init();
  1326. pgtable_cache_init();
  1327. }
  1328. static inline bool pgtable_page_ctor(struct page *page)
  1329. {
  1330. inc_zone_page_state(page, NR_PAGETABLE);
  1331. return ptlock_init(page);
  1332. }
  1333. static inline void pgtable_page_dtor(struct page *page)
  1334. {
  1335. pte_lock_deinit(page);
  1336. dec_zone_page_state(page, NR_PAGETABLE);
  1337. }
  1338. #define pte_offset_map_lock(mm, pmd, address, ptlp) \
  1339. ({ \
  1340. spinlock_t *__ptl = pte_lockptr(mm, pmd); \
  1341. pte_t *__pte = pte_offset_map(pmd, address); \
  1342. *(ptlp) = __ptl; \
  1343. spin_lock(__ptl); \
  1344. __pte; \
  1345. })
  1346. #define pte_unmap_unlock(pte, ptl) do { \
  1347. spin_unlock(ptl); \
  1348. pte_unmap(pte); \
  1349. } while (0)
  1350. #define pte_alloc_map(mm, vma, pmd, address) \
  1351. ((unlikely(pmd_none(*(pmd))) && __pte_alloc(mm, vma, \
  1352. pmd, address))? \
  1353. NULL: pte_offset_map(pmd, address))
  1354. #define pte_alloc_map_lock(mm, pmd, address, ptlp) \
  1355. ((unlikely(pmd_none(*(pmd))) && __pte_alloc(mm, NULL, \
  1356. pmd, address))? \
  1357. NULL: pte_offset_map_lock(mm, pmd, address, ptlp))
  1358. #define pte_alloc_kernel(pmd, address) \
  1359. ((unlikely(pmd_none(*(pmd))) && __pte_alloc_kernel(pmd, address))? \
  1360. NULL: pte_offset_kernel(pmd, address))
  1361. #if USE_SPLIT_PMD_PTLOCKS
  1362. static struct page *pmd_to_page(pmd_t *pmd)
  1363. {
  1364. unsigned long mask = ~(PTRS_PER_PMD * sizeof(pmd_t) - 1);
  1365. return virt_to_page((void *)((unsigned long) pmd & mask));
  1366. }
  1367. static inline spinlock_t *pmd_lockptr(struct mm_struct *mm, pmd_t *pmd)
  1368. {
  1369. return ptlock_ptr(pmd_to_page(pmd));
  1370. }
  1371. static inline bool pgtable_pmd_page_ctor(struct page *page)
  1372. {
  1373. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  1374. page->pmd_huge_pte = NULL;
  1375. #endif
  1376. return ptlock_init(page);
  1377. }
  1378. static inline void pgtable_pmd_page_dtor(struct page *page)
  1379. {
  1380. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  1381. VM_BUG_ON_PAGE(page->pmd_huge_pte, page);
  1382. #endif
  1383. ptlock_free(page);
  1384. }
  1385. #define pmd_huge_pte(mm, pmd) (pmd_to_page(pmd)->pmd_huge_pte)
  1386. #else
  1387. static inline spinlock_t *pmd_lockptr(struct mm_struct *mm, pmd_t *pmd)
  1388. {
  1389. return &mm->page_table_lock;
  1390. }
  1391. static inline bool pgtable_pmd_page_ctor(struct page *page) { return true; }
  1392. static inline void pgtable_pmd_page_dtor(struct page *page) {}
  1393. #define pmd_huge_pte(mm, pmd) ((mm)->pmd_huge_pte)
  1394. #endif
  1395. static inline spinlock_t *pmd_lock(struct mm_struct *mm, pmd_t *pmd)
  1396. {
  1397. spinlock_t *ptl = pmd_lockptr(mm, pmd);
  1398. spin_lock(ptl);
  1399. return ptl;
  1400. }
  1401. extern void free_area_init(unsigned long * zones_size);
  1402. extern void free_area_init_node(int nid, unsigned long * zones_size,
  1403. unsigned long zone_start_pfn, unsigned long *zholes_size);
  1404. extern void free_initmem(void);
  1405. /*
  1406. * Free reserved pages within range [PAGE_ALIGN(start), end & PAGE_MASK)
  1407. * into the buddy system. The freed pages will be poisoned with pattern
  1408. * "poison" if it's within range [0, UCHAR_MAX].
  1409. * Return pages freed into the buddy system.
  1410. */
  1411. extern unsigned long free_reserved_area(void *start, void *end,
  1412. int poison, char *s);
  1413. #ifdef CONFIG_HIGHMEM
  1414. /*
  1415. * Free a highmem page into the buddy system, adjusting totalhigh_pages
  1416. * and totalram_pages.
  1417. */
  1418. extern void free_highmem_page(struct page *page);
  1419. #endif
  1420. extern void adjust_managed_page_count(struct page *page, long count);
  1421. extern void mem_init_print_info(const char *str);
  1422. extern void reserve_bootmem_region(unsigned long start, unsigned long end);
  1423. /* Free the reserved page into the buddy system, so it gets managed. */
  1424. static inline void __free_reserved_page(struct page *page)
  1425. {
  1426. ClearPageReserved(page);
  1427. init_page_count(page);
  1428. __free_page(page);
  1429. }
  1430. static inline void free_reserved_page(struct page *page)
  1431. {
  1432. __free_reserved_page(page);
  1433. adjust_managed_page_count(page, 1);
  1434. }
  1435. static inline void mark_page_reserved(struct page *page)
  1436. {
  1437. SetPageReserved(page);
  1438. adjust_managed_page_count(page, -1);
  1439. }
  1440. /*
  1441. * Default method to free all the __init memory into the buddy system.
  1442. * The freed pages will be poisoned with pattern "poison" if it's within
  1443. * range [0, UCHAR_MAX].
  1444. * Return pages freed into the buddy system.
  1445. */
  1446. static inline unsigned long free_initmem_default(int poison)
  1447. {
  1448. extern char __init_begin[], __init_end[];
  1449. return free_reserved_area(&__init_begin, &__init_end,
  1450. poison, "unused kernel");
  1451. }
  1452. static inline unsigned long get_num_physpages(void)
  1453. {
  1454. int nid;
  1455. unsigned long phys_pages = 0;
  1456. for_each_online_node(nid)
  1457. phys_pages += node_present_pages(nid);
  1458. return phys_pages;
  1459. }
  1460. #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
  1461. /*
  1462. * With CONFIG_HAVE_MEMBLOCK_NODE_MAP set, an architecture may initialise its
  1463. * zones, allocate the backing mem_map and account for memory holes in a more
  1464. * architecture independent manner. This is a substitute for creating the
  1465. * zone_sizes[] and zholes_size[] arrays and passing them to
  1466. * free_area_init_node()
  1467. *
  1468. * An architecture is expected to register range of page frames backed by
  1469. * physical memory with memblock_add[_node]() before calling
  1470. * free_area_init_nodes() passing in the PFN each zone ends at. At a basic
  1471. * usage, an architecture is expected to do something like
  1472. *
  1473. * unsigned long max_zone_pfns[MAX_NR_ZONES] = {max_dma, max_normal_pfn,
  1474. * max_highmem_pfn};
  1475. * for_each_valid_physical_page_range()
  1476. * memblock_add_node(base, size, nid)
  1477. * free_area_init_nodes(max_zone_pfns);
  1478. *
  1479. * free_bootmem_with_active_regions() calls free_bootmem_node() for each
  1480. * registered physical page range. Similarly
  1481. * sparse_memory_present_with_active_regions() calls memory_present() for
  1482. * each range when SPARSEMEM is enabled.
  1483. *
  1484. * See mm/page_alloc.c for more information on each function exposed by
  1485. * CONFIG_HAVE_MEMBLOCK_NODE_MAP.
  1486. */
  1487. extern void free_area_init_nodes(unsigned long *max_zone_pfn);
  1488. unsigned long node_map_pfn_alignment(void);
  1489. unsigned long __absent_pages_in_range(int nid, unsigned long start_pfn,
  1490. unsigned long end_pfn);
  1491. extern unsigned long absent_pages_in_range(unsigned long start_pfn,
  1492. unsigned long end_pfn);
  1493. extern void get_pfn_range_for_nid(unsigned int nid,
  1494. unsigned long *start_pfn, unsigned long *end_pfn);
  1495. extern unsigned long find_min_pfn_with_active_regions(void);
  1496. extern void free_bootmem_with_active_regions(int nid,
  1497. unsigned long max_low_pfn);
  1498. extern void sparse_memory_present_with_active_regions(int nid);
  1499. #endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */
  1500. #if !defined(CONFIG_HAVE_MEMBLOCK_NODE_MAP) && \
  1501. !defined(CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID)
  1502. static inline int __early_pfn_to_nid(unsigned long pfn,
  1503. struct mminit_pfnnid_cache *state)
  1504. {
  1505. return 0;
  1506. }
  1507. #else
  1508. /* please see mm/page_alloc.c */
  1509. extern int __meminit early_pfn_to_nid(unsigned long pfn);
  1510. /* there is a per-arch backend function. */
  1511. extern int __meminit __early_pfn_to_nid(unsigned long pfn,
  1512. struct mminit_pfnnid_cache *state);
  1513. #endif
  1514. extern void set_dma_reserve(unsigned long new_dma_reserve);
  1515. extern void memmap_init_zone(unsigned long, int, unsigned long,
  1516. unsigned long, enum memmap_context);
  1517. extern void setup_per_zone_wmarks(void);
  1518. extern int __meminit init_per_zone_wmark_min(void);
  1519. extern void mem_init(void);
  1520. extern void __init mmap_init(void);
  1521. extern void show_mem(unsigned int flags);
  1522. extern void si_meminfo(struct sysinfo * val);
  1523. extern void si_meminfo_node(struct sysinfo *val, int nid);
  1524. extern __printf(3, 4)
  1525. void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...);
  1526. extern void setup_per_cpu_pageset(void);
  1527. extern void zone_pcp_update(struct zone *zone);
  1528. extern void zone_pcp_reset(struct zone *zone);
  1529. /* page_alloc.c */
  1530. extern int min_free_kbytes;
  1531. /* nommu.c */
  1532. extern atomic_long_t mmap_pages_allocated;
  1533. extern int nommu_shrink_inode_mappings(struct inode *, size_t, size_t);
  1534. /* interval_tree.c */
  1535. void vma_interval_tree_insert(struct vm_area_struct *node,
  1536. struct rb_root *root);
  1537. void vma_interval_tree_insert_after(struct vm_area_struct *node,
  1538. struct vm_area_struct *prev,
  1539. struct rb_root *root);
  1540. void vma_interval_tree_remove(struct vm_area_struct *node,
  1541. struct rb_root *root);
  1542. struct vm_area_struct *vma_interval_tree_iter_first(struct rb_root *root,
  1543. unsigned long start, unsigned long last);
  1544. struct vm_area_struct *vma_interval_tree_iter_next(struct vm_area_struct *node,
  1545. unsigned long start, unsigned long last);
  1546. #define vma_interval_tree_foreach(vma, root, start, last) \
  1547. for (vma = vma_interval_tree_iter_first(root, start, last); \
  1548. vma; vma = vma_interval_tree_iter_next(vma, start, last))
  1549. void anon_vma_interval_tree_insert(struct anon_vma_chain *node,
  1550. struct rb_root *root);
  1551. void anon_vma_interval_tree_remove(struct anon_vma_chain *node,
  1552. struct rb_root *root);
  1553. struct anon_vma_chain *anon_vma_interval_tree_iter_first(
  1554. struct rb_root *root, unsigned long start, unsigned long last);
  1555. struct anon_vma_chain *anon_vma_interval_tree_iter_next(
  1556. struct anon_vma_chain *node, unsigned long start, unsigned long last);
  1557. #ifdef CONFIG_DEBUG_VM_RB
  1558. void anon_vma_interval_tree_verify(struct anon_vma_chain *node);
  1559. #endif
  1560. #define anon_vma_interval_tree_foreach(avc, root, start, last) \
  1561. for (avc = anon_vma_interval_tree_iter_first(root, start, last); \
  1562. avc; avc = anon_vma_interval_tree_iter_next(avc, start, last))
  1563. /* mmap.c */
  1564. extern int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin);
  1565. extern int vma_adjust(struct vm_area_struct *vma, unsigned long start,
  1566. unsigned long end, pgoff_t pgoff, struct vm_area_struct *insert);
  1567. extern struct vm_area_struct *vma_merge(struct mm_struct *,
  1568. struct vm_area_struct *prev, unsigned long addr, unsigned long end,
  1569. unsigned long vm_flags, struct anon_vma *, struct file *, pgoff_t,
  1570. struct mempolicy *);
  1571. extern struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *);
  1572. extern int split_vma(struct mm_struct *,
  1573. struct vm_area_struct *, unsigned long addr, int new_below);
  1574. extern int insert_vm_struct(struct mm_struct *, struct vm_area_struct *);
  1575. extern void __vma_link_rb(struct mm_struct *, struct vm_area_struct *,
  1576. struct rb_node **, struct rb_node *);
  1577. extern void unlink_file_vma(struct vm_area_struct *);
  1578. extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
  1579. unsigned long addr, unsigned long len, pgoff_t pgoff,
  1580. bool *need_rmap_locks);
  1581. extern void exit_mmap(struct mm_struct *);
  1582. static inline int check_data_rlimit(unsigned long rlim,
  1583. unsigned long new,
  1584. unsigned long start,
  1585. unsigned long end_data,
  1586. unsigned long start_data)
  1587. {
  1588. if (rlim < RLIM_INFINITY) {
  1589. if (((new - start) + (end_data - start_data)) > rlim)
  1590. return -ENOSPC;
  1591. }
  1592. return 0;
  1593. }
  1594. extern int mm_take_all_locks(struct mm_struct *mm);
  1595. extern void mm_drop_all_locks(struct mm_struct *mm);
  1596. extern void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file);
  1597. extern struct file *get_mm_exe_file(struct mm_struct *mm);
  1598. extern int may_expand_vm(struct mm_struct *mm, unsigned long npages);
  1599. extern struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
  1600. unsigned long addr, unsigned long len,
  1601. unsigned long flags,
  1602. const struct vm_special_mapping *spec);
  1603. /* This is an obsolete alternative to _install_special_mapping. */
  1604. extern int install_special_mapping(struct mm_struct *mm,
  1605. unsigned long addr, unsigned long len,
  1606. unsigned long flags, struct page **pages);
  1607. extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
  1608. extern unsigned long mmap_region(struct file *file, unsigned long addr,
  1609. unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
  1610. extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
  1611. unsigned long len, unsigned long prot, unsigned long flags,
  1612. unsigned long pgoff, unsigned long *populate);
  1613. extern int do_munmap(struct mm_struct *, unsigned long, size_t);
  1614. #ifdef CONFIG_MMU
  1615. extern int __mm_populate(unsigned long addr, unsigned long len,
  1616. int ignore_errors);
  1617. static inline void mm_populate(unsigned long addr, unsigned long len)
  1618. {
  1619. /* Ignore errors */
  1620. (void) __mm_populate(addr, len, 1);
  1621. }
  1622. #else
  1623. static inline void mm_populate(unsigned long addr, unsigned long len) {}
  1624. #endif
  1625. /* These take the mm semaphore themselves */
  1626. extern unsigned long vm_brk(unsigned long, unsigned long);
  1627. extern int vm_munmap(unsigned long, size_t);
  1628. extern unsigned long vm_mmap(struct file *, unsigned long,
  1629. unsigned long, unsigned long,
  1630. unsigned long, unsigned long);
  1631. struct vm_unmapped_area_info {
  1632. #define VM_UNMAPPED_AREA_TOPDOWN 1
  1633. unsigned long flags;
  1634. unsigned long length;
  1635. unsigned long low_limit;
  1636. unsigned long high_limit;
  1637. unsigned long align_mask;
  1638. unsigned long align_offset;
  1639. };
  1640. extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
  1641. extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
  1642. /*
  1643. * Search for an unmapped address range.
  1644. *
  1645. * We are looking for a range that:
  1646. * - does not intersect with any VMA;
  1647. * - is contained within the [low_limit, high_limit) interval;
  1648. * - is at least the desired size.
  1649. * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
  1650. */
  1651. static inline unsigned long
  1652. vm_unmapped_area(struct vm_unmapped_area_info *info)
  1653. {
  1654. if (info->flags & VM_UNMAPPED_AREA_TOPDOWN)
  1655. return unmapped_area_topdown(info);
  1656. else
  1657. return unmapped_area(info);
  1658. }
  1659. /* truncate.c */
  1660. extern void truncate_inode_pages(struct address_space *, loff_t);
  1661. extern void truncate_inode_pages_range(struct address_space *,
  1662. loff_t lstart, loff_t lend);
  1663. extern void truncate_inode_pages_final(struct address_space *);
  1664. /* generic vm_area_ops exported for stackable file systems */
  1665. extern int filemap_fault(struct vm_area_struct *, struct vm_fault *);
  1666. extern void filemap_map_pages(struct vm_area_struct *vma, struct vm_fault *vmf);
  1667. extern int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);
  1668. /* mm/page-writeback.c */
  1669. int write_one_page(struct page *page, int wait);
  1670. void task_dirty_inc(struct task_struct *tsk);
  1671. /* readahead.c */
  1672. #define VM_MAX_READAHEAD 128 /* kbytes */
  1673. #define VM_MIN_READAHEAD 16 /* kbytes (includes current page) */
  1674. int force_page_cache_readahead(struct address_space *mapping, struct file *filp,
  1675. pgoff_t offset, unsigned long nr_to_read);
  1676. void page_cache_sync_readahead(struct address_space *mapping,
  1677. struct file_ra_state *ra,
  1678. struct file *filp,
  1679. pgoff_t offset,
  1680. unsigned long size);
  1681. void page_cache_async_readahead(struct address_space *mapping,
  1682. struct file_ra_state *ra,
  1683. struct file *filp,
  1684. struct page *pg,
  1685. pgoff_t offset,
  1686. unsigned long size);
  1687. unsigned long max_sane_readahead(unsigned long nr);
  1688. /* Generic expand stack which grows the stack according to GROWS{UP,DOWN} */
  1689. extern int expand_stack(struct vm_area_struct *vma, unsigned long address);
  1690. /* CONFIG_STACK_GROWSUP still needs to to grow downwards at some places */
  1691. extern int expand_downwards(struct vm_area_struct *vma,
  1692. unsigned long address);
  1693. #if VM_GROWSUP
  1694. extern int expand_upwards(struct vm_area_struct *vma, unsigned long address);
  1695. #else
  1696. #define expand_upwards(vma, address) (0)
  1697. #endif
  1698. /* Look up the first VMA which satisfies addr < vm_end, NULL if none. */
  1699. extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);
  1700. extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
  1701. struct vm_area_struct **pprev);
  1702. /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
  1703. NULL if none. Assume start_addr < end_addr. */
  1704. static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
  1705. {
  1706. struct vm_area_struct * vma = find_vma(mm,start_addr);
  1707. if (vma && end_addr <= vma->vm_start)
  1708. vma = NULL;
  1709. return vma;
  1710. }
  1711. static inline unsigned long vma_pages(struct vm_area_struct *vma)
  1712. {
  1713. return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
  1714. }
  1715. /* Look up the first VMA which exactly match the interval vm_start ... vm_end */
  1716. static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
  1717. unsigned long vm_start, unsigned long vm_end)
  1718. {
  1719. struct vm_area_struct *vma = find_vma(mm, vm_start);
  1720. if (vma && (vma->vm_start != vm_start || vma->vm_end != vm_end))
  1721. vma = NULL;
  1722. return vma;
  1723. }
  1724. #ifdef CONFIG_MMU
  1725. pgprot_t vm_get_page_prot(unsigned long vm_flags);
  1726. void vma_set_page_prot(struct vm_area_struct *vma);
  1727. #else
  1728. static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
  1729. {
  1730. return __pgprot(0);
  1731. }
  1732. static inline void vma_set_page_prot(struct vm_area_struct *vma)
  1733. {
  1734. vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
  1735. }
  1736. #endif
  1737. #ifdef CONFIG_NUMA_BALANCING
  1738. unsigned long change_prot_numa(struct vm_area_struct *vma,
  1739. unsigned long start, unsigned long end);
  1740. #endif
  1741. struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
  1742. int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
  1743. unsigned long pfn, unsigned long size, pgprot_t);
  1744. int vm_insert_page(struct vm_area_struct *, unsigned long addr, struct page *);
  1745. int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
  1746. unsigned long pfn);
  1747. int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
  1748. unsigned long pfn);
  1749. int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned long len);
  1750. struct page *follow_page_mask(struct vm_area_struct *vma,
  1751. unsigned long address, unsigned int foll_flags,
  1752. unsigned int *page_mask);
  1753. static inline struct page *follow_page(struct vm_area_struct *vma,
  1754. unsigned long address, unsigned int foll_flags)
  1755. {
  1756. unsigned int unused_page_mask;
  1757. return follow_page_mask(vma, address, foll_flags, &unused_page_mask);
  1758. }
  1759. #define FOLL_WRITE 0x01 /* check pte is writable */
  1760. #define FOLL_TOUCH 0x02 /* mark page accessed */
  1761. #define FOLL_GET 0x04 /* do get_page on page */
  1762. #define FOLL_DUMP 0x08 /* give error on hole if it would be zero */
  1763. #define FOLL_FORCE 0x10 /* get_user_pages read/write w/o permission */
  1764. #define FOLL_NOWAIT 0x20 /* if a disk transfer is needed, start the IO
  1765. * and return without waiting upon it */
  1766. #define FOLL_POPULATE 0x40 /* fault in page */
  1767. #define FOLL_SPLIT 0x80 /* don't return transhuge pages, split them */
  1768. #define FOLL_HWPOISON 0x100 /* check page is hwpoisoned */
  1769. #define FOLL_NUMA 0x200 /* force NUMA hinting page fault */
  1770. #define FOLL_MIGRATION 0x400 /* wait for page to replace migration entry */
  1771. #define FOLL_TRIED 0x800 /* a retry, previous pass started an IO */
  1772. typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
  1773. void *data);
  1774. extern int apply_to_page_range(struct mm_struct *mm, unsigned long address,
  1775. unsigned long size, pte_fn_t fn, void *data);
  1776. #ifdef CONFIG_PROC_FS
  1777. void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
  1778. #else
  1779. static inline void vm_stat_account(struct mm_struct *mm,
  1780. unsigned long flags, struct file *file, long pages)
  1781. {
  1782. mm->total_vm += pages;
  1783. }
  1784. #endif /* CONFIG_PROC_FS */
  1785. #ifdef CONFIG_DEBUG_PAGEALLOC
  1786. extern bool _debug_pagealloc_enabled;
  1787. extern void __kernel_map_pages(struct page *page, int numpages, int enable);
  1788. static inline bool debug_pagealloc_enabled(void)
  1789. {
  1790. return _debug_pagealloc_enabled;
  1791. }
  1792. static inline void
  1793. kernel_map_pages(struct page *page, int numpages, int enable)
  1794. {
  1795. if (!debug_pagealloc_enabled())
  1796. return;
  1797. __kernel_map_pages(page, numpages, enable);
  1798. }
  1799. #ifdef CONFIG_HIBERNATION
  1800. extern bool kernel_page_present(struct page *page);
  1801. #endif /* CONFIG_HIBERNATION */
  1802. #else
  1803. static inline void
  1804. kernel_map_pages(struct page *page, int numpages, int enable) {}
  1805. #ifdef CONFIG_HIBERNATION
  1806. static inline bool kernel_page_present(struct page *page) { return true; }
  1807. #endif /* CONFIG_HIBERNATION */
  1808. #endif
  1809. #ifdef __HAVE_ARCH_GATE_AREA
  1810. extern struct vm_area_struct *get_gate_vma(struct mm_struct *mm);
  1811. extern int in_gate_area_no_mm(unsigned long addr);
  1812. extern int in_gate_area(struct mm_struct *mm, unsigned long addr);
  1813. #else
  1814. static inline struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
  1815. {
  1816. return NULL;
  1817. }
  1818. static inline int in_gate_area_no_mm(unsigned long addr) { return 0; }
  1819. static inline int in_gate_area(struct mm_struct *mm, unsigned long addr)
  1820. {
  1821. return 0;
  1822. }
  1823. #endif /* __HAVE_ARCH_GATE_AREA */
  1824. #ifdef CONFIG_SYSCTL
  1825. extern int sysctl_drop_caches;
  1826. int drop_caches_sysctl_handler(struct ctl_table *, int,
  1827. void __user *, size_t *, loff_t *);
  1828. #endif
  1829. void drop_slab(void);
  1830. void drop_slab_node(int nid);
  1831. #ifndef CONFIG_MMU
  1832. #define randomize_va_space 0
  1833. #else
  1834. extern int randomize_va_space;
  1835. #endif
  1836. const char * arch_vma_name(struct vm_area_struct *vma);
  1837. void print_vma_addr(char *prefix, unsigned long rip);
  1838. void sparse_mem_maps_populate_node(struct page **map_map,
  1839. unsigned long pnum_begin,
  1840. unsigned long pnum_end,
  1841. unsigned long map_count,
  1842. int nodeid);
  1843. struct page *sparse_mem_map_populate(unsigned long pnum, int nid);
  1844. pgd_t *vmemmap_pgd_populate(unsigned long addr, int node);
  1845. pud_t *vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node);
  1846. pmd_t *vmemmap_pmd_populate(pud_t *pud, unsigned long addr, int node);
  1847. pte_t *vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, int node);
  1848. void *vmemmap_alloc_block(unsigned long size, int node);
  1849. void *vmemmap_alloc_block_buf(unsigned long size, int node);
  1850. void vmemmap_verify(pte_t *, int, unsigned long, unsigned long);
  1851. int vmemmap_populate_basepages(unsigned long start, unsigned long end,
  1852. int node);
  1853. int vmemmap_populate(unsigned long start, unsigned long end, int node);
  1854. void vmemmap_populate_print_last(void);
  1855. #ifdef CONFIG_MEMORY_HOTPLUG
  1856. void vmemmap_free(unsigned long start, unsigned long end);
  1857. #endif
  1858. void register_page_bootmem_memmap(unsigned long section_nr, struct page *map,
  1859. unsigned long size);
  1860. enum mf_flags {
  1861. MF_COUNT_INCREASED = 1 << 0,
  1862. MF_ACTION_REQUIRED = 1 << 1,
  1863. MF_MUST_KILL = 1 << 2,
  1864. MF_SOFT_OFFLINE = 1 << 3,
  1865. };
  1866. extern int memory_failure(unsigned long pfn, int trapno, int flags);
  1867. extern void memory_failure_queue(unsigned long pfn, int trapno, int flags);
  1868. extern int unpoison_memory(unsigned long pfn);
  1869. extern int get_hwpoison_page(struct page *page);
  1870. extern int sysctl_memory_failure_early_kill;
  1871. extern int sysctl_memory_failure_recovery;
  1872. extern void shake_page(struct page *p, int access);
  1873. extern atomic_long_t num_poisoned_pages;
  1874. extern int soft_offline_page(struct page *page, int flags);
  1875. /*
  1876. * Error handlers for various types of pages.
  1877. */
  1878. enum mf_result {
  1879. MF_IGNORED, /* Error: cannot be handled */
  1880. MF_FAILED, /* Error: handling failed */
  1881. MF_DELAYED, /* Will be handled later */
  1882. MF_RECOVERED, /* Successfully recovered */
  1883. };
  1884. enum mf_action_page_type {
  1885. MF_MSG_KERNEL,
  1886. MF_MSG_KERNEL_HIGH_ORDER,
  1887. MF_MSG_SLAB,
  1888. MF_MSG_DIFFERENT_COMPOUND,
  1889. MF_MSG_POISONED_HUGE,
  1890. MF_MSG_HUGE,
  1891. MF_MSG_FREE_HUGE,
  1892. MF_MSG_UNMAP_FAILED,
  1893. MF_MSG_DIRTY_SWAPCACHE,
  1894. MF_MSG_CLEAN_SWAPCACHE,
  1895. MF_MSG_DIRTY_MLOCKED_LRU,
  1896. MF_MSG_CLEAN_MLOCKED_LRU,
  1897. MF_MSG_DIRTY_UNEVICTABLE_LRU,
  1898. MF_MSG_CLEAN_UNEVICTABLE_LRU,
  1899. MF_MSG_DIRTY_LRU,
  1900. MF_MSG_CLEAN_LRU,
  1901. MF_MSG_TRUNCATED_LRU,
  1902. MF_MSG_BUDDY,
  1903. MF_MSG_BUDDY_2ND,
  1904. MF_MSG_UNKNOWN,
  1905. };
  1906. #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
  1907. extern void clear_huge_page(struct page *page,
  1908. unsigned long addr,
  1909. unsigned int pages_per_huge_page);
  1910. extern void copy_user_huge_page(struct page *dst, struct page *src,
  1911. unsigned long addr, struct vm_area_struct *vma,
  1912. unsigned int pages_per_huge_page);
  1913. #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
  1914. extern struct page_ext_operations debug_guardpage_ops;
  1915. extern struct page_ext_operations page_poisoning_ops;
  1916. #ifdef CONFIG_DEBUG_PAGEALLOC
  1917. extern unsigned int _debug_guardpage_minorder;
  1918. extern bool _debug_guardpage_enabled;
  1919. static inline unsigned int debug_guardpage_minorder(void)
  1920. {
  1921. return _debug_guardpage_minorder;
  1922. }
  1923. static inline bool debug_guardpage_enabled(void)
  1924. {
  1925. return _debug_guardpage_enabled;
  1926. }
  1927. static inline bool page_is_guard(struct page *page)
  1928. {
  1929. struct page_ext *page_ext;
  1930. if (!debug_guardpage_enabled())
  1931. return false;
  1932. page_ext = lookup_page_ext(page);
  1933. return test_bit(PAGE_EXT_DEBUG_GUARD, &page_ext->flags);
  1934. }
  1935. #else
  1936. static inline unsigned int debug_guardpage_minorder(void) { return 0; }
  1937. static inline bool debug_guardpage_enabled(void) { return false; }
  1938. static inline bool page_is_guard(struct page *page) { return false; }
  1939. #endif /* CONFIG_DEBUG_PAGEALLOC */
  1940. #if MAX_NUMNODES > 1
  1941. void __init setup_nr_node_ids(void);
  1942. #else
  1943. static inline void setup_nr_node_ids(void) {}
  1944. #endif
  1945. #endif /* __KERNEL__ */
  1946. #endif /* _LINUX_MM_H */