Lines Matching refs:page

63  * finished 'unifying' the page and buffer cache and SMP-threaded the
64 * page-cache, 21.05.1999, Ingo Molnar <mingo@redhat.com>
121 struct page *page, void *shadow)
123 XA_STATE(xas, &mapping->i_pages, page->index);
129 if (!PageHuge(page)) {
130 xas_set_order(&xas, page->index, compound_order(page));
131 nr = compound_nr(page);
134 VM_BUG_ON_PAGE(!PageLocked(page), page);
135 VM_BUG_ON_PAGE(PageTail(page), page);
136 VM_BUG_ON_PAGE(nr != 1 && shadow, page);
141 page->mapping = NULL;
142 /* Leave page->index set: truncation lookup relies upon it */
158 struct page *page)
165 * stale data around in the cleancache once our page is gone
167 if (PageUptodate(page) && PageMappedToDisk(page))
168 cleancache_put_page(page);
170 cleancache_invalidate_page(mapping, page);
172 VM_BUG_ON_PAGE(PageTail(page), page);
173 VM_BUG_ON_PAGE(page_mapped(page), page);
174 if (!IS_ENABLED(CONFIG_DEBUG_VM) && unlikely(page_mapped(page))) {
177 pr_alert("BUG: Bad page cache in process %s pfn:%05lx\n",
178 current->comm, page_to_pfn(page));
179 dump_page(page, "still mapped when deleted");
183 mapcount = page_mapcount(page);
185 page_count(page) >= mapcount + 2) {
188 * a good bet that actually the page is unmapped,
190 * some other bad page check should catch it later.
192 page_mapcount_reset(page);
193 page_ref_sub(page, mapcount);
197 /* hugetlb pages do not participate in page cache accounting. */
198 if (PageHuge(page))
201 nr = thp_nr_pages(page);
203 __mod_lruvec_page_state(page, NR_FILE_PAGES, -nr);
204 if (PageSwapBacked(page)) {
205 __mod_lruvec_page_state(page, NR_SHMEM, -nr);
206 if (PageTransHuge(page))
207 __dec_node_page_state(page, NR_SHMEM_THPS);
208 } else if (PageTransHuge(page)) {
209 __dec_node_page_state(page, NR_FILE_THPS);
214 * At this point page must be either written or cleaned by
215 * truncate. Dirty page here signals a bug and loss of
218 * This fixes dirty accounting after removing the page entirely
220 * page and anyway will be cleared before returning page into
223 if (WARN_ON_ONCE(PageDirty(page)))
224 account_page_cleaned(page, mapping, inode_to_wb(mapping->host));
228 * Delete a page from the page cache and free it. Caller has to make
229 * sure the page is locked and that nobody else uses it - or that usage
232 void __delete_from_page_cache(struct page *page, void *shadow)
234 struct address_space *mapping = page->mapping;
236 trace_mm_filemap_delete_from_page_cache(page);
238 unaccount_page_cache_page(mapping, page);
239 page_cache_delete(mapping, page, shadow);
243 struct page *page)
245 void (*freepage)(struct page *);
249 freepage(page);
251 if (PageTransHuge(page) && !PageHuge(page)) {
252 page_ref_sub(page, thp_nr_pages(page));
253 VM_BUG_ON_PAGE(page_count(page) <= 0, page);
255 put_page(page);
260 * delete_from_page_cache - delete page from page cache
261 * @page: the page which the kernel is trying to remove from page cache
263 * This must be called only on pages that have been verified to be in the page
264 * cache and locked. It will never put the page into the free list, the caller
265 * has a reference on the page.
267 void delete_from_page_cache(struct page *page)
269 struct address_space *mapping = page_mapping(page);
272 BUG_ON(!PageLocked(page));
274 __delete_from_page_cache(page, NULL);
277 page_cache_free_page(mapping, page);
282 * page_cache_delete_batch - delete several pages from page cache
287 * from the mapping. The function expects @pvec to be sorted by page index
301 struct page *page;
304 xas_for_each(&xas, page, ULONG_MAX) {
309 if (xa_is_value(page))
312 * A page got inserted in our range? Skip it. We have our
314 * If we see a page whose index is higher than ours, it
315 * means our page has been removed, which shouldn't be
318 if (page != pvec->pages[i]) {
319 VM_BUG_ON_PAGE(page->index > pvec->pages[i]->index,
320 page);
324 WARN_ON_ONCE(!PageLocked(page));
326 if (page->index == xas.xa_index)
327 page->mapping = NULL;
328 /* Leave page->index set: truncation lookup relies on it */
331 * Move to the next page in the vector if this is a regular
332 * page or the index is of the last sub-page of this compound
333 * page.
335 if (page->index + compound_nr(page) - 1 == xas.xa_index)
401 * these two operations is that if a dirty page/buffer is encountered, it must
462 * filemap_range_has_page - check if a page exists in range.
467 * Find at least one page in the range supplied, usually used to check if
470 * Return: %true if at least one page exists in the specified range,
476 struct page *page;
485 page = xas_find(&xas, max);
486 if (xas_retry(&xas, page))
489 if (xa_is_value(page))
492 * We don't need to try to pin this page; we're about to
494 * there was a page here recently.
500 return page != NULL;
525 struct page *page = pvec.pages[i];
527 wait_on_page_writeback(page);
528 ClearPageError(page);
775 * replace_page_cache_page - replace a pagecache page with a new one
776 * @old: page to be replaced
777 * @new: page to replace with
780 * This function replaces a page in the pagecache with a new one. On
781 * success it acquires the pagecache reference for the new page and
782 * drops it for the old page. Both the old and new pages must be
783 * locked. This function does not add the new page to the LRU, the
790 int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask)
793 void (*freepage)(struct page *) = mapping->a_ops->freepage;
812 /* hugetlb pages do not participate in page cache accounting. */
830 noinline int __add_to_page_cache_locked(struct page *page,
836 int huge = PageHuge(page);
840 VM_BUG_ON_PAGE(!PageLocked(page), page);
841 VM_BUG_ON_PAGE(PageSwapBacked(page), page);
844 get_page(page);
845 page->mapping = mapping;
846 page->index = offset;
849 error = mem_cgroup_charge(page, current->mm, gfp);
861 if (order > thp_order(page))
878 if (order > thp_order(page)) {
884 xas_store(&xas, page);
892 /* hugetlb pages do not participate in page cache accounting */
894 __inc_lruvec_page_state(page, NR_FILE_PAGES);
902 mem_cgroup_uncharge(page);
906 trace_mm_filemap_add_to_page_cache(page);
909 page->mapping = NULL;
910 /* Leave page->index set: truncation relies upon it */
911 put_page(page);
917 * add_to_page_cache_locked - add a locked page to the pagecache
918 * @page: page to add
919 * @mapping: the page's address_space
920 * @offset: page index
921 * @gfp_mask: page allocation mode
923 * This function is used to add a page to the pagecache. It must be locked.
924 * This function does not add the page to the LRU. The caller must do that.
928 int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
931 return __add_to_page_cache_locked(page, mapping, offset,
936 int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
942 __SetPageLocked(page);
943 ret = __add_to_page_cache_locked(page, mapping, offset,
946 __ClearPageLocked(page);
949 * The page might have been evicted from cache only
951 * any other repeatedly accessed page.
956 WARN_ON_ONCE(PageActive(page));
958 workingset_refault(page, shadow);
959 lru_cache_add(page);
966 struct page *__page_cache_alloc(gfp_t gfp)
969 struct page *page;
976 page = __alloc_pages_node(n, gfp, 0);
977 } while (!page && read_mems_allowed_retry(cpuset_mems_cookie));
979 return page;
992 * sure the appropriate page became available, this saves space
1000 static wait_queue_head_t *page_waitqueue(struct page *page)
1002 return &page_wait_table[hash_ptr(page, PAGE_WAIT_TABLE_BITS)];
1016 * The page wait code treats the "wait->flags" somewhat unusually, because
1065 if (test_bit(key->bit_nr, &key->page->flags))
1068 if (test_and_set_bit(key->bit_nr, &key->page->flags))
1100 static void wake_up_page_bit(struct page *page, int bit_nr)
1102 wait_queue_head_t *q = page_waitqueue(page);
1107 key.page = page;
1134 * hash, so in that case check for a page match. That prevents a long-
1137 * It is still possible to miss a case here, when we woke page waiters
1139 * page waiters.
1142 ClearPageWaiters(page);
1145 * our page waiters, but the hashed waitqueue has waiters for
1154 static void wake_up_page(struct page *page, int bit)
1156 if (!PageWaiters(page))
1158 wake_up_page_bit(page, bit);
1165 EXCLUSIVE, /* Hold ref to page and take the bit when woken, like
1168 SHARED, /* Hold ref to page and check the bit when woken, like
1171 DROP, /* Drop ref to page before wait, no check when woken,
1177 * Attempt to check (or get) the page bit, and mark us done
1180 static inline bool trylock_page_bit_common(struct page *page, int bit_nr,
1184 if (test_and_set_bit(bit_nr, &page->flags))
1186 } else if (test_bit(bit_nr, &page->flags))
1197 struct page *page, int bit_nr, int state, enum behavior behavior)
1207 !PageUptodate(page) && PageWorkingset(page)) {
1208 if (!PageSwapBacked(page)) {
1218 wait_page.page = page;
1231 * page bit synchronously.
1237 * page queue), and add ourselves to the wait
1244 SetPageWaiters(page);
1245 if (!trylock_page_bit_common(page, bit_nr, wait))
1252 * see whether the page bit testing has already
1255 * We can drop our reference to the page.
1258 put_page(page);
1295 if (unlikely(test_and_set_bit(bit_nr, &page->flags)))
1335 void wait_on_page_bit(struct page *page, int bit_nr)
1337 wait_queue_head_t *q = page_waitqueue(page);
1338 wait_on_page_bit_common(q, page, bit_nr, TASK_UNINTERRUPTIBLE, SHARED);
1342 int wait_on_page_bit_killable(struct page *page, int bit_nr)
1344 wait_queue_head_t *q = page_waitqueue(page);
1345 return wait_on_page_bit_common(q, page, bit_nr, TASK_KILLABLE, SHARED);
1349 static int __wait_on_page_locked_async(struct page *page,
1352 struct wait_queue_head *q = page_waitqueue(page);
1355 wait->page = page;
1360 SetPageWaiters(page);
1362 ret = !trylock_page(page);
1364 ret = PageLocked(page);
1379 static int wait_on_page_locked_async(struct page *page,
1382 if (!PageLocked(page))
1384 return __wait_on_page_locked_async(compound_head(page), wait, false);
1389 * @page: The page to wait for.
1391 * The caller should hold a reference on @page. They expect the page to
1393 * (for example) by holding the reference while waiting for the page to
1395 * dereference @page.
1397 void put_and_wait_on_page_locked(struct page *page)
1401 page = compound_head(page);
1402 q = page_waitqueue(page);
1403 wait_on_page_bit_common(q, page, PG_locked, TASK_UNINTERRUPTIBLE, DROP);
1407 * add_page_wait_queue - Add an arbitrary waiter to a page's wait queue
1408 * @page: Page defining the wait queue of interest
1411 * Add an arbitrary @waiter to the wait queue for the nominated @page.
1413 void add_page_wait_queue(struct page *page, wait_queue_entry_t *waiter)
1415 wait_queue_head_t *q = page_waitqueue(page);
1420 SetPageWaiters(page);
1449 * unlock_page - unlock a locked page
1450 * @page: the page
1452 * Unlocks the page and wakes up sleepers in wait_on_page_locked().
1463 void unlock_page(struct page *page)
1466 page = compound_head(page);
1467 VM_BUG_ON_PAGE(!PageLocked(page), page);
1468 if (clear_bit_unlock_is_negative_byte(PG_locked, &page->flags))
1469 wake_up_page_bit(page, PG_locked);
1474 * end_page_writeback - end writeback against a page
1475 * @page: the page
1477 void end_page_writeback(struct page *page)
1482 * shuffle a page marked for immediate reclaim is too mild to
1484 * ever page writeback.
1486 if (PageReclaim(page)) {
1487 ClearPageReclaim(page);
1488 rotate_reclaimable_page(page);
1492 * Writeback does not hold a page reference of its own, relying
1494 * But here we must make sure that the page is not freed and
1497 get_page(page);
1498 if (!test_clear_page_writeback(page))
1502 wake_up_page(page, PG_writeback);
1503 put_page(page);
1508 * After completing I/O on a page, call this routine to update the page
1511 void page_endio(struct page *page, bool is_write, int err)
1515 SetPageUptodate(page);
1517 ClearPageUptodate(page);
1518 SetPageError(page);
1520 unlock_page(page);
1525 SetPageError(page);
1526 mapping = page_mapping(page);
1530 end_page_writeback(page);
1536 * __lock_page - get a lock on the page, assuming we need to sleep to get it
1537 * @__page: the page to lock
1539 void __lock_page(struct page *__page)
1541 struct page *page = compound_head(__page);
1542 wait_queue_head_t *q = page_waitqueue(page);
1543 wait_on_page_bit_common(q, page, PG_locked, TASK_UNINTERRUPTIBLE,
1548 int __lock_page_killable(struct page *__page)
1550 struct page *page = compound_head(__page);
1551 wait_queue_head_t *q = page_waitqueue(page);
1552 return wait_on_page_bit_common(q, page, PG_locked, TASK_KILLABLE,
1557 int __lock_page_async(struct page *page, struct wait_page_queue *wait)
1559 return __wait_on_page_locked_async(page, wait, true);
1564 * 1 - page is locked; mmap_lock is still held.
1565 * 0 - page is not locked.
1571 * with the page locked and the mmap_lock unperturbed.
1573 int __lock_page_or_retry(struct page *page, struct mm_struct *mm,
1586 wait_on_page_locked_killable(page);
1588 wait_on_page_locked(page);
1594 ret = __lock_page_killable(page);
1600 __lock_page(page);
1606 * page_cache_next_miss() - Find the next gap in the page cache.
1642 * page_cache_prev_miss() - Find the previous gap in the page cache.
1678 * find_get_entry - find and get a page cache entry
1680 * @index: The page cache index.
1682 * Looks up the page cache slot at @mapping & @offset. If there is a
1683 * page cache page, the head page is returned with an increased refcount.
1685 * If the slot holds a shadow entry of a previously evicted page, or a
1688 * Return: The head page or shadow entry, %NULL if nothing is found.
1690 struct page *find_get_entry(struct address_space *mapping, pgoff_t index)
1693 struct page *page;
1698 page = xas_load(&xas);
1699 if (xas_retry(&xas, page))
1702 * A shadow entry of a recently evicted page, or a swap entry from
1703 * shmem/tmpfs. Return it without attempting to raise page count.
1705 if (!page || xa_is_value(page))
1708 if (!page_cache_get_speculative(page))
1712 * Has the page moved or been split?
1716 if (unlikely(page != xas_reload(&xas))) {
1717 put_page(page);
1723 return page;
1727 * find_lock_entry - Locate and lock a page cache entry.
1729 * @index: The page cache index.
1731 * Looks up the page at @mapping & @index. If there is a page in the
1732 * cache, the head page is returned locked and with an increased refcount.
1734 * If the slot holds a shadow entry of a previously evicted page, or a
1738 * Return: The head page or shadow entry, %NULL if nothing is found.
1740 struct page *find_lock_entry(struct address_space *mapping, pgoff_t index)
1742 struct page *page;
1745 page = find_get_entry(mapping, index);
1746 if (page && !xa_is_value(page)) {
1747 lock_page(page);
1748 /* Has the page been truncated? */
1749 if (unlikely(page->mapping != mapping)) {
1750 unlock_page(page);
1751 put_page(page);
1754 VM_BUG_ON_PAGE(!thp_contains(page, index), page);
1756 return page;
1760 * pagecache_get_page - Find and get a reference to a page.
1762 * @index: The page index.
1763 * @fgp_flags: %FGP flags modify how the page is returned.
1766 * Looks up the page cache entry at @mapping & @index.
1770 * * %FGP_ACCESSED - The page will be marked accessed.
1771 * * %FGP_LOCK - The page is returned locked.
1772 * * %FGP_HEAD - If the page is present and a THP, return the head page
1773 * rather than the exact page specified by the index.
1774 * * %FGP_CREAT - If no page is present then a new page is allocated using
1775 * @gfp_mask and added to the page cache and the VM's LRU list.
1776 * The page is returned locked and with an increased refcount.
1778 * page is already in cache. If the page was allocated, unlock it before
1780 * * %FGP_WRITE - The page will be written
1782 * * %FGP_NOWAIT - Don't get blocked by page lock
1787 * If there is a page cache page, it is returned with an increased refcount.
1789 * Return: The found page or %NULL otherwise.
1791 struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
1794 struct page *page;
1797 page = find_get_entry(mapping, index);
1798 if (xa_is_value(page))
1799 page = NULL;
1800 if (!page)
1805 if (!trylock_page(page)) {
1806 put_page(page);
1810 lock_page(page);
1813 /* Has the page been truncated? */
1814 if (unlikely(page->mapping != mapping)) {
1815 unlock_page(page);
1816 put_page(page);
1819 VM_BUG_ON_PAGE(!thp_contains(page, index), page);
1823 mark_page_accessed(page);
1826 if (page_is_idle(page))
1827 clear_page_idle(page);
1830 page = find_subpage(page, index);
1833 if (!page && (fgp_flags & FGP_CREAT)) {
1840 page = __page_cache_alloc(gfp_mask);
1841 if (!page)
1849 __SetPageReferenced(page);
1851 err = add_to_page_cache_lru(page, mapping, index, gfp_mask);
1853 put_page(page);
1854 page = NULL;
1860 * add_to_page_cache_lru locks the page, and for mmap we expect
1861 * an unlocked page.
1863 if (page && (fgp_flags & FGP_FOR_MMAP))
1864 unlock_page(page);
1867 return page;
1874 * @start: The starting page cache index
1884 * The search returns a group of mapping-contiguous page cache entries
1892 * stops at that page: the caller is likely to have a better way to handle
1893 * the compound page as a whole, and then skip its extent, than repeatedly
1900 struct page **entries, pgoff_t *indices)
1903 struct page *page;
1910 xas_for_each(&xas, page, ULONG_MAX) {
1911 if (xas_retry(&xas, page))
1914 * A shadow entry of a recently evicted page, a swap
1916 * without attempting to raise page count.
1918 if (xa_is_value(page))
1921 if (!page_cache_get_speculative(page))
1924 /* Has the page moved or been split? */
1925 if (unlikely(page != xas_reload(&xas)))
1932 if (PageTransHuge(page) && !PageHuge(page)) {
1933 page = find_subpage(page, xas.xa_index);
1938 entries[ret] = page;
1943 put_page(page);
1954 * @start: The starting page index
1955 * @end: The final page index (inclusive)
1966 * We also update @start to index the next page for the traversal.
1974 struct page **pages)
1977 struct page *page;
1984 xas_for_each(&xas, page, end) {
1985 if (xas_retry(&xas, page))
1988 if (xa_is_value(page))
1991 if (!page_cache_get_speculative(page))
1994 /* Has the page moved or been split? */
1995 if (unlikely(page != xas_reload(&xas)))
1998 pages[ret] = find_subpage(page, xas.xa_index);
2005 put_page(page);
2011 * We come here when there is no page beyond @end. We take care to not
2013 * breaks the iteration when there is a page at index -1 but that is
2029 * @index: The starting page index
2039 unsigned int nr_pages, struct page **pages)
2042 struct page *page;
2049 for (page = xas_load(&xas); page; page = xas_next(&xas)) {
2050 if (xas_retry(&xas, page))
2056 if (xa_is_value(page))
2059 if (!page_cache_get_speculative(page))
2062 /* Has the page moved or been split? */
2063 if (unlikely(page != xas_reload(&xas)))
2066 pages[ret] = find_subpage(page, xas.xa_index);
2071 put_page(page);
2083 * @index: the starting page index
2084 * @end: The final page index (inclusive)
2090 * @tag. We update @index to index the next page for the traversal.
2096 struct page **pages)
2099 struct page *page;
2106 xas_for_each_marked(&xas, page, end, tag) {
2107 if (xas_retry(&xas, page))
2111 * is lockless so there is a window for page reclaim to evict
2112 * a page we saw tagged. Skip over it.
2114 if (xa_is_value(page))
2117 if (!page_cache_get_speculative(page))
2120 /* Has the page moved or been split? */
2121 if (unlikely(page != xas_reload(&xas)))
2124 pages[ret] = find_subpage(page, xas.xa_index);
2131 put_page(page);
2139 * iteration when there is a page at index -1 but that is already
2200 unsigned long offset; /* offset into pagecache page */
2226 struct page *page;
2238 page = find_get_page(mapping, index);
2239 if (!page) {
2245 page = find_get_page(mapping, index);
2246 if (unlikely(page == NULL))
2249 if (PageReadahead(page)) {
2251 put_page(page);
2255 ra, filp, page,
2258 if (!PageUptodate(page)) {
2266 put_page(page);
2269 error = wait_on_page_locked_async(page,
2273 put_page(page);
2276 error = wait_on_page_locked_killable(page);
2280 if (PageUptodate(page))
2289 if (!trylock_page(page))
2292 if (!page->mapping)
2294 if (!mapping->a_ops->is_partially_uptodate(page,
2297 unlock_page(page);
2301 * i_size must be checked after we know the page is Uptodate.
2305 * part of the page is not copied back to userspace (unless
2312 put_page(page);
2316 /* nr is the maximum number of bytes to copy from this page */
2321 put_page(page);
2327 /* If users can be writing to this page using arbitrary
2329 * before reading the page on the kernel side.
2332 flush_dcache_page(page);
2335 * When a sequential read accesses a page several times,
2339 mark_page_accessed(page);
2343 * Ok, we have the page, and it's up-to-date, so
2347 ret = copy_page_to_iter(page, offset, nr, iter);
2353 put_page(page);
2364 /* Get exclusive access to the page ... */
2367 put_page(page);
2370 error = lock_page_async(page, iocb->ki_waitq);
2372 error = lock_page_killable(page);
2379 if (!page->mapping) {
2380 unlock_page(page);
2381 put_page(page);
2386 if (PageUptodate(page)) {
2387 unlock_page(page);
2393 unlock_page(page);
2394 put_page(page);
2402 ClearPageError(page);
2403 /* Start the actual read. The read will unlock the page. */
2404 error = mapping->a_ops->readpage(filp, page);
2408 put_page(page);
2415 if (!PageUptodate(page)) {
2418 put_page(page);
2421 error = lock_page_async(page, iocb->ki_waitq);
2423 error = lock_page_killable(page);
2428 if (!PageUptodate(page)) {
2429 if (page->mapping == NULL) {
2433 unlock_page(page);
2434 put_page(page);
2437 unlock_page(page);
2442 unlock_page(page);
2449 put_page(page);
2455 * page..
2457 page = page_cache_alloc(mapping);
2458 if (!page) {
2462 error = add_to_page_cache_lru(page, mapping, index,
2465 put_page(page);
2494 * that can use the page cache directly.
2569 * lock_page_maybe_drop_mmap - lock the page, possibly dropping the mmap_lock
2571 * @page - the page to lock.
2575 * It differs in that it actually returns the page locked if it returns 1 and 0
2576 * if it couldn't lock the page. If we did have to drop the mmap_lock then fpin
2579 static int lock_page_maybe_drop_mmap(struct vm_fault *vmf, struct page *page,
2582 if (trylock_page(page))
2595 if (__lock_page_killable(page)) {
2607 __lock_page(page);
2613 * Synchronous readahead happens when we don't even find a page in the page
2665 * Asynchronous readahead happens when we find the page and PG_readahead,
2670 struct page *page)
2685 if (PageReadahead(page)) {
2688 page, offset, ra->ra_pages);
2694 * filemap_fault - read in file data for page fault handling
2698 * mapped memory region to read in file data during a page fault.
2701 * it in the page cache, and handles the special cases reasonably without
2726 struct page *page;
2734 * Do we have something in the page cache already?
2736 page = find_get_page(mapping, offset);
2737 if (likely(page) && !(vmf->flags & FAULT_FLAG_TRIED)) {
2739 * We found the page, so try async readahead before
2742 fpin = do_async_mmap_readahead(vmf, page);
2743 } else if (!page) {
2744 /* No page in the page cache at all */
2750 page = pagecache_get_page(mapping, offset,
2753 if (!page) {
2760 if (!lock_page_maybe_drop_mmap(vmf, page, &fpin))
2764 if (unlikely(compound_head(page)->mapping != mapping)) {
2765 unlock_page(page);
2766 put_page(page);
2769 VM_BUG_ON_PAGE(page_to_pgoff(page) != offset, page);
2772 * We have a locked page in the page cache, now we need to check
2775 if (unlikely(!PageUptodate(page)))
2784 unlock_page(page);
2789 * Found the page and have a reference on it.
2790 * We must recheck i_size under page lock.
2794 unlock_page(page);
2795 put_page(page);
2799 vmf->page = page;
2804 * Umm, take care of errors if the page isn't up-to-date.
2809 ClearPageError(page);
2811 error = mapping->a_ops->readpage(file, page);
2813 wait_on_page_locked(page);
2814 if (!PageUptodate(page))
2819 put_page(page);
2831 * page.
2833 if (page)
2834 put_page(page);
2849 struct page *head, *page;
2860 * Check for a locked page first, as a speculative
2861 * reference may adversely influence page migration.
2868 /* Has the page moved or been split? */
2871 page = find_subpage(head, xas.xa_index);
2874 PageReadahead(page) ||
2875 PageHWPoison(page))
2894 if (alloc_set_pte(vmf, page))
2903 /* Huge page is mapped? No need to proceed. */
2914 struct page *page = vmf->page;
2920 lock_page(page);
2921 if (page->mapping != inode->i_mapping) {
2922 unlock_page(page);
2927 * We mark the page dirty already here so that when freeze is in
2929 * see the dirty page and writeprotect it again.
2931 set_page_dirty(page);
2932 wait_for_stable_page(page);
2985 static struct page *wait_on_page_read(struct page *page)
2987 if (!IS_ERR(page)) {
2988 wait_on_page_locked(page);
2989 if (!PageUptodate(page)) {
2990 put_page(page);
2991 page = ERR_PTR(-EIO);
2994 return page;
2997 static struct page *do_read_cache_page(struct address_space *mapping,
2999 int (*filler)(void *, struct page *),
3003 struct page *page;
3006 page = find_get_page(mapping, index);
3007 if (!page) {
3008 page = __page_cache_alloc(gfp);
3009 if (!page)
3011 err = add_to_page_cache_lru(page, mapping, index, gfp);
3013 put_page(page);
3022 err = filler(data, page);
3024 err = mapping->a_ops->readpage(data, page);
3027 put_page(page);
3031 page = wait_on_page_read(page);
3032 if (IS_ERR(page))
3033 return page;
3036 if (PageUptodate(page))
3041 * case a: Page is being filled and the page lock is held
3042 * case b: Read/write error clearing the page uptodate status
3043 * case c: Truncation in progress (page locked)
3046 * Case a, the page will be up to date when the page is unlocked.
3047 * There is no need to serialise on the page lock here as the page
3049 * page is truncated, the data is still valid if PageUptodate as
3051 * Case b, the page will not be up to date
3052 * Case c, the page may be truncated but in itself, the data may still
3054 * operation must restart if the page is not uptodate on unlock but
3055 * otherwise serialising on page lock to stabilise the mapping gives
3056 * no additional guarantees to the caller as the page lock is
3058 * Case d, similar to truncation. If reclaim holds the page lock, it
3061 * no need to serialise with page lock.
3063 * As the page lock gives no additional guarantee, we optimistically
3064 * wait on the page to be unlocked and check if it's up to date and
3065 * use the page if it is. Otherwise, the page lock is required to
3068 * wait on the same page for IO to complete.
3070 wait_on_page_locked(page);
3071 if (PageUptodate(page))
3075 lock_page(page);
3078 if (!page->mapping) {
3079 unlock_page(page);
3080 put_page(page);
3084 /* Someone else locked and filled the page in a very small window */
3085 if (PageUptodate(page)) {
3086 unlock_page(page);
3093 * Clear page error before actual read, PG_error will be
3094 * set again if read page fails.
3096 ClearPageError(page);
3100 mark_page_accessed(page);
3101 return page;
3105 * read_cache_page - read into page cache, fill it if needed
3106 * @mapping: the page's address_space
3107 * @index: the page index
3109 * @data: first arg to filler(data, page) function, often left as NULL
3111 * Read into the page cache. If a page already exists, and PageUptodate() is
3112 * not set, try to fill the page and wait for it to become unlocked.
3114 * If the page does not get brought uptodate, return -EIO.
3116 * Return: up to date page on success, ERR_PTR() on failure.
3118 struct page *read_cache_page(struct address_space *mapping,
3120 int (*filler)(void *, struct page *),
3129 * read_cache_page_gfp - read into page cache, using specified page allocation flags.
3130 * @mapping: the page's address_space
3131 * @index: the page index
3132 * @gfp: the page allocator flags to use if allocating
3135 * any new page allocations done using the specified allocation flags.
3137 * If the page does not get brought uptodate, return -EIO.
3139 * Return: up to date page on success, ERR_PTR() on failure.
3141 struct page *read_cache_page_gfp(struct address_space *mapping,
3151 struct page **pagep, void **fsdata)
3162 struct page *page, void *fsdata)
3166 return aops->write_end(file, mapping, pos, len, copied, page, fsdata);
3171 * Warn about a page cache invalidation failure during a direct I/O write.
3219 * the new data. We invalidate clean cached page from the region we're
3226 * If a page can not be invalidated, return 0 to fall back
3274 * Find or create a page at the given pagecache position. Return the locked
3275 * page. This function is specifically for buffered writes.
3277 struct page *grab_cache_page_write_begin(struct address_space *mapping,
3280 struct page *page;
3286 page = pagecache_get_page(mapping, index, fgp_flags,
3288 if (page)
3289 wait_for_stable_page(page);
3291 return page;
3305 struct page *page;
3306 unsigned long offset; /* Offset into pagecache page */
3307 unsigned long bytes; /* Bytes to write to page */
3317 * Bring in the user page that we will copy from _first_.
3319 * same page as we're writing to, without it being marked
3337 &page, &fsdata);
3342 flush_dcache_page(page);
3344 copied = iov_iter_copy_from_user_atomic(page, i, offset, bytes);
3345 flush_dcache_page(page);
3348 page, fsdata);
3409 /* We can write back this queue in page reclaim */
3428 * page-cache pages correctly).
3446 * We need to ensure that the page cache pages are written to
3507 * try_to_release_page() - release old fs-specific metadata on a page
3509 * @page: the page which the kernel is trying to free
3512 * The address_space is to try to release any data against the page
3513 * (presumably at page->private).
3515 * This may also be called if PG_fscache is set on a page, indicating that the
3516 * page is known to the local caching routines.
3519 * this page (__GFP_IO), and whether the call may block (__GFP_RECLAIM & __GFP_FS).
3523 int try_to_release_page(struct page *page, gfp_t gfp_mask)
3525 struct address_space * const mapping = page->mapping;
3527 BUG_ON(!PageLocked(page));
3528 if (PageWriteback(page))
3532 return mapping->a_ops->releasepage(page, gfp_mask);
3533 return try_to_free_buffers(page);