mm.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  1. #ifndef _LINUX_MM_H
  2. #define _LINUX_MM_H
  3. #include <linux/errno.h>
  4. #ifdef __KERNEL__
  5. #include <linux/gfp.h>
  6. #include <linux/list.h>
  7. #include <linux/mmzone.h>
  8. #include <linux/rbtree.h>
  9. #include <linux/prio_tree.h>
  10. #include <linux/fs.h>
  11. #include <linux/mutex.h>
  12. #include <linux/debug_locks.h>
  13. #include <linux/backing-dev.h>
  14. #include <linux/mm_types.h>
  15. struct mempolicy;
  16. struct anon_vma;
  17. struct user_struct;
  18. #ifndef CONFIG_DISCONTIGMEM /* Don't use mapnrs, do it properly */
  19. extern unsigned long max_mapnr;
  20. #endif
  21. extern unsigned long num_physpages;
  22. extern void * high_memory;
  23. extern int page_cluster;
  24. #ifdef CONFIG_SYSCTL
  25. extern int sysctl_legacy_va_layout;
  26. #else
  27. #define sysctl_legacy_va_layout 0
  28. #endif
  29. #include <asm/page.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/processor.h>
  32. #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
  33. /*
  34. * Linux kernel virtual memory manager primitives.
  35. * The idea being to have a "virtual" mm in the same way
  36. * we have a virtual fs - giving a cleaner interface to the
  37. * mm details, and allowing different kinds of memory mappings
  38. * (from shared memory to executable loading to arbitrary
  39. * mmap() functions).
  40. */
  41. /*
  42. * This struct defines a memory VMM memory area. There is one of these
  43. * per VM-area/task. A VM area is any part of the process virtual memory
  44. * space that has a special rule for the page-fault handlers (ie a shared
  45. * library, the executable area etc).
  46. */
  47. struct vm_area_struct {
  48. struct mm_struct * vm_mm; /* The address space we belong to. */
  49. unsigned long vm_start; /* Our start address within vm_mm. */
  50. unsigned long vm_end; /* The first byte after our end address
  51. within vm_mm. */
  52. /* linked list of VM areas per task, sorted by address */
  53. struct vm_area_struct *vm_next;
  54. pgprot_t vm_page_prot; /* Access permissions of this VMA. */
  55. unsigned long vm_flags; /* Flags, listed below. */
  56. struct rb_node vm_rb;
  57. /*
  58. * For areas with an address space and backing store,
  59. * linkage into the address_space->i_mmap prio tree, or
  60. * linkage to the list of like vmas hanging off its node, or
  61. * linkage of vma in the address_space->i_mmap_nonlinear list.
  62. */
  63. union {
  64. struct {
  65. struct list_head list;
  66. void *parent; /* aligns with prio_tree_node parent */
  67. struct vm_area_struct *head;
  68. } vm_set;
  69. struct raw_prio_tree_node prio_tree_node;
  70. } shared;
  71. /*
  72. * A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
  73. * list, after a COW of one of the file pages. A MAP_SHARED vma
  74. * can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
  75. * or brk vma (with NULL file) can only be in an anon_vma list.
  76. */
  77. struct list_head anon_vma_node; /* Serialized by anon_vma->lock */
  78. struct anon_vma *anon_vma; /* Serialized by page_table_lock */
  79. /* Function pointers to deal with this struct. */
  80. struct vm_operations_struct * vm_ops;
  81. /* Information about our backing store: */
  82. unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
  83. units, *not* PAGE_CACHE_SIZE */
  84. struct file * vm_file; /* File we map to (can be NULL). */
  85. void * vm_private_data; /* was vm_pte (shared mem) */
  86. unsigned long vm_truncate_count;/* truncate_count or restart_addr */
  87. #ifndef CONFIG_MMU
  88. atomic_t vm_usage; /* refcount (VMAs shared if !MMU) */
  89. #endif
  90. #ifdef CONFIG_NUMA
  91. struct mempolicy *vm_policy; /* NUMA policy for the VMA */
  92. #endif
  93. };
  94. extern struct kmem_cache *vm_area_cachep;
  95. /*
  96. * This struct defines the per-mm list of VMAs for uClinux. If CONFIG_MMU is
  97. * disabled, then there's a single shared list of VMAs maintained by the
  98. * system, and mm's subscribe to these individually
  99. */
  100. struct vm_list_struct {
  101. struct vm_list_struct *next;
  102. struct vm_area_struct *vma;
  103. };
  104. #ifndef CONFIG_MMU
  105. extern struct rb_root nommu_vma_tree;
  106. extern struct rw_semaphore nommu_vma_sem;
  107. extern unsigned int kobjsize(const void *objp);
  108. #endif
  109. /*
  110. * vm_flags..
  111. */
  112. #define VM_READ 0x00000001 /* currently active flags */
  113. #define VM_WRITE 0x00000002
  114. #define VM_EXEC 0x00000004
  115. #define VM_SHARED 0x00000008
  116. /* mprotect() hardcodes VM_MAYREAD >> 4 == VM_READ, and so for r/w/x bits. */
  117. #define VM_MAYREAD 0x00000010 /* limits for mprotect() etc */
  118. #define VM_MAYWRITE 0x00000020
  119. #define VM_MAYEXEC 0x00000040
  120. #define VM_MAYSHARE 0x00000080
  121. #define VM_GROWSDOWN 0x00000100 /* general info on the segment */
  122. #define VM_GROWSUP 0x00000200
  123. #define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page", just pure PFN */
  124. #define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */
  125. #define VM_EXECUTABLE 0x00001000
  126. #define VM_LOCKED 0x00002000
  127. #define VM_IO 0x00004000 /* Memory mapped I/O or similar */
  128. /* Used by sys_madvise() */
  129. #define VM_SEQ_READ 0x00008000 /* App will access data sequentially */
  130. #define VM_RAND_READ 0x00010000 /* App will not benefit from clustered reads */
  131. #define VM_DONTCOPY 0x00020000 /* Do not copy this vma on fork */
  132. #define VM_DONTEXPAND 0x00040000 /* Cannot expand with mremap() */
  133. #define VM_RESERVED 0x00080000 /* Count as reserved_vm like IO */
  134. #define VM_ACCOUNT 0x00100000 /* Is a VM accounted object */
  135. #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
  136. #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
  137. #define VM_MAPPED_COPY 0x01000000 /* T if mapped copy of data (nommu mmap) */
  138. #define VM_INSERTPAGE 0x02000000 /* The vma has had "vm_insert_page()" done on it */
  139. #define VM_ALWAYSDUMP 0x04000000 /* Always include in core dumps */
  140. #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
  141. #ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */
  142. #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
  143. #endif
  144. #ifdef CONFIG_STACK_GROWSUP
  145. #define VM_STACK_FLAGS (VM_GROWSUP | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)
  146. #else
  147. #define VM_STACK_FLAGS (VM_GROWSDOWN | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT)
  148. #endif
  149. #define VM_READHINTMASK (VM_SEQ_READ | VM_RAND_READ)
  150. #define VM_ClearReadHint(v) (v)->vm_flags &= ~VM_READHINTMASK
  151. #define VM_NormalReadHint(v) (!((v)->vm_flags & VM_READHINTMASK))
  152. #define VM_SequentialReadHint(v) ((v)->vm_flags & VM_SEQ_READ)
  153. #define VM_RandomReadHint(v) ((v)->vm_flags & VM_RAND_READ)
  154. /*
  155. * mapping from the currently active vm_flags protection bits (the
  156. * low four bits) to a page protection mask..
  157. */
  158. extern pgprot_t protection_map[16];
  159. #define FAULT_FLAG_WRITE 0x01 /* Fault was a write access */
  160. #define FAULT_FLAG_NONLINEAR 0x02 /* Fault was via a nonlinear mapping */
  161. /*
  162. * vm_fault is filled by the the pagefault handler and passed to the vma's
  163. * ->fault function. The vma's ->fault is responsible for returning a bitmask
  164. * of VM_FAULT_xxx flags that give details about how the fault was handled.
  165. *
  166. * pgoff should be used in favour of virtual_address, if possible. If pgoff
  167. * is used, one may set VM_CAN_NONLINEAR in the vma->vm_flags to get nonlinear
  168. * mapping support.
  169. */
  170. struct vm_fault {
  171. unsigned int flags; /* FAULT_FLAG_xxx flags */
  172. pgoff_t pgoff; /* Logical page offset based on vma */
  173. void __user *virtual_address; /* Faulting virtual address */
  174. struct page *page; /* ->fault handlers should return a
  175. * page here, unless VM_FAULT_NOPAGE
  176. * is set (which is also implied by
  177. * VM_FAULT_ERROR).
  178. */
  179. };
  180. /*
  181. * These are the virtual MM functions - opening of an area, closing and
  182. * unmapping it (needed to keep files on disk up-to-date etc), pointer
  183. * to the functions called when a no-page or a wp-page exception occurs.
  184. */
  185. struct vm_operations_struct {
  186. void (*open)(struct vm_area_struct * area);
  187. void (*close)(struct vm_area_struct * area);
  188. int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf);
  189. struct page *(*nopage)(struct vm_area_struct *area,
  190. unsigned long address, int *type);
  191. unsigned long (*nopfn)(struct vm_area_struct *area,
  192. unsigned long address);
  193. /* notification that a previously read-only page is about to become
  194. * writable, if an error is returned it will cause a SIGBUS */
  195. int (*page_mkwrite)(struct vm_area_struct *vma, struct page *page);
  196. #ifdef CONFIG_NUMA
  197. int (*set_policy)(struct vm_area_struct *vma, struct mempolicy *new);
  198. struct mempolicy *(*get_policy)(struct vm_area_struct *vma,
  199. unsigned long addr);
  200. int (*migrate)(struct vm_area_struct *vma, const nodemask_t *from,
  201. const nodemask_t *to, unsigned long flags);
  202. #endif
  203. };
  204. struct mmu_gather;
  205. struct inode;
  206. #define page_private(page) ((page)->private)
  207. #define set_page_private(page, v) ((page)->private = (v))
  208. /*
  209. * FIXME: take this include out, include page-flags.h in
  210. * files which need it (119 of them)
  211. */
  212. #include <linux/page-flags.h>
  213. #ifdef CONFIG_DEBUG_VM
  214. #define VM_BUG_ON(cond) BUG_ON(cond)
  215. #else
  216. #define VM_BUG_ON(condition) do { } while(0)
  217. #endif
  218. /*
  219. * Methods to modify the page usage count.
  220. *
  221. * What counts for a page usage:
  222. * - cache mapping (page->mapping)
  223. * - private data (page->private)
  224. * - page mapped in a task's page tables, each mapping
  225. * is counted separately
  226. *
  227. * Also, many kernel routines increase the page count before a critical
  228. * routine so they can be sure the page doesn't go away from under them.
  229. */
  230. /*
  231. * Drop a ref, return true if the refcount fell to zero (the page has no users)
  232. */
  233. static inline int put_page_testzero(struct page *page)
  234. {
  235. VM_BUG_ON(atomic_read(&page->_count) == 0);
  236. return atomic_dec_and_test(&page->_count);
  237. }
  238. /*
  239. * Try to grab a ref unless the page has a refcount of zero, return false if
  240. * that is the case.
  241. */
  242. static inline int get_page_unless_zero(struct page *page)
  243. {
  244. VM_BUG_ON(PageCompound(page));
  245. return atomic_inc_not_zero(&page->_count);
  246. }
  247. static inline struct page *compound_head(struct page *page)
  248. {
  249. if (unlikely(PageTail(page)))
  250. return page->first_page;
  251. return page;
  252. }
  253. static inline int page_count(struct page *page)
  254. {
  255. return atomic_read(&compound_head(page)->_count);
  256. }
  257. static inline void get_page(struct page *page)
  258. {
  259. page = compound_head(page);
  260. VM_BUG_ON(atomic_read(&page->_count) == 0);
  261. atomic_inc(&page->_count);
  262. }
  263. static inline struct page *virt_to_head_page(const void *x)
  264. {
  265. struct page *page = virt_to_page(x);
  266. return compound_head(page);
  267. }
  268. /*
  269. * Setup the page count before being freed into the page allocator for
  270. * the first time (boot or memory hotplug)
  271. */
  272. static inline void init_page_count(struct page *page)
  273. {
  274. atomic_set(&page->_count, 1);
  275. }
  276. void put_page(struct page *page);
  277. void put_pages_list(struct list_head *pages);
  278. void split_page(struct page *page, unsigned int order);
  279. /*
  280. * Compound pages have a destructor function. Provide a
  281. * prototype for that function and accessor functions.
  282. * These are _only_ valid on the head of a PG_compound page.
  283. */
  284. typedef void compound_page_dtor(struct page *);
  285. static inline void set_compound_page_dtor(struct page *page,
  286. compound_page_dtor *dtor)
  287. {
  288. page[1].lru.next = (void *)dtor;
  289. }
  290. static inline compound_page_dtor *get_compound_page_dtor(struct page *page)
  291. {
  292. return (compound_page_dtor *)page[1].lru.next;
  293. }
  294. static inline int compound_order(struct page *page)
  295. {
  296. if (!PageHead(page))
  297. return 0;
  298. return (unsigned long)page[1].lru.prev;
  299. }
  300. static inline void set_compound_order(struct page *page, unsigned long order)
  301. {
  302. page[1].lru.prev = (void *)order;
  303. }
  304. /*
  305. * Multiple processes may "see" the same page. E.g. for untouched
  306. * mappings of /dev/null, all processes see the same page full of
  307. * zeroes, and text pages of executables and shared libraries have
  308. * only one copy in memory, at most, normally.
  309. *
  310. * For the non-reserved pages, page_count(page) denotes a reference count.
  311. * page_count() == 0 means the page is free. page->lru is then used for
  312. * freelist management in the buddy allocator.
  313. * page_count() > 0 means the page has been allocated.
  314. *
  315. * Pages are allocated by the slab allocator in order to provide memory
  316. * to kmalloc and kmem_cache_alloc. In this case, the management of the
  317. * page, and the fields in 'struct page' are the responsibility of mm/slab.c
  318. * unless a particular usage is carefully commented. (the responsibility of
  319. * freeing the kmalloc memory is the caller's, of course).
  320. *
  321. * A page may be used by anyone else who does a __get_free_page().
  322. * In this case, page_count still tracks the references, and should only
  323. * be used through the normal accessor functions. The top bits of page->flags
  324. * and page->virtual store page management information, but all other fields
  325. * are unused and could be used privately, carefully. The management of this
  326. * page is the responsibility of the one who allocated it, and those who have
  327. * subsequently been given references to it.
  328. *
  329. * The other pages (we may call them "pagecache pages") are completely
  330. * managed by the Linux memory manager: I/O, buffers, swapping etc.
  331. * The following discussion applies only to them.
  332. *
  333. * A pagecache page contains an opaque `private' member, which belongs to the
  334. * page's address_space. Usually, this is the address of a circular list of
  335. * the page's disk buffers. PG_private must be set to tell the VM to call
  336. * into the filesystem to release these pages.
  337. *
  338. * A page may belong to an inode's memory mapping. In this case, page->mapping
  339. * is the pointer to the inode, and page->index is the file offset of the page,
  340. * in units of PAGE_CACHE_SIZE.
  341. *
  342. * If pagecache pages are not associated with an inode, they are said to be
  343. * anonymous pages. These may become associated with the swapcache, and in that
  344. * case PG_swapcache is set, and page->private is an offset into the swapcache.
  345. *
  346. * In either case (swapcache or inode backed), the pagecache itself holds one
  347. * reference to the page. Setting PG_private should also increment the
  348. * refcount. The each user mapping also has a reference to the page.
  349. *
  350. * The pagecache pages are stored in a per-mapping radix tree, which is
  351. * rooted at mapping->page_tree, and indexed by offset.
  352. * Where 2.4 and early 2.6 kernels kept dirty/clean pages in per-address_space
  353. * lists, we instead now tag pages as dirty/writeback in the radix tree.
  354. *
  355. * All pagecache pages may be subject to I/O:
  356. * - inode pages may need to be read from disk,
  357. * - inode pages which have been modified and are MAP_SHARED may need
  358. * to be written back to the inode on disk,
  359. * - anonymous pages (including MAP_PRIVATE file mappings) which have been
  360. * modified may need to be swapped out to swap space and (later) to be read
  361. * back into memory.
  362. */
  363. /*
  364. * The zone field is never updated after free_area_init_core()
  365. * sets it, so none of the operations on it need to be atomic.
  366. */
  367. /*
  368. * page->flags layout:
  369. *
  370. * There are three possibilities for how page->flags get
  371. * laid out. The first is for the normal case, without
  372. * sparsemem. The second is for sparsemem when there is
  373. * plenty of space for node and section. The last is when
  374. * we have run out of space and have to fall back to an
  375. * alternate (slower) way of determining the node.
  376. *
  377. * No sparsemem: | NODE | ZONE | ... | FLAGS |
  378. * with space for node: | SECTION | NODE | ZONE | ... | FLAGS |
  379. * no space for node: | SECTION | ZONE | ... | FLAGS |
  380. */
  381. #ifdef CONFIG_SPARSEMEM
  382. #define SECTIONS_WIDTH SECTIONS_SHIFT
  383. #else
  384. #define SECTIONS_WIDTH 0
  385. #endif
  386. #define ZONES_WIDTH ZONES_SHIFT
  387. #if SECTIONS_WIDTH+ZONES_WIDTH+NODES_SHIFT <= FLAGS_RESERVED
  388. #define NODES_WIDTH NODES_SHIFT
  389. #else
  390. #define NODES_WIDTH 0
  391. #endif
  392. /* Page flags: | [SECTION] | [NODE] | ZONE | ... | FLAGS | */
  393. #define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - SECTIONS_WIDTH)
  394. #define NODES_PGOFF (SECTIONS_PGOFF - NODES_WIDTH)
  395. #define ZONES_PGOFF (NODES_PGOFF - ZONES_WIDTH)
  396. /*
  397. * We are going to use the flags for the page to node mapping if its in
  398. * there. This includes the case where there is no node, so it is implicit.
  399. */
  400. #if !(NODES_WIDTH > 0 || NODES_SHIFT == 0)
  401. #define NODE_NOT_IN_PAGE_FLAGS
  402. #endif
  403. #ifndef PFN_SECTION_SHIFT
  404. #define PFN_SECTION_SHIFT 0
  405. #endif
  406. /*
  407. * Define the bit shifts to access each section. For non-existant
  408. * sections we define the shift as 0; that plus a 0 mask ensures
  409. * the compiler will optimise away reference to them.
  410. */
  411. #define SECTIONS_PGSHIFT (SECTIONS_PGOFF * (SECTIONS_WIDTH != 0))
  412. #define NODES_PGSHIFT (NODES_PGOFF * (NODES_WIDTH != 0))
  413. #define ZONES_PGSHIFT (ZONES_PGOFF * (ZONES_WIDTH != 0))
  414. /* NODE:ZONE or SECTION:ZONE is used to ID a zone for the buddy allcator */
  415. #ifdef NODE_NOT_IN_PAGEFLAGS
  416. #define ZONEID_SHIFT (SECTIONS_SHIFT + ZONES_SHIFT)
  417. #define ZONEID_PGOFF ((SECTIONS_PGOFF < ZONES_PGOFF)? \
  418. SECTIONS_PGOFF : ZONES_PGOFF)
  419. #else
  420. #define ZONEID_SHIFT (NODES_SHIFT + ZONES_SHIFT)
  421. #define ZONEID_PGOFF ((NODES_PGOFF < ZONES_PGOFF)? \
  422. NODES_PGOFF : ZONES_PGOFF)
  423. #endif
  424. #define ZONEID_PGSHIFT (ZONEID_PGOFF * (ZONEID_SHIFT != 0))
  425. #if SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > FLAGS_RESERVED
  426. #error SECTIONS_WIDTH+NODES_WIDTH+ZONES_WIDTH > FLAGS_RESERVED
  427. #endif
  428. #define ZONES_MASK ((1UL << ZONES_WIDTH) - 1)
  429. #define NODES_MASK ((1UL << NODES_WIDTH) - 1)
  430. #define SECTIONS_MASK ((1UL << SECTIONS_WIDTH) - 1)
  431. #define ZONEID_MASK ((1UL << ZONEID_SHIFT) - 1)
  432. static inline enum zone_type page_zonenum(struct page *page)
  433. {
  434. return (page->flags >> ZONES_PGSHIFT) & ZONES_MASK;
  435. }
  436. /*
  437. * The identification function is only used by the buddy allocator for
  438. * determining if two pages could be buddies. We are not really
  439. * identifying a zone since we could be using a the section number
  440. * id if we have not node id available in page flags.
  441. * We guarantee only that it will return the same value for two
  442. * combinable pages in a zone.
  443. */
  444. static inline int page_zone_id(struct page *page)
  445. {
  446. return (page->flags >> ZONEID_PGSHIFT) & ZONEID_MASK;
  447. }
  448. static inline int zone_to_nid(struct zone *zone)
  449. {
  450. #ifdef CONFIG_NUMA
  451. return zone->node;
  452. #else
  453. return 0;
  454. #endif
  455. }
  456. #ifdef NODE_NOT_IN_PAGE_FLAGS
  457. extern int page_to_nid(struct page *page);
  458. #else
  459. static inline int page_to_nid(struct page *page)
  460. {
  461. return (page->flags >> NODES_PGSHIFT) & NODES_MASK;
  462. }
  463. #endif
  464. static inline struct zone *page_zone(struct page *page)
  465. {
  466. return &NODE_DATA(page_to_nid(page))->node_zones[page_zonenum(page)];
  467. }
  468. static inline unsigned long page_to_section(struct page *page)
  469. {
  470. return (page->flags >> SECTIONS_PGSHIFT) & SECTIONS_MASK;
  471. }
  472. static inline void set_page_zone(struct page *page, enum zone_type zone)
  473. {
  474. page->flags &= ~(ZONES_MASK << ZONES_PGSHIFT);
  475. page->flags |= (zone & ZONES_MASK) << ZONES_PGSHIFT;
  476. }
  477. static inline void set_page_node(struct page *page, unsigned long node)
  478. {
  479. page->flags &= ~(NODES_MASK << NODES_PGSHIFT);
  480. page->flags |= (node & NODES_MASK) << NODES_PGSHIFT;
  481. }
  482. static inline void set_page_section(struct page *page, unsigned long section)
  483. {
  484. page->flags &= ~(SECTIONS_MASK << SECTIONS_PGSHIFT);
  485. page->flags |= (section & SECTIONS_MASK) << SECTIONS_PGSHIFT;
  486. }
  487. static inline void set_page_links(struct page *page, enum zone_type zone,
  488. unsigned long node, unsigned long pfn)
  489. {
  490. set_page_zone(page, zone);
  491. set_page_node(page, node);
  492. set_page_section(page, pfn_to_section_nr(pfn));
  493. }
  494. /*
  495. * Some inline functions in vmstat.h depend on page_zone()
  496. */
  497. #include <linux/vmstat.h>
  498. static __always_inline void *lowmem_page_address(struct page *page)
  499. {
  500. return __va(page_to_pfn(page) << PAGE_SHIFT);
  501. }
  502. #if defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL)
  503. #define HASHED_PAGE_VIRTUAL
  504. #endif
  505. #if defined(WANT_PAGE_VIRTUAL)
  506. #define page_address(page) ((page)->virtual)
  507. #define set_page_address(page, address) \
  508. do { \
  509. (page)->virtual = (address); \
  510. } while(0)
  511. #define page_address_init() do { } while(0)
  512. #endif
  513. #if defined(HASHED_PAGE_VIRTUAL)
  514. void *page_address(struct page *page);
  515. void set_page_address(struct page *page, void *virtual);
  516. void page_address_init(void);
  517. #endif
  518. #if !defined(HASHED_PAGE_VIRTUAL) && !defined(WANT_PAGE_VIRTUAL)
  519. #define page_address(page) lowmem_page_address(page)
  520. #define set_page_address(page, address) do { } while(0)
  521. #define page_address_init() do { } while(0)
  522. #endif
  523. /*
  524. * On an anonymous page mapped into a user virtual memory area,
  525. * page->mapping points to its anon_vma, not to a struct address_space;
  526. * with the PAGE_MAPPING_ANON bit set to distinguish it.
  527. *
  528. * Please note that, confusingly, "page_mapping" refers to the inode
  529. * address_space which maps the page from disk; whereas "page_mapped"
  530. * refers to user virtual address space into which the page is mapped.
  531. */
  532. #define PAGE_MAPPING_ANON 1
  533. extern struct address_space swapper_space;
  534. static inline struct address_space *page_mapping(struct page *page)
  535. {
  536. struct address_space *mapping = page->mapping;
  537. VM_BUG_ON(PageSlab(page));
  538. if (unlikely(PageSwapCache(page)))
  539. mapping = &swapper_space;
  540. #ifdef CONFIG_SLUB
  541. else if (unlikely(PageSlab(page)))
  542. mapping = NULL;
  543. #endif
  544. else if (unlikely((unsigned long)mapping & PAGE_MAPPING_ANON))
  545. mapping = NULL;
  546. return mapping;
  547. }
  548. static inline int PageAnon(struct page *page)
  549. {
  550. return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0;
  551. }
  552. /*
  553. * Return the pagecache index of the passed page. Regular pagecache pages
  554. * use ->index whereas swapcache pages use ->private
  555. */
  556. static inline pgoff_t page_index(struct page *page)
  557. {
  558. if (unlikely(PageSwapCache(page)))
  559. return page_private(page);
  560. return page->index;
  561. }
  562. /*
  563. * The atomic page->_mapcount, like _count, starts from -1:
  564. * so that transitions both from it and to it can be tracked,
  565. * using atomic_inc_and_test and atomic_add_negative(-1).
  566. */
  567. static inline void reset_page_mapcount(struct page *page)
  568. {
  569. atomic_set(&(page)->_mapcount, -1);
  570. }
  571. static inline int page_mapcount(struct page *page)
  572. {
  573. return atomic_read(&(page)->_mapcount) + 1;
  574. }
  575. /*
  576. * Return true if this page is mapped into pagetables.
  577. */
  578. static inline int page_mapped(struct page *page)
  579. {
  580. return atomic_read(&(page)->_mapcount) >= 0;
  581. }
  582. /*
  583. * Error return values for the *_nopage functions
  584. */
  585. #define NOPAGE_SIGBUS (NULL)
  586. #define NOPAGE_OOM ((struct page *) (-1))
  587. /*
  588. * Error return values for the *_nopfn functions
  589. */
  590. #define NOPFN_SIGBUS ((unsigned long) -1)
  591. #define NOPFN_OOM ((unsigned long) -2)
  592. #define NOPFN_REFAULT ((unsigned long) -3)
  593. /*
  594. * Different kinds of faults, as returned by handle_mm_fault().
  595. * Used to decide whether a process gets delivered SIGBUS or
  596. * just gets major/minor fault counters bumped up.
  597. */
  598. #define VM_FAULT_MINOR 0 /* For backwards compat. Remove me quickly. */
  599. #define VM_FAULT_OOM 0x0001
  600. #define VM_FAULT_SIGBUS 0x0002
  601. #define VM_FAULT_MAJOR 0x0004
  602. #define VM_FAULT_WRITE 0x0008 /* Special case for get_user_pages */
  603. #define VM_FAULT_NOPAGE 0x0100 /* ->fault installed the pte, not return page */
  604. #define VM_FAULT_LOCKED 0x0200 /* ->fault locked the returned page */
  605. #define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS)
  606. #define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
  607. extern void show_free_areas(void);
  608. #ifdef CONFIG_SHMEM
  609. int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *new);
  610. struct mempolicy *shmem_get_policy(struct vm_area_struct *vma,
  611. unsigned long addr);
  612. int shmem_lock(struct file *file, int lock, struct user_struct *user);
  613. #else
  614. static inline int shmem_lock(struct file *file, int lock,
  615. struct user_struct *user)
  616. {
  617. return 0;
  618. }
  619. static inline int shmem_set_policy(struct vm_area_struct *vma,
  620. struct mempolicy *new)
  621. {
  622. return 0;
  623. }
  624. static inline struct mempolicy *shmem_get_policy(struct vm_area_struct *vma,
  625. unsigned long addr)
  626. {
  627. return NULL;
  628. }
  629. #endif
  630. struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags);
  631. int shmem_zero_setup(struct vm_area_struct *);
  632. #ifndef CONFIG_MMU
  633. extern unsigned long shmem_get_unmapped_area(struct file *file,
  634. unsigned long addr,
  635. unsigned long len,
  636. unsigned long pgoff,
  637. unsigned long flags);
  638. #endif
  639. extern int can_do_mlock(void);
  640. extern int user_shm_lock(size_t, struct user_struct *);
  641. extern void user_shm_unlock(size_t, struct user_struct *);
  642. /*
  643. * Parameter block passed down to zap_pte_range in exceptional cases.
  644. */
  645. struct zap_details {
  646. struct vm_area_struct *nonlinear_vma; /* Check page->index if set */
  647. struct address_space *check_mapping; /* Check page->mapping if set */
  648. pgoff_t first_index; /* Lowest page->index to unmap */
  649. pgoff_t last_index; /* Highest page->index to unmap */
  650. spinlock_t *i_mmap_lock; /* For unmap_mapping_range: */
  651. unsigned long truncate_count; /* Compare vm_truncate_count */
  652. };
  653. struct page *vm_normal_page(struct vm_area_struct *, unsigned long, pte_t);
  654. unsigned long zap_page_range(struct vm_area_struct *vma, unsigned long address,
  655. unsigned long size, struct zap_details *);
  656. unsigned long unmap_vmas(struct mmu_gather **tlb,
  657. struct vm_area_struct *start_vma, unsigned long start_addr,
  658. unsigned long end_addr, unsigned long *nr_accounted,
  659. struct zap_details *);
  660. void free_pgd_range(struct mmu_gather **tlb, unsigned long addr,
  661. unsigned long end, unsigned long floor, unsigned long ceiling);
  662. void free_pgtables(struct mmu_gather **tlb, struct vm_area_struct *start_vma,
  663. unsigned long floor, unsigned long ceiling);
  664. int copy_page_range(struct mm_struct *dst, struct mm_struct *src,
  665. struct vm_area_struct *vma);
  666. int zeromap_page_range(struct vm_area_struct *vma, unsigned long from,
  667. unsigned long size, pgprot_t prot);
  668. void unmap_mapping_range(struct address_space *mapping,
  669. loff_t const holebegin, loff_t const holelen, int even_cows);
  670. static inline void unmap_shared_mapping_range(struct address_space *mapping,
  671. loff_t const holebegin, loff_t const holelen)
  672. {
  673. unmap_mapping_range(mapping, holebegin, holelen, 0);
  674. }
  675. extern int vmtruncate(struct inode * inode, loff_t offset);
  676. extern int vmtruncate_range(struct inode * inode, loff_t offset, loff_t end);
  677. #ifdef CONFIG_MMU
  678. extern int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
  679. unsigned long address, int write_access);
  680. #else
  681. static inline int handle_mm_fault(struct mm_struct *mm,
  682. struct vm_area_struct *vma, unsigned long address,
  683. int write_access)
  684. {
  685. /* should never happen if there's no MMU */
  686. BUG();
  687. return VM_FAULT_SIGBUS;
  688. }
  689. #endif
  690. extern int make_pages_present(unsigned long addr, unsigned long end);
  691. extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
  692. void install_arg_page(struct vm_area_struct *, struct page *, unsigned long);
  693. int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, unsigned long start,
  694. int len, int write, int force, struct page **pages, struct vm_area_struct **vmas);
  695. void print_bad_pte(struct vm_area_struct *, pte_t, unsigned long);
  696. extern int try_to_release_page(struct page * page, gfp_t gfp_mask);
  697. extern void do_invalidatepage(struct page *page, unsigned long offset);
  698. int __set_page_dirty_nobuffers(struct page *page);
  699. int __set_page_dirty_no_writeback(struct page *page);
  700. int redirty_page_for_writepage(struct writeback_control *wbc,
  701. struct page *page);
  702. int FASTCALL(set_page_dirty(struct page *page));
  703. int set_page_dirty_lock(struct page *page);
  704. int clear_page_dirty_for_io(struct page *page);
  705. extern unsigned long do_mremap(unsigned long addr,
  706. unsigned long old_len, unsigned long new_len,
  707. unsigned long flags, unsigned long new_addr);
  708. /*
  709. * A callback you can register to apply pressure to ageable caches.
  710. *
  711. * 'shrink' is passed a count 'nr_to_scan' and a 'gfpmask'. It should
  712. * look through the least-recently-used 'nr_to_scan' entries and
  713. * attempt to free them up. It should return the number of objects
  714. * which remain in the cache. If it returns -1, it means it cannot do
  715. * any scanning at this time (eg. there is a risk of deadlock).
  716. *
  717. * The 'gfpmask' refers to the allocation we are currently trying to
  718. * fulfil.
  719. *
  720. * Note that 'shrink' will be passed nr_to_scan == 0 when the VM is
  721. * querying the cache size, so a fastpath for that case is appropriate.
  722. */
  723. struct shrinker {
  724. int (*shrink)(int nr_to_scan, gfp_t gfp_mask);
  725. int seeks; /* seeks to recreate an obj */
  726. /* These are for internal use */
  727. struct list_head list;
  728. long nr; /* objs pending delete */
  729. };
  730. #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
  731. extern void register_shrinker(struct shrinker *);
  732. extern void unregister_shrinker(struct shrinker *);
  733. /*
  734. * Some shared mappigns will want the pages marked read-only
  735. * to track write events. If so, we'll downgrade vm_page_prot
  736. * to the private version (using protection_map[] without the
  737. * VM_SHARED bit).
  738. */
  739. static inline int vma_wants_writenotify(struct vm_area_struct *vma)
  740. {
  741. unsigned int vm_flags = vma->vm_flags;
  742. /* If it was private or non-writable, the write bit is already clear */
  743. if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
  744. return 0;
  745. /* The backer wishes to know when pages are first written to? */
  746. if (vma->vm_ops && vma->vm_ops->page_mkwrite)
  747. return 1;
  748. /* The open routine did something to the protections already? */
  749. if (pgprot_val(vma->vm_page_prot) !=
  750. pgprot_val(protection_map[vm_flags &
  751. (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]))
  752. return 0;
  753. /* Specialty mapping? */
  754. if (vm_flags & (VM_PFNMAP|VM_INSERTPAGE))
  755. return 0;
  756. /* Can the mapping track the dirty pages? */
  757. return vma->vm_file && vma->vm_file->f_mapping &&
  758. mapping_cap_account_dirty(vma->vm_file->f_mapping);
  759. }
  760. extern pte_t *FASTCALL(get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl));
  761. #ifdef __PAGETABLE_PUD_FOLDED
  762. static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
  763. unsigned long address)
  764. {
  765. return 0;
  766. }
  767. #else
  768. int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
  769. #endif
  770. #ifdef __PAGETABLE_PMD_FOLDED
  771. static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
  772. unsigned long address)
  773. {
  774. return 0;
  775. }
  776. #else
  777. int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
  778. #endif
  779. int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address);
  780. int __pte_alloc_kernel(pmd_t *pmd, unsigned long address);
  781. /*
  782. * The following ifdef needed to get the 4level-fixup.h header to work.
  783. * Remove it when 4level-fixup.h has been removed.
  784. */
  785. #if defined(CONFIG_MMU) && !defined(__ARCH_HAS_4LEVEL_HACK)
  786. static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
  787. {
  788. return (unlikely(pgd_none(*pgd)) && __pud_alloc(mm, pgd, address))?
  789. NULL: pud_offset(pgd, address);
  790. }
  791. static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
  792. {
  793. return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
  794. NULL: pmd_offset(pud, address);
  795. }
  796. #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
  797. #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
  798. /*
  799. * We tuck a spinlock to guard each pagetable page into its struct page,
  800. * at page->private, with BUILD_BUG_ON to make sure that this will not
  801. * overflow into the next struct page (as it might with DEBUG_SPINLOCK).
  802. * When freeing, reset page->mapping so free_pages_check won't complain.
  803. */
  804. #define __pte_lockptr(page) &((page)->ptl)
  805. #define pte_lock_init(_page) do { \
  806. spin_lock_init(__pte_lockptr(_page)); \
  807. } while (0)
  808. #define pte_lock_deinit(page) ((page)->mapping = NULL)
  809. #define pte_lockptr(mm, pmd) ({(void)(mm); __pte_lockptr(pmd_page(*(pmd)));})
  810. #else
  811. /*
  812. * We use mm->page_table_lock to guard all pagetable pages of the mm.
  813. */
  814. #define pte_lock_init(page) do {} while (0)
  815. #define pte_lock_deinit(page) do {} while (0)
  816. #define pte_lockptr(mm, pmd) ({(void)(pmd); &(mm)->page_table_lock;})
  817. #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
  818. #define pte_offset_map_lock(mm, pmd, address, ptlp) \
  819. ({ \
  820. spinlock_t *__ptl = pte_lockptr(mm, pmd); \
  821. pte_t *__pte = pte_offset_map(pmd, address); \
  822. *(ptlp) = __ptl; \
  823. spin_lock(__ptl); \
  824. __pte; \
  825. })
  826. #define pte_unmap_unlock(pte, ptl) do { \
  827. spin_unlock(ptl); \
  828. pte_unmap(pte); \
  829. } while (0)
  830. #define pte_alloc_map(mm, pmd, address) \
  831. ((unlikely(!pmd_present(*(pmd))) && __pte_alloc(mm, pmd, address))? \
  832. NULL: pte_offset_map(pmd, address))
  833. #define pte_alloc_map_lock(mm, pmd, address, ptlp) \
  834. ((unlikely(!pmd_present(*(pmd))) && __pte_alloc(mm, pmd, address))? \
  835. NULL: pte_offset_map_lock(mm, pmd, address, ptlp))
  836. #define pte_alloc_kernel(pmd, address) \
  837. ((unlikely(!pmd_present(*(pmd))) && __pte_alloc_kernel(pmd, address))? \
  838. NULL: pte_offset_kernel(pmd, address))
  839. extern void free_area_init(unsigned long * zones_size);
  840. extern void free_area_init_node(int nid, pg_data_t *pgdat,
  841. unsigned long * zones_size, unsigned long zone_start_pfn,
  842. unsigned long *zholes_size);
  843. #ifdef CONFIG_ARCH_POPULATES_NODE_MAP
  844. /*
  845. * With CONFIG_ARCH_POPULATES_NODE_MAP set, an architecture may initialise its
  846. * zones, allocate the backing mem_map and account for memory holes in a more
  847. * architecture independent manner. This is a substitute for creating the
  848. * zone_sizes[] and zholes_size[] arrays and passing them to
  849. * free_area_init_node()
  850. *
  851. * An architecture is expected to register range of page frames backed by
  852. * physical memory with add_active_range() before calling
  853. * free_area_init_nodes() passing in the PFN each zone ends at. At a basic
  854. * usage, an architecture is expected to do something like
  855. *
  856. * unsigned long max_zone_pfns[MAX_NR_ZONES] = {max_dma, max_normal_pfn,
  857. * max_highmem_pfn};
  858. * for_each_valid_physical_page_range()
  859. * add_active_range(node_id, start_pfn, end_pfn)
  860. * free_area_init_nodes(max_zone_pfns);
  861. *
  862. * If the architecture guarantees that there are no holes in the ranges
  863. * registered with add_active_range(), free_bootmem_active_regions()
  864. * will call free_bootmem_node() for each registered physical page range.
  865. * Similarly sparse_memory_present_with_active_regions() calls
  866. * memory_present() for each range when SPARSEMEM is enabled.
  867. *
  868. * See mm/page_alloc.c for more information on each function exposed by
  869. * CONFIG_ARCH_POPULATES_NODE_MAP
  870. */
  871. extern void free_area_init_nodes(unsigned long *max_zone_pfn);
  872. extern void add_active_range(unsigned int nid, unsigned long start_pfn,
  873. unsigned long end_pfn);
  874. extern void shrink_active_range(unsigned int nid, unsigned long old_end_pfn,
  875. unsigned long new_end_pfn);
  876. extern void push_node_boundaries(unsigned int nid, unsigned long start_pfn,
  877. unsigned long end_pfn);
  878. extern void remove_all_active_ranges(void);
  879. extern unsigned long absent_pages_in_range(unsigned long start_pfn,
  880. unsigned long end_pfn);
  881. extern void get_pfn_range_for_nid(unsigned int nid,
  882. unsigned long *start_pfn, unsigned long *end_pfn);
  883. extern unsigned long find_min_pfn_with_active_regions(void);
  884. extern unsigned long find_max_pfn_with_active_regions(void);
  885. extern void free_bootmem_with_active_regions(int nid,
  886. unsigned long max_low_pfn);
  887. extern void sparse_memory_present_with_active_regions(int nid);
  888. #ifndef CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID
  889. extern int early_pfn_to_nid(unsigned long pfn);
  890. #endif /* CONFIG_HAVE_ARCH_EARLY_PFN_TO_NID */
  891. #endif /* CONFIG_ARCH_POPULATES_NODE_MAP */
  892. extern void set_dma_reserve(unsigned long new_dma_reserve);
  893. extern void memmap_init_zone(unsigned long, int, unsigned long,
  894. unsigned long, enum memmap_context);
  895. extern void setup_per_zone_pages_min(void);
  896. extern void mem_init(void);
  897. extern void show_mem(void);
  898. extern void si_meminfo(struct sysinfo * val);
  899. extern void si_meminfo_node(struct sysinfo *val, int nid);
  900. #ifdef CONFIG_NUMA
  901. extern void setup_per_cpu_pageset(void);
  902. #else
  903. static inline void setup_per_cpu_pageset(void) {}
  904. #endif
  905. /* prio_tree.c */
  906. void vma_prio_tree_add(struct vm_area_struct *, struct vm_area_struct *old);
  907. void vma_prio_tree_insert(struct vm_area_struct *, struct prio_tree_root *);
  908. void vma_prio_tree_remove(struct vm_area_struct *, struct prio_tree_root *);
  909. struct vm_area_struct *vma_prio_tree_next(struct vm_area_struct *vma,
  910. struct prio_tree_iter *iter);
  911. #define vma_prio_tree_foreach(vma, iter, root, begin, end) \
  912. for (prio_tree_iter_init(iter, root, begin, end), vma = NULL; \
  913. (vma = vma_prio_tree_next(vma, iter)); )
  914. static inline void vma_nonlinear_insert(struct vm_area_struct *vma,
  915. struct list_head *list)
  916. {
  917. vma->shared.vm_set.parent = NULL;
  918. list_add_tail(&vma->shared.vm_set.list, list);
  919. }
  920. /* mmap.c */
  921. extern int __vm_enough_memory(long pages, int cap_sys_admin);
  922. extern void vma_adjust(struct vm_area_struct *vma, unsigned long start,
  923. unsigned long end, pgoff_t pgoff, struct vm_area_struct *insert);
  924. extern struct vm_area_struct *vma_merge(struct mm_struct *,
  925. struct vm_area_struct *prev, unsigned long addr, unsigned long end,
  926. unsigned long vm_flags, struct anon_vma *, struct file *, pgoff_t,
  927. struct mempolicy *);
  928. extern struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *);
  929. extern int split_vma(struct mm_struct *,
  930. struct vm_area_struct *, unsigned long addr, int new_below);
  931. extern int insert_vm_struct(struct mm_struct *, struct vm_area_struct *);
  932. extern void __vma_link_rb(struct mm_struct *, struct vm_area_struct *,
  933. struct rb_node **, struct rb_node *);
  934. extern void unlink_file_vma(struct vm_area_struct *);
  935. extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
  936. unsigned long addr, unsigned long len, pgoff_t pgoff);
  937. extern void exit_mmap(struct mm_struct *);
  938. extern int may_expand_vm(struct mm_struct *mm, unsigned long npages);
  939. extern int install_special_mapping(struct mm_struct *mm,
  940. unsigned long addr, unsigned long len,
  941. unsigned long flags, struct page **pages);
  942. extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
  943. extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
  944. unsigned long len, unsigned long prot,
  945. unsigned long flag, unsigned long pgoff);
  946. extern unsigned long mmap_region(struct file *file, unsigned long addr,
  947. unsigned long len, unsigned long flags,
  948. unsigned int vm_flags, unsigned long pgoff,
  949. int accountable);
  950. static inline unsigned long do_mmap(struct file *file, unsigned long addr,
  951. unsigned long len, unsigned long prot,
  952. unsigned long flag, unsigned long offset)
  953. {
  954. unsigned long ret = -EINVAL;
  955. if ((offset + PAGE_ALIGN(len)) < offset)
  956. goto out;
  957. if (!(offset & ~PAGE_MASK))
  958. ret = do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
  959. out:
  960. return ret;
  961. }
  962. extern int do_munmap(struct mm_struct *, unsigned long, size_t);
  963. extern unsigned long do_brk(unsigned long, unsigned long);
  964. /* filemap.c */
  965. extern unsigned long page_unuse(struct page *);
  966. extern void truncate_inode_pages(struct address_space *, loff_t);
  967. extern void truncate_inode_pages_range(struct address_space *,
  968. loff_t lstart, loff_t lend);
  969. /* generic vm_area_ops exported for stackable file systems */
  970. extern int filemap_fault(struct vm_area_struct *, struct vm_fault *);
  971. /* mm/page-writeback.c */
  972. int write_one_page(struct page *page, int wait);
  973. /* readahead.c */
  974. #define VM_MAX_READAHEAD 128 /* kbytes */
  975. #define VM_MIN_READAHEAD 16 /* kbytes (includes current page) */
  976. #define VM_MAX_CACHE_HIT 256 /* max pages in a row in cache before
  977. * turning readahead off */
  978. int do_page_cache_readahead(struct address_space *mapping, struct file *filp,
  979. pgoff_t offset, unsigned long nr_to_read);
  980. int force_page_cache_readahead(struct address_space *mapping, struct file *filp,
  981. pgoff_t offset, unsigned long nr_to_read);
  982. void page_cache_sync_readahead(struct address_space *mapping,
  983. struct file_ra_state *ra,
  984. struct file *filp,
  985. pgoff_t offset,
  986. unsigned long size);
  987. void page_cache_async_readahead(struct address_space *mapping,
  988. struct file_ra_state *ra,
  989. struct file *filp,
  990. struct page *pg,
  991. pgoff_t offset,
  992. unsigned long size);
  993. unsigned long max_sane_readahead(unsigned long nr);
  994. /* Do stack extension */
  995. extern int expand_stack(struct vm_area_struct *vma, unsigned long address);
  996. #ifdef CONFIG_IA64
  997. extern int expand_upwards(struct vm_area_struct *vma, unsigned long address);
  998. #endif
  999. /* Look up the first VMA which satisfies addr < vm_end, NULL if none. */
  1000. extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);
  1001. extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
  1002. struct vm_area_struct **pprev);
  1003. /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
  1004. NULL if none. Assume start_addr < end_addr. */
  1005. static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
  1006. {
  1007. struct vm_area_struct * vma = find_vma(mm,start_addr);
  1008. if (vma && end_addr <= vma->vm_start)
  1009. vma = NULL;
  1010. return vma;
  1011. }
  1012. static inline unsigned long vma_pages(struct vm_area_struct *vma)
  1013. {
  1014. return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
  1015. }
  1016. pgprot_t vm_get_page_prot(unsigned long vm_flags);
  1017. struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
  1018. struct page *vmalloc_to_page(void *addr);
  1019. unsigned long vmalloc_to_pfn(void *addr);
  1020. int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
  1021. unsigned long pfn, unsigned long size, pgprot_t);
  1022. int vm_insert_page(struct vm_area_struct *, unsigned long addr, struct page *);
  1023. int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
  1024. unsigned long pfn);
  1025. struct page *follow_page(struct vm_area_struct *, unsigned long address,
  1026. unsigned int foll_flags);
  1027. #define FOLL_WRITE 0x01 /* check pte is writable */
  1028. #define FOLL_TOUCH 0x02 /* mark page accessed */
  1029. #define FOLL_GET 0x04 /* do get_page on page */
  1030. #define FOLL_ANON 0x08 /* give ZERO_PAGE if no pgtable */
  1031. typedef int (*pte_fn_t)(pte_t *pte, struct page *pmd_page, unsigned long addr,
  1032. void *data);
  1033. extern int apply_to_page_range(struct mm_struct *mm, unsigned long address,
  1034. unsigned long size, pte_fn_t fn, void *data);
  1035. #ifdef CONFIG_PROC_FS
  1036. void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
  1037. #else
  1038. static inline void vm_stat_account(struct mm_struct *mm,
  1039. unsigned long flags, struct file *file, long pages)
  1040. {
  1041. }
  1042. #endif /* CONFIG_PROC_FS */
  1043. #ifndef CONFIG_DEBUG_PAGEALLOC
  1044. static inline void
  1045. kernel_map_pages(struct page *page, int numpages, int enable) {}
  1046. #endif
  1047. extern struct vm_area_struct *get_gate_vma(struct task_struct *tsk);
  1048. #ifdef __HAVE_ARCH_GATE_AREA
  1049. int in_gate_area_no_task(unsigned long addr);
  1050. int in_gate_area(struct task_struct *task, unsigned long addr);
  1051. #else
  1052. int in_gate_area_no_task(unsigned long addr);
  1053. #define in_gate_area(task, addr) ({(void)task; in_gate_area_no_task(addr);})
  1054. #endif /* __HAVE_ARCH_GATE_AREA */
  1055. int drop_caches_sysctl_handler(struct ctl_table *, int, struct file *,
  1056. void __user *, size_t *, loff_t *);
  1057. unsigned long shrink_slab(unsigned long scanned, gfp_t gfp_mask,
  1058. unsigned long lru_pages);
  1059. void drop_pagecache(void);
  1060. void drop_slab(void);
  1061. #ifndef CONFIG_MMU
  1062. #define randomize_va_space 0
  1063. #else
  1064. extern int randomize_va_space;
  1065. #endif
  1066. __attribute__((weak)) const char *arch_vma_name(struct vm_area_struct *vma);
  1067. #endif /* __KERNEL__ */
  1068. #endif /* _LINUX_MM_H */