pagemap.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. #ifndef _LINUX_PAGEMAP_H
  2. #define _LINUX_PAGEMAP_H
  3. /*
  4. * Copyright 1995 Linus Torvalds
  5. */
  6. #include <linux/mm.h>
  7. #include <linux/fs.h>
  8. #include <linux/list.h>
  9. #include <linux/highmem.h>
  10. #include <linux/compiler.h>
  11. #include <asm/uaccess.h>
  12. #include <linux/gfp.h>
  13. #include <linux/bitops.h>
  14. #include <linux/hardirq.h> /* for in_interrupt() */
  15. #include <linux/hugetlb_inline.h>
  16. /*
  17. * Bits in mapping->flags. The lower __GFP_BITS_SHIFT bits are the page
  18. * allocation mode flags.
  19. */
  20. enum mapping_flags {
  21. AS_EIO = __GFP_BITS_SHIFT + 0, /* IO error on async write */
  22. AS_ENOSPC = __GFP_BITS_SHIFT + 1, /* ENOSPC on async write */
  23. AS_MM_ALL_LOCKS = __GFP_BITS_SHIFT + 2, /* under mm_take_all_locks() */
  24. AS_UNEVICTABLE = __GFP_BITS_SHIFT + 3, /* e.g., ramdisk, SHM_LOCK */
  25. AS_EXITING = __GFP_BITS_SHIFT + 4, /* final truncate in progress */
  26. };
  27. static inline void mapping_set_error(struct address_space *mapping, int error)
  28. {
  29. if (unlikely(error)) {
  30. if (error == -ENOSPC)
  31. set_bit(AS_ENOSPC, &mapping->flags);
  32. else
  33. set_bit(AS_EIO, &mapping->flags);
  34. }
  35. }
  36. static inline void mapping_set_unevictable(struct address_space *mapping)
  37. {
  38. set_bit(AS_UNEVICTABLE, &mapping->flags);
  39. }
  40. static inline void mapping_clear_unevictable(struct address_space *mapping)
  41. {
  42. clear_bit(AS_UNEVICTABLE, &mapping->flags);
  43. }
  44. static inline int mapping_unevictable(struct address_space *mapping)
  45. {
  46. if (mapping)
  47. return test_bit(AS_UNEVICTABLE, &mapping->flags);
  48. return !!mapping;
  49. }
  50. static inline void mapping_set_exiting(struct address_space *mapping)
  51. {
  52. set_bit(AS_EXITING, &mapping->flags);
  53. }
  54. static inline int mapping_exiting(struct address_space *mapping)
  55. {
  56. return test_bit(AS_EXITING, &mapping->flags);
  57. }
  58. static inline gfp_t mapping_gfp_mask(struct address_space * mapping)
  59. {
  60. return (__force gfp_t)mapping->flags & __GFP_BITS_MASK;
  61. }
  62. /* Restricts the given gfp_mask to what the mapping allows. */
  63. static inline gfp_t mapping_gfp_constraint(struct address_space *mapping,
  64. gfp_t gfp_mask)
  65. {
  66. return mapping_gfp_mask(mapping) & gfp_mask;
  67. }
  68. /*
  69. * This is non-atomic. Only to be used before the mapping is activated.
  70. * Probably needs a barrier...
  71. */
  72. static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask)
  73. {
  74. m->flags = (m->flags & ~(__force unsigned long)__GFP_BITS_MASK) |
  75. (__force unsigned long)mask;
  76. }
  77. void release_pages(struct page **pages, int nr, bool cold);
  78. /*
  79. * speculatively take a reference to a page.
  80. * If the page is free (_refcount == 0), then _refcount is untouched, and 0
  81. * is returned. Otherwise, _refcount is incremented by 1 and 1 is returned.
  82. *
  83. * This function must be called inside the same rcu_read_lock() section as has
  84. * been used to lookup the page in the pagecache radix-tree (or page table):
  85. * this allows allocators to use a synchronize_rcu() to stabilize _refcount.
  86. *
  87. * Unless an RCU grace period has passed, the count of all pages coming out
  88. * of the allocator must be considered unstable. page_count may return higher
  89. * than expected, and put_page must be able to do the right thing when the
  90. * page has been finished with, no matter what it is subsequently allocated
  91. * for (because put_page is what is used here to drop an invalid speculative
  92. * reference).
  93. *
  94. * This is the interesting part of the lockless pagecache (and lockless
  95. * get_user_pages) locking protocol, where the lookup-side (eg. find_get_page)
  96. * has the following pattern:
  97. * 1. find page in radix tree
  98. * 2. conditionally increment refcount
  99. * 3. check the page is still in pagecache (if no, goto 1)
  100. *
  101. * Remove-side that cares about stability of _refcount (eg. reclaim) has the
  102. * following (with tree_lock held for write):
  103. * A. atomically check refcount is correct and set it to 0 (atomic_cmpxchg)
  104. * B. remove page from pagecache
  105. * C. free the page
  106. *
  107. * There are 2 critical interleavings that matter:
  108. * - 2 runs before A: in this case, A sees elevated refcount and bails out
  109. * - A runs before 2: in this case, 2 sees zero refcount and retries;
  110. * subsequently, B will complete and 1 will find no page, causing the
  111. * lookup to return NULL.
  112. *
  113. * It is possible that between 1 and 2, the page is removed then the exact same
  114. * page is inserted into the same position in pagecache. That's OK: the
  115. * old find_get_page using tree_lock could equally have run before or after
  116. * such a re-insertion, depending on order that locks are granted.
  117. *
  118. * Lookups racing against pagecache insertion isn't a big problem: either 1
  119. * will find the page or it will not. Likewise, the old find_get_page could run
  120. * either before the insertion or afterwards, depending on timing.
  121. */
  122. static inline int page_cache_get_speculative(struct page *page)
  123. {
  124. VM_BUG_ON(in_interrupt());
  125. #ifdef CONFIG_TINY_RCU
  126. # ifdef CONFIG_PREEMPT_COUNT
  127. VM_BUG_ON(!in_atomic());
  128. # endif
  129. /*
  130. * Preempt must be disabled here - we rely on rcu_read_lock doing
  131. * this for us.
  132. *
  133. * Pagecache won't be truncated from interrupt context, so if we have
  134. * found a page in the radix tree here, we have pinned its refcount by
  135. * disabling preempt, and hence no need for the "speculative get" that
  136. * SMP requires.
  137. */
  138. VM_BUG_ON_PAGE(page_count(page) == 0, page);
  139. page_ref_inc(page);
  140. #else
  141. if (unlikely(!get_page_unless_zero(page))) {
  142. /*
  143. * Either the page has been freed, or will be freed.
  144. * In either case, retry here and the caller should
  145. * do the right thing (see comments above).
  146. */
  147. return 0;
  148. }
  149. #endif
  150. VM_BUG_ON_PAGE(PageTail(page), page);
  151. return 1;
  152. }
  153. /*
  154. * Same as above, but add instead of inc (could just be merged)
  155. */
  156. static inline int page_cache_add_speculative(struct page *page, int count)
  157. {
  158. VM_BUG_ON(in_interrupt());
  159. #if !defined(CONFIG_SMP) && defined(CONFIG_TREE_RCU)
  160. # ifdef CONFIG_PREEMPT_COUNT
  161. VM_BUG_ON(!in_atomic());
  162. # endif
  163. VM_BUG_ON_PAGE(page_count(page) == 0, page);
  164. page_ref_add(page, count);
  165. #else
  166. if (unlikely(!page_ref_add_unless(page, count, 0)))
  167. return 0;
  168. #endif
  169. VM_BUG_ON_PAGE(PageCompound(page) && page != compound_head(page), page);
  170. return 1;
  171. }
  172. #ifdef CONFIG_NUMA
  173. extern struct page *__page_cache_alloc(gfp_t gfp);
  174. #else
  175. static inline struct page *__page_cache_alloc(gfp_t gfp)
  176. {
  177. return alloc_pages(gfp, 0);
  178. }
  179. #endif
  180. static inline struct page *page_cache_alloc(struct address_space *x)
  181. {
  182. return __page_cache_alloc(mapping_gfp_mask(x));
  183. }
  184. static inline struct page *page_cache_alloc_cold(struct address_space *x)
  185. {
  186. return __page_cache_alloc(mapping_gfp_mask(x)|__GFP_COLD);
  187. }
  188. static inline gfp_t readahead_gfp_mask(struct address_space *x)
  189. {
  190. return mapping_gfp_mask(x) |
  191. __GFP_COLD | __GFP_NORETRY | __GFP_NOWARN;
  192. }
  193. typedef int filler_t(void *, struct page *);
  194. pgoff_t page_cache_next_hole(struct address_space *mapping,
  195. pgoff_t index, unsigned long max_scan);
  196. pgoff_t page_cache_prev_hole(struct address_space *mapping,
  197. pgoff_t index, unsigned long max_scan);
  198. #define FGP_ACCESSED 0x00000001
  199. #define FGP_LOCK 0x00000002
  200. #define FGP_CREAT 0x00000004
  201. #define FGP_WRITE 0x00000008
  202. #define FGP_NOFS 0x00000010
  203. #define FGP_NOWAIT 0x00000020
  204. struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,
  205. int fgp_flags, gfp_t cache_gfp_mask);
  206. /**
  207. * find_get_page - find and get a page reference
  208. * @mapping: the address_space to search
  209. * @offset: the page index
  210. *
  211. * Looks up the page cache slot at @mapping & @offset. If there is a
  212. * page cache page, it is returned with an increased refcount.
  213. *
  214. * Otherwise, %NULL is returned.
  215. */
  216. static inline struct page *find_get_page(struct address_space *mapping,
  217. pgoff_t offset)
  218. {
  219. return pagecache_get_page(mapping, offset, 0, 0);
  220. }
  221. static inline struct page *find_get_page_flags(struct address_space *mapping,
  222. pgoff_t offset, int fgp_flags)
  223. {
  224. return pagecache_get_page(mapping, offset, fgp_flags, 0);
  225. }
  226. /**
  227. * find_lock_page - locate, pin and lock a pagecache page
  228. * pagecache_get_page - find and get a page reference
  229. * @mapping: the address_space to search
  230. * @offset: the page index
  231. *
  232. * Looks up the page cache slot at @mapping & @offset. If there is a
  233. * page cache page, it is returned locked and with an increased
  234. * refcount.
  235. *
  236. * Otherwise, %NULL is returned.
  237. *
  238. * find_lock_page() may sleep.
  239. */
  240. static inline struct page *find_lock_page(struct address_space *mapping,
  241. pgoff_t offset)
  242. {
  243. return pagecache_get_page(mapping, offset, FGP_LOCK, 0);
  244. }
  245. /**
  246. * find_or_create_page - locate or add a pagecache page
  247. * @mapping: the page's address_space
  248. * @index: the page's index into the mapping
  249. * @gfp_mask: page allocation mode
  250. *
  251. * Looks up the page cache slot at @mapping & @offset. If there is a
  252. * page cache page, it is returned locked and with an increased
  253. * refcount.
  254. *
  255. * If the page is not present, a new page is allocated using @gfp_mask
  256. * and added to the page cache and the VM's LRU list. The page is
  257. * returned locked and with an increased refcount.
  258. *
  259. * On memory exhaustion, %NULL is returned.
  260. *
  261. * find_or_create_page() may sleep, even if @gfp_flags specifies an
  262. * atomic allocation!
  263. */
  264. static inline struct page *find_or_create_page(struct address_space *mapping,
  265. pgoff_t offset, gfp_t gfp_mask)
  266. {
  267. return pagecache_get_page(mapping, offset,
  268. FGP_LOCK|FGP_ACCESSED|FGP_CREAT,
  269. gfp_mask);
  270. }
  271. /**
  272. * grab_cache_page_nowait - returns locked page at given index in given cache
  273. * @mapping: target address_space
  274. * @index: the page index
  275. *
  276. * Same as grab_cache_page(), but do not wait if the page is unavailable.
  277. * This is intended for speculative data generators, where the data can
  278. * be regenerated if the page couldn't be grabbed. This routine should
  279. * be safe to call while holding the lock for another page.
  280. *
  281. * Clear __GFP_FS when allocating the page to avoid recursion into the fs
  282. * and deadlock against the caller's locked page.
  283. */
  284. static inline struct page *grab_cache_page_nowait(struct address_space *mapping,
  285. pgoff_t index)
  286. {
  287. return pagecache_get_page(mapping, index,
  288. FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT,
  289. mapping_gfp_mask(mapping));
  290. }
  291. struct page *find_get_entry(struct address_space *mapping, pgoff_t offset);
  292. struct page *find_lock_entry(struct address_space *mapping, pgoff_t offset);
  293. unsigned find_get_entries(struct address_space *mapping, pgoff_t start,
  294. unsigned int nr_entries, struct page **entries,
  295. pgoff_t *indices);
  296. unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
  297. unsigned int nr_pages, struct page **pages);
  298. unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t start,
  299. unsigned int nr_pages, struct page **pages);
  300. unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index,
  301. int tag, unsigned int nr_pages, struct page **pages);
  302. unsigned find_get_entries_tag(struct address_space *mapping, pgoff_t start,
  303. int tag, unsigned int nr_entries,
  304. struct page **entries, pgoff_t *indices);
  305. struct page *grab_cache_page_write_begin(struct address_space *mapping,
  306. pgoff_t index, unsigned flags);
  307. /*
  308. * Returns locked page at given index in given cache, creating it if needed.
  309. */
  310. static inline struct page *grab_cache_page(struct address_space *mapping,
  311. pgoff_t index)
  312. {
  313. return find_or_create_page(mapping, index, mapping_gfp_mask(mapping));
  314. }
  315. extern struct page * read_cache_page(struct address_space *mapping,
  316. pgoff_t index, filler_t *filler, void *data);
  317. extern struct page * read_cache_page_gfp(struct address_space *mapping,
  318. pgoff_t index, gfp_t gfp_mask);
  319. extern int read_cache_pages(struct address_space *mapping,
  320. struct list_head *pages, filler_t *filler, void *data);
  321. static inline struct page *read_mapping_page(struct address_space *mapping,
  322. pgoff_t index, void *data)
  323. {
  324. filler_t *filler = (filler_t *)mapping->a_ops->readpage;
  325. return read_cache_page(mapping, index, filler, data);
  326. }
  327. /*
  328. * Get the offset in PAGE_SIZE.
  329. * (TODO: hugepage should have ->index in PAGE_SIZE)
  330. */
  331. static inline pgoff_t page_to_pgoff(struct page *page)
  332. {
  333. pgoff_t pgoff;
  334. if (unlikely(PageHeadHuge(page)))
  335. return page->index << compound_order(page);
  336. if (likely(!PageTransTail(page)))
  337. return page->index;
  338. /*
  339. * We don't initialize ->index for tail pages: calculate based on
  340. * head page
  341. */
  342. pgoff = compound_head(page)->index;
  343. pgoff += page - compound_head(page);
  344. return pgoff;
  345. }
  346. /*
  347. * Return byte-offset into filesystem object for page.
  348. */
  349. static inline loff_t page_offset(struct page *page)
  350. {
  351. return ((loff_t)page->index) << PAGE_SHIFT;
  352. }
  353. static inline loff_t page_file_offset(struct page *page)
  354. {
  355. return ((loff_t)page_file_index(page)) << PAGE_SHIFT;
  356. }
  357. extern pgoff_t linear_hugepage_index(struct vm_area_struct *vma,
  358. unsigned long address);
  359. static inline pgoff_t linear_page_index(struct vm_area_struct *vma,
  360. unsigned long address)
  361. {
  362. pgoff_t pgoff;
  363. if (unlikely(is_vm_hugetlb_page(vma)))
  364. return linear_hugepage_index(vma, address);
  365. pgoff = (address - vma->vm_start) >> PAGE_SHIFT;
  366. pgoff += vma->vm_pgoff;
  367. return pgoff;
  368. }
  369. extern void __lock_page(struct page *page);
  370. extern int __lock_page_killable(struct page *page);
  371. extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
  372. unsigned int flags);
  373. extern void unlock_page(struct page *page);
  374. static inline int trylock_page(struct page *page)
  375. {
  376. page = compound_head(page);
  377. return (likely(!test_and_set_bit_lock(PG_locked, &page->flags)));
  378. }
  379. /*
  380. * lock_page may only be called if we have the page's inode pinned.
  381. */
  382. static inline void lock_page(struct page *page)
  383. {
  384. might_sleep();
  385. if (!trylock_page(page))
  386. __lock_page(page);
  387. }
  388. /*
  389. * lock_page_killable is like lock_page but can be interrupted by fatal
  390. * signals. It returns 0 if it locked the page and -EINTR if it was
  391. * killed while waiting.
  392. */
  393. static inline int lock_page_killable(struct page *page)
  394. {
  395. might_sleep();
  396. if (!trylock_page(page))
  397. return __lock_page_killable(page);
  398. return 0;
  399. }
  400. /*
  401. * lock_page_or_retry - Lock the page, unless this would block and the
  402. * caller indicated that it can handle a retry.
  403. *
  404. * Return value and mmap_sem implications depend on flags; see
  405. * __lock_page_or_retry().
  406. */
  407. static inline int lock_page_or_retry(struct page *page, struct mm_struct *mm,
  408. unsigned int flags)
  409. {
  410. might_sleep();
  411. return trylock_page(page) || __lock_page_or_retry(page, mm, flags);
  412. }
  413. /*
  414. * This is exported only for wait_on_page_locked/wait_on_page_writeback,
  415. * and for filesystems which need to wait on PG_private.
  416. */
  417. extern void wait_on_page_bit(struct page *page, int bit_nr);
  418. extern int wait_on_page_bit_killable(struct page *page, int bit_nr);
  419. extern int wait_on_page_bit_killable_timeout(struct page *page,
  420. int bit_nr, unsigned long timeout);
  421. static inline int wait_on_page_locked_killable(struct page *page)
  422. {
  423. if (!PageLocked(page))
  424. return 0;
  425. return wait_on_page_bit_killable(compound_head(page), PG_locked);
  426. }
  427. extern wait_queue_head_t *page_waitqueue(struct page *page);
  428. static inline void wake_up_page(struct page *page, int bit)
  429. {
  430. __wake_up_bit(page_waitqueue(page), &page->flags, bit);
  431. }
  432. /*
  433. * Wait for a page to be unlocked.
  434. *
  435. * This must be called with the caller "holding" the page,
  436. * ie with increased "page->count" so that the page won't
  437. * go away during the wait..
  438. */
  439. static inline void wait_on_page_locked(struct page *page)
  440. {
  441. if (PageLocked(page))
  442. wait_on_page_bit(compound_head(page), PG_locked);
  443. }
  444. /*
  445. * Wait for a page to complete writeback
  446. */
  447. static inline void wait_on_page_writeback(struct page *page)
  448. {
  449. if (PageWriteback(page))
  450. wait_on_page_bit(page, PG_writeback);
  451. }
  452. extern void end_page_writeback(struct page *page);
  453. void wait_for_stable_page(struct page *page);
  454. void page_endio(struct page *page, bool is_write, int err);
  455. /*
  456. * Add an arbitrary waiter to a page's wait queue
  457. */
  458. extern void add_page_wait_queue(struct page *page, wait_queue_t *waiter);
  459. /*
  460. * Fault one or two userspace pages into pagetables.
  461. * Return -EINVAL if more than two pages would be needed.
  462. * Return non-zero on a fault.
  463. */
  464. static inline int fault_in_pages_writeable(char __user *uaddr, int size)
  465. {
  466. int span, ret;
  467. if (unlikely(size == 0))
  468. return 0;
  469. span = offset_in_page(uaddr) + size;
  470. if (span > 2 * PAGE_SIZE)
  471. return -EINVAL;
  472. /*
  473. * Writing zeroes into userspace here is OK, because we know that if
  474. * the zero gets there, we'll be overwriting it.
  475. */
  476. ret = __put_user(0, uaddr);
  477. if (ret == 0 && span > PAGE_SIZE)
  478. ret = __put_user(0, uaddr + size - 1);
  479. return ret;
  480. }
  481. static inline int fault_in_pages_readable(const char __user *uaddr, int size)
  482. {
  483. volatile char c;
  484. int ret;
  485. if (unlikely(size == 0))
  486. return 0;
  487. ret = __get_user(c, uaddr);
  488. if (ret == 0) {
  489. const char __user *end = uaddr + size - 1;
  490. if (((unsigned long)uaddr & PAGE_MASK) !=
  491. ((unsigned long)end & PAGE_MASK)) {
  492. ret = __get_user(c, end);
  493. (void)c;
  494. }
  495. }
  496. return ret;
  497. }
  498. /*
  499. * Multipage variants of the above prefault helpers, useful if more than
  500. * PAGE_SIZE of data needs to be prefaulted. These are separate from the above
  501. * functions (which only handle up to PAGE_SIZE) to avoid clobbering the
  502. * filemap.c hotpaths.
  503. */
  504. static inline int fault_in_multipages_writeable(char __user *uaddr, int size)
  505. {
  506. int ret = 0;
  507. char __user *end = uaddr + size - 1;
  508. if (unlikely(size == 0))
  509. return ret;
  510. /*
  511. * Writing zeroes into userspace here is OK, because we know that if
  512. * the zero gets there, we'll be overwriting it.
  513. */
  514. while (uaddr <= end) {
  515. ret = __put_user(0, uaddr);
  516. if (ret != 0)
  517. return ret;
  518. uaddr += PAGE_SIZE;
  519. }
  520. /* Check whether the range spilled into the next page. */
  521. if (((unsigned long)uaddr & PAGE_MASK) ==
  522. ((unsigned long)end & PAGE_MASK))
  523. ret = __put_user(0, end);
  524. return ret;
  525. }
  526. static inline int fault_in_multipages_readable(const char __user *uaddr,
  527. int size)
  528. {
  529. volatile char c;
  530. int ret = 0;
  531. const char __user *end = uaddr + size - 1;
  532. if (unlikely(size == 0))
  533. return ret;
  534. while (uaddr <= end) {
  535. ret = __get_user(c, uaddr);
  536. if (ret != 0)
  537. return ret;
  538. uaddr += PAGE_SIZE;
  539. }
  540. /* Check whether the range spilled into the next page. */
  541. if (((unsigned long)uaddr & PAGE_MASK) ==
  542. ((unsigned long)end & PAGE_MASK)) {
  543. ret = __get_user(c, end);
  544. (void)c;
  545. }
  546. return ret;
  547. }
  548. int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
  549. pgoff_t index, gfp_t gfp_mask);
  550. int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
  551. pgoff_t index, gfp_t gfp_mask);
  552. extern void delete_from_page_cache(struct page *page);
  553. extern void __delete_from_page_cache(struct page *page, void *shadow);
  554. int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask);
  555. /*
  556. * Like add_to_page_cache_locked, but used to add newly allocated pages:
  557. * the page is new, so we can just run __SetPageLocked() against it.
  558. */
  559. static inline int add_to_page_cache(struct page *page,
  560. struct address_space *mapping, pgoff_t offset, gfp_t gfp_mask)
  561. {
  562. int error;
  563. __SetPageLocked(page);
  564. error = add_to_page_cache_locked(page, mapping, offset, gfp_mask);
  565. if (unlikely(error))
  566. __ClearPageLocked(page);
  567. return error;
  568. }
  569. static inline unsigned long dir_pages(struct inode *inode)
  570. {
  571. return (unsigned long)(inode->i_size + PAGE_SIZE - 1) >>
  572. PAGE_SHIFT;
  573. }
  574. #endif /* _LINUX_PAGEMAP_H */