Lines Matching +full:wait +full:- +full:on +full:- +full:write

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 1994-1999 Linus Torvalds
30 #include <linux/error-injection.h>
33 #include <linux/backing-dev.h>
71 * finished 'unifying' the page and buffer cache and SMP-threaded the
72 * page-cache, 21.05.1999, Ingo Molnar <mingo@redhat.com>
74 * SMP-threaded pagemap-LRU 1999, Andrea Arcangeli <andrea@suse.de>
80 * ->i_mmap_rwsem (truncate_pagecache)
81 * ->private_lock (__free_pte->block_dirty_folio)
82 * ->swap_lock (exclusive_swap_page, others)
83 * ->i_pages lock
85 * ->i_rwsem
86 * ->invalidate_lock (acquired by fs in truncate path)
87 * ->i_mmap_rwsem (truncate->unmap_mapping_range)
89 * ->mmap_lock
90 * ->i_mmap_rwsem
91 * ->page_table_lock or pte_lock (various, mainly in memory.c)
92 * ->i_pages lock (arch-dependent flush_dcache_mmap_lock)
94 * ->mmap_lock
95 * ->invalidate_lock (filemap_fault)
96 * ->lock_page (filemap_fault, access_process_vm)
98 * ->i_rwsem (generic_perform_write)
99 * ->mmap_lock (fault_in_readable->do_page_fault)
101 * bdi->wb.list_lock
102 * sb_lock (fs/fs-writeback.c)
103 * ->i_pages lock (__sync_single_inode)
105 * ->i_mmap_rwsem
106 * ->anon_vma.lock (vma_merge)
108 * ->anon_vma.lock
109 * ->page_table_lock or pte_lock (anon_vma_prepare and various)
111 * ->page_table_lock or pte_lock
112 * ->swap_lock (try_to_unmap_one)
113 * ->private_lock (try_to_unmap_one)
114 * ->i_pages lock (try_to_unmap_one)
115 * ->lruvec->lru_lock (follow_page->mark_page_accessed)
116 * ->lruvec->lru_lock (check_pte_range->isolate_lru_page)
117 * ->private_lock (folio_remove_rmap_pte->set_page_dirty)
118 * ->i_pages lock (folio_remove_rmap_pte->set_page_dirty)
119 * bdi.wb->list_lock (folio_remove_rmap_pte->set_page_dirty)
120 * ->inode->i_lock (folio_remove_rmap_pte->set_page_dirty)
121 * ->memcg->move_lock (folio_remove_rmap_pte->folio_memcg_lock)
122 * bdi.wb->list_lock (zap_pte_range->set_page_dirty)
123 * ->inode->i_lock (zap_pte_range->set_page_dirty)
124 * ->private_lock (zap_pte_range->block_dirty_folio)
130 XA_STATE(xas, &mapping->i_pages, folio->index); in page_cache_delete()
135 xas_set_order(&xas, folio->index, folio_order(folio)); in page_cache_delete()
143 folio->mapping = NULL; in page_cache_delete()
144 /* Leave page->index set: truncation lookup relies upon it */ in page_cache_delete()
145 mapping->nrpages -= nr; in page_cache_delete()
156 current->comm, folio_pfn(folio)); in filemap_unaccount_folio()
157 dump_page(&folio->page, "still mapped when deleted"); in filemap_unaccount_folio()
162 int mapcount = page_mapcount(&folio->page); in filemap_unaccount_folio()
171 page_mapcount_reset(&folio->page); in filemap_unaccount_folio()
183 __lruvec_stat_mod_folio(folio, NR_FILE_PAGES, -nr); in filemap_unaccount_folio()
185 __lruvec_stat_mod_folio(folio, NR_SHMEM, -nr); in filemap_unaccount_folio()
187 __lruvec_stat_mod_folio(folio, NR_SHMEM_THPS, -nr); in filemap_unaccount_folio()
189 __lruvec_stat_mod_folio(folio, NR_FILE_THPS, -nr); in filemap_unaccount_folio()
196 * unwritten data - on ordinary filesystems. in filemap_unaccount_folio()
198 * But it's harmless on in-memory filesystems like tmpfs; and can in filemap_unaccount_folio()
209 folio_account_cleaned(folio, inode_to_wb(mapping->host)); in filemap_unaccount_folio()
214 * sure the page is locked and that nobody else uses it - or that usage
219 struct address_space *mapping = folio->mapping; in __filemap_remove_folio()
231 free_folio = mapping->a_ops->free_folio; in filemap_free_folio()
241 * filemap_remove_folio - Remove folio from page cache.
244 * This must be called only on folios that are locked and have been
246 * the free list because the caller has a reference on the page.
250 struct address_space *mapping = folio->mapping; in filemap_remove_folio()
253 spin_lock(&mapping->host->i_lock); in filemap_remove_folio()
254 xa_lock_irq(&mapping->i_pages); in filemap_remove_folio()
256 xa_unlock_irq(&mapping->i_pages); in filemap_remove_folio()
258 inode_add_lru(mapping->host); in filemap_remove_folio()
259 spin_unlock(&mapping->host->i_lock); in filemap_remove_folio()
265 * page_cache_delete_batch - delete several folios from page cache
269 * The function walks over mapping->i_pages and removes folios passed in
280 XA_STATE(xas, &mapping->i_pages, fbatch->folios[0]->index); in page_cache_delete_batch()
300 if (folio != fbatch->folios[i]) { in page_cache_delete_batch()
301 VM_BUG_ON_FOLIO(folio->index > in page_cache_delete_batch()
302 fbatch->folios[i]->index, folio); in page_cache_delete_batch()
308 folio->mapping = NULL; in page_cache_delete_batch()
309 /* Leave folio->index set: truncation lookup relies on it */ in page_cache_delete_batch()
315 mapping->nrpages -= total_pages; in page_cache_delete_batch()
326 spin_lock(&mapping->host->i_lock); in delete_from_page_cache_batch()
327 xa_lock_irq(&mapping->i_pages); in delete_from_page_cache_batch()
329 struct folio *folio = fbatch->folios[i]; in delete_from_page_cache_batch()
335 xa_unlock_irq(&mapping->i_pages); in delete_from_page_cache_batch()
337 inode_add_lru(mapping->host); in delete_from_page_cache_batch()
338 spin_unlock(&mapping->host->i_lock); in delete_from_page_cache_batch()
341 filemap_free_folio(mapping, fbatch->folios[i]); in delete_from_page_cache_batch()
347 /* Check for outstanding write errors */ in filemap_check_errors()
348 if (test_bit(AS_ENOSPC, &mapping->flags) && in filemap_check_errors()
349 test_and_clear_bit(AS_ENOSPC, &mapping->flags)) in filemap_check_errors()
350 ret = -ENOSPC; in filemap_check_errors()
351 if (test_bit(AS_EIO, &mapping->flags) && in filemap_check_errors()
352 test_and_clear_bit(AS_EIO, &mapping->flags)) in filemap_check_errors()
353 ret = -EIO; in filemap_check_errors()
360 /* Check for outstanding write errors */ in filemap_check_and_keep_errors()
361 if (test_bit(AS_EIO, &mapping->flags)) in filemap_check_and_keep_errors()
362 return -EIO; in filemap_check_and_keep_errors()
363 if (test_bit(AS_ENOSPC, &mapping->flags)) in filemap_check_and_keep_errors()
364 return -ENOSPC; in filemap_check_and_keep_errors()
369 * filemap_fdatawrite_wbc - start writeback on mapping dirty pages in range
370 * @mapping: address space structure to write
373 * Call writepages on the mapping using the provided wbc to control the
376 * Return: %0 on success, negative error code otherwise.
387 wbc_attach_fdatawrite_inode(wbc, mapping->host); in filemap_fdatawrite_wbc()
395 * __filemap_fdatawrite_range - start writeback on mapping dirty pages in range
396 * @mapping: address space structure to write
409 * Return: %0 on success, negative error code otherwise.
444 * filemap_flush - mostly a non-blocking flush
447 * This is a mostly non-blocking flush. Not suitable for data-integrity
448 * purposes - I/O may not be started against all dirty pages.
450 * Return: %0 on success, negative error code otherwise.
459 * filemap_range_has_page - check if a page exists in range.
474 XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT); in filemap_range_has_page()
532 * filemap_fdatawait_range - wait for writeback to complete
533 * @mapping: address space structure to wait for
537 * Walk the list of under-writeback pages of the given address space
538 * in the given range and wait for all of them. Check error status of
556 * filemap_fdatawait_range_keep_errors - wait for writeback to complete
557 * @mapping: address space structure to wait for
561 * Walk the list of under-writeback pages of the given address space in the
562 * given range and wait for all of them. Unlike filemap_fdatawait_range(),
566 * call sites are system-wide / filesystem-wide data flushers: e.g. sync(2),
578 * file_fdatawait_range - wait for writeback to complete
579 * @file: file pointing to address space structure to wait for
583 * Walk the list of under-writeback pages of the address space that file
584 * refers to, in the given range and wait for all of them. Check error
585 * status of the address space vs. the file->f_wb_err cursor and return it.
591 * Return: error status of the address space vs. the file->f_wb_err cursor.
595 struct address_space *mapping = file->f_mapping; in file_fdatawait_range()
603 * filemap_fdatawait_keep_errors - wait for writeback without clearing errors
604 * @mapping: address space structure to wait for
606 * Walk the list of under-writeback pages of the given address space
607 * and wait for all of them. Unlike filemap_fdatawait(), this function
611 * call sites are system-wide / filesystem-wide data flushers: e.g. sync(2),
626 return mapping->nrpages; in mapping_needs_writeback()
632 XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT); in filemap_range_has_writeback()
655 * filemap_write_and_wait_range - write out & wait on a file range
660 * Write out and wait upon file offsets lstart->lend, inclusive.
663 * that this function can be used to write to the very end-of-file (end = -1).
680 * written partially (e.g. -ENOSPC), so we wait for it. in filemap_write_and_wait_range()
681 * But the -EIO is special case, it may indicate the worst in filemap_write_and_wait_range()
684 if (err != -EIO) in filemap_write_and_wait_range()
696 errseq_t eseq = errseq_set(&mapping->wb_err, err); in __filemap_set_wb_err()
703 * file_check_and_advance_wb_err - report wb error (if any) that was previously
705 * @file: struct file on which the error is being reported
720 * While we handle mapping->wb_err with atomic operations, the f_wb_err
724 * Return: %0 on success, negative error code otherwise.
729 errseq_t old = READ_ONCE(file->f_wb_err); in file_check_and_advance_wb_err()
730 struct address_space *mapping = file->f_mapping; in file_check_and_advance_wb_err()
733 if (errseq_check(&mapping->wb_err, old)) { in file_check_and_advance_wb_err()
735 spin_lock(&file->f_lock); in file_check_and_advance_wb_err()
736 old = file->f_wb_err; in file_check_and_advance_wb_err()
737 err = errseq_check_and_advance(&mapping->wb_err, in file_check_and_advance_wb_err()
738 &file->f_wb_err); in file_check_and_advance_wb_err()
740 spin_unlock(&file->f_lock); in file_check_and_advance_wb_err()
746 * that the legacy code would have had on these flags. in file_check_and_advance_wb_err()
748 clear_bit(AS_EIO, &mapping->flags); in file_check_and_advance_wb_err()
749 clear_bit(AS_ENOSPC, &mapping->flags); in file_check_and_advance_wb_err()
755 * file_write_and_wait_range - write out & wait on a file range
760 * Write out and wait upon file offsets lstart->lend, inclusive.
763 * that this function can be used to write to the very end-of-file (end = -1).
765 * After writing out and waiting on the data, we check and advance the
768 * Return: %0 on success, negative error code otherwise.
773 struct address_space *mapping = file->f_mapping; in file_write_and_wait_range()
782 if (err != -EIO) in file_write_and_wait_range()
793 * replace_page_cache_folio - replace a pagecache folio with a new one
797 * This function replaces a folio in the pagecache with a new one. On
807 struct address_space *mapping = old->mapping; in replace_page_cache_folio()
808 void (*free_folio)(struct folio *) = mapping->a_ops->free_folio; in replace_page_cache_folio()
809 pgoff_t offset = old->index; in replace_page_cache_folio()
810 XA_STATE(xas, &mapping->i_pages, offset); in replace_page_cache_folio()
814 VM_BUG_ON_FOLIO(new->mapping, new); in replace_page_cache_folio()
817 new->mapping = mapping; in replace_page_cache_folio()
818 new->index = offset; in replace_page_cache_folio()
825 old->mapping = NULL; in replace_page_cache_folio()
845 XA_STATE(xas, &mapping->i_pages, index); in __filemap_add_folio()
861 VM_BUG_ON_FOLIO(index & (folio_nr_pages(folio) - 1), folio); in __filemap_add_folio()
867 folio->mapping = mapping; in __filemap_add_folio()
868 folio->index = xas.xa_index; in __filemap_add_folio()
881 xas_set_err(&xas, -EEXIST); in __filemap_add_folio()
903 mapping->nrpages += nr; in __filemap_add_folio()
924 folio->mapping = NULL; in __filemap_add_folio()
925 /* Leave page->index set: truncation relies upon it */ in __filemap_add_folio()
981 * filemap_invalidate_lock_two - lock invalidate_lock for two mappings
994 down_write(&mapping1->invalidate_lock); in filemap_invalidate_lock_two()
996 down_write_nested(&mapping2->invalidate_lock, 1); in filemap_invalidate_lock_two()
1001 * filemap_invalidate_unlock_two - unlock invalidate_lock for two mappings
1012 up_write(&mapping1->invalidate_lock); in filemap_invalidate_unlock_two()
1014 up_write(&mapping2->invalidate_lock); in filemap_invalidate_unlock_two()
1019 * In order to wait for pages to become available there must be
1022 * waiters on the same queue and wake all when any of the pages
1048 * The page wait code treats the "wait->flags" somewhat unusually, because
1058 * and remove it from the wait queue.
1066 * WQ_FLAG_WOKEN bit, wake it up, and remove it from the wait queue.
1068 * This is the traditional exclusive wait.
1074 * cannot be taken, we stop walking the wait queue without waking
1081 static int wake_page_function(wait_queue_entry_t *wait, unsigned mode, int sync, void *arg) in wake_page_function() argument
1086 = container_of(wait, struct wait_page_queue, wait); in wake_page_function()
1092 * If it's a lock handoff wait, we get the bit for it, and in wake_page_function()
1095 flags = wait->flags; in wake_page_function()
1097 if (test_bit(key->bit_nr, &key->folio->flags)) in wake_page_function()
1098 return -1; in wake_page_function()
1100 if (test_and_set_bit(key->bit_nr, &key->folio->flags)) in wake_page_function()
1101 return -1; in wake_page_function()
1107 * We are holding the wait-queue lock, but the waiter that in wake_page_function()
1112 * afterwards to avoid any races. This store-release pairs in wake_page_function()
1113 * with the load-acquire in folio_wait_bit_common(). in wake_page_function()
1115 smp_store_release(&wait->flags, flags | WQ_FLAG_WOKEN); in wake_page_function()
1116 wake_up_state(wait->private, mode); in wake_page_function()
1120 * and we can unconditionally remove the wait entry. in wake_page_function()
1124 * After this list_del_init(&wait->entry) the wait entry in wake_page_function()
1125 * might be de-allocated and the process might even have in wake_page_function()
1128 list_del_init_careful(&wait->entry); in wake_page_function()
1142 spin_lock_irqsave(&q->lock, flags); in folio_wake_bit()
1147 * waiters, but the hashed waitqueue has waiters for other pages on it. in folio_wake_bit()
1150 * Note that, depending on the page pool (buddy, hugetlb, ZONE_DEVICE, in folio_wake_bit()
1157 spin_unlock_irqrestore(&q->lock, flags); in folio_wake_bit()
1165 * __folio_lock() waiting on then setting PG_locked.
1168 * folio_wait_writeback() waiting on PG_writeback.
1170 DROP, /* Drop ref to page before wait, no check when woken,
1171 * like folio_put_wait_locked() on PG_locked.
1180 struct wait_queue_entry *wait) in folio_trylock_flag() argument
1182 if (wait->flags & WQ_FLAG_EXCLUSIVE) { in folio_trylock_flag()
1183 if (test_and_set_bit(bit_nr, &folio->flags)) in folio_trylock_flag()
1185 } else if (test_bit(bit_nr, &folio->flags)) in folio_trylock_flag()
1188 wait->flags |= WQ_FLAG_WOKEN | WQ_FLAG_DONE; in folio_trylock_flag()
1201 wait_queue_entry_t *wait = &wait_page.wait; in folio_wait_bit_common() local
1213 init_wait(wait); in folio_wait_bit_common()
1214 wait->func = wake_page_function; in folio_wait_bit_common()
1219 wait->flags = 0; in folio_wait_bit_common()
1221 wait->flags = WQ_FLAG_EXCLUSIVE; in folio_wait_bit_common()
1222 if (--unfairness < 0) in folio_wait_bit_common()
1223 wait->flags |= WQ_FLAG_CUSTOM; in folio_wait_bit_common()
1234 * page queue), and add ourselves to the wait in folio_wait_bit_common()
1240 spin_lock_irq(&q->lock); in folio_wait_bit_common()
1242 if (!folio_trylock_flag(folio, bit_nr, wait)) in folio_wait_bit_common()
1243 __add_wait_queue_entry_tail(q, wait); in folio_wait_bit_common()
1244 spin_unlock_irq(&q->lock); in folio_wait_bit_common()
1247 * From now on, all the logic will be based on in folio_wait_bit_common()
1260 * be very careful with the 'wait->flags', because in folio_wait_bit_common()
1269 flags = smp_load_acquire(&wait->flags); in folio_wait_bit_common()
1278 /* If we were non-exclusive, we're done */ in folio_wait_bit_common()
1295 wait->flags |= WQ_FLAG_DONE; in folio_wait_bit_common()
1301 * waiter from the wait-queues, but the folio waiters bit will remain in folio_wait_bit_common()
1305 finish_wait(q, wait); in folio_wait_bit_common()
1313 * NOTE! The wait->flags weren't stable until we've done the in folio_wait_bit_common()
1320 * return value based on that state without races. in folio_wait_bit_common()
1322 * Also note that WQ_FLAG_WOKEN is sufficient for a non-exclusive in folio_wait_bit_common()
1326 return wait->flags & WQ_FLAG_DONE ? 0 : -EINTR; in folio_wait_bit_common()
1328 return wait->flags & WQ_FLAG_WOKEN ? 0 : -EINTR; in folio_wait_bit_common()
1333 * migration_entry_wait_on_locked - Wait for a migration entry to be removed
1337 * Wait for a migration entry referencing the given page to be removed. This is
1339 * this can be called without taking a reference on the page. Instead this
1352 wait_queue_entry_t *wait = &wait_page.wait; in migration_entry_wait_on_locked() local
1366 init_wait(wait); in migration_entry_wait_on_locked()
1367 wait->func = wake_page_function; in migration_entry_wait_on_locked()
1370 wait->flags = 0; in migration_entry_wait_on_locked()
1372 spin_lock_irq(&q->lock); in migration_entry_wait_on_locked()
1374 if (!folio_trylock_flag(folio, PG_locked, wait)) in migration_entry_wait_on_locked()
1375 __add_wait_queue_entry_tail(q, wait); in migration_entry_wait_on_locked()
1376 spin_unlock_irq(&q->lock); in migration_entry_wait_on_locked()
1391 flags = smp_load_acquire(&wait->flags); in migration_entry_wait_on_locked()
1402 finish_wait(q, wait); in migration_entry_wait_on_locked()
1424 * folio_put_wait_locked - Drop a reference and wait for it to be unlocked
1425 * @folio: The folio to wait for.
1428 * The caller should hold a reference on @folio. They expect the page to
1434 * Return: 0 if the folio was unlocked or -EINTR if interrupted by a signal.
1442 * folio_add_wait_queue - Add an arbitrary waiter to a folio's wait queue
1443 * @folio: Folio defining the wait queue of interest
1446 * Add an arbitrary @waiter to the wait queue for the nominated @folio.
1453 spin_lock_irqsave(&q->lock, flags); in folio_add_wait_queue()
1456 spin_unlock_irqrestore(&q->lock, flags); in folio_add_wait_queue()
1461 * folio_unlock - Unlock a locked folio.
1464 * Unlocks the folio and wakes up any thread sleeping on the page lock.
1481 * folio_end_read - End read on a folio.
1488 * sleeping on the lock. The folio will also be marked uptodate if all
1511 * folio_end_private_2 - Clear PG_private_2 and wake any waiters.
1514 * Clear the PG_private_2 bit on a folio and wake up any sleepers waiting for
1531 * folio_wait_private_2 - Wait for PG_private_2 to be cleared on a folio.
1532 * @folio: The folio to wait on.
1534 * Wait for PG_private_2 (aka PG_fscache) to be cleared on a folio.
1544 * folio_wait_private_2_killable - Wait for PG_private_2 to be cleared on a folio.
1545 * @folio: The folio to wait on.
1547 * Wait for PG_private_2 (aka PG_fscache) to be cleared on a folio or until a
1551 * - 0 if successful.
1552 * - -EINTR if a fatal signal was encountered.
1569 * folio_end_writeback - End writeback against a folio.
1594 * on truncation to wait for the clearing of PG_writeback. in folio_end_writeback()
1607 * __folio_lock - Get a lock on the folio, assuming we need to sleep to get it.
1624 static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) in __folio_lock_async() argument
1629 wait->folio = folio; in __folio_lock_async()
1630 wait->bit_nr = PG_locked; in __folio_lock_async()
1632 spin_lock_irq(&q->lock); in __folio_lock_async()
1633 __add_wait_queue_entry_tail(q, &wait->wait); in __folio_lock_async()
1637 * If we were successful now, we know we're still on the in __folio_lock_async()
1643 __remove_wait_queue(q, &wait->wait); in __folio_lock_async()
1645 ret = -EIOCBQUEUED; in __folio_lock_async()
1646 spin_unlock_irq(&q->lock); in __folio_lock_async()
1652 * 0 - folio is locked.
1653 * non-zero - folio is not locked.
1654 * mmap_lock or per-VMA lock has been released (mmap_read_unlock() or
1659 * with the folio locked and the mmap_lock/per-VMA lock is left unperturbed.
1663 unsigned int flags = vmf->flags; in __folio_lock_or_retry()
1667 * CAUTION! In this case, mmap_lock/per-VMA lock is not in __folio_lock_or_retry()
1696 * page_cache_next_miss() - Find the next gap in the page cache.
1701 * Search the range [index, min(index + max_scan - 1, ULONG_MAX)] for the
1711 * range specified (in which case 'return - index >= max_scan' will be true).
1712 * In the rare case of index wrap-around, 0 will be returned.
1717 XA_STATE(xas, &mapping->i_pages, index); in page_cache_next_miss()
1719 while (max_scan--) { in page_cache_next_miss()
1732 * page_cache_prev_miss() - Find the previous gap in the page cache.
1737 * Search the range [max(index - max_scan + 1, 0), index] for the
1747 * range specified (in which case 'index - return >= max_scan' will be true).
1748 * In the rare case of wrap-around, ULONG_MAX will be returned.
1753 XA_STATE(xas, &mapping->i_pages, index); in page_cache_prev_miss()
1755 while (max_scan--) { in page_cache_prev_miss()
1769 * On the lookup side:
1774 * On the removal side:
1783 * last refcount on the page, any page allocation must be freeable by
1788 * filemap_get_entry - Get a page cache entry.
1801 XA_STATE(xas, &mapping->i_pages, index); in filemap_get_entry()
1831 * __filemap_get_folio - Find and get a reference to a folio.
1862 return ERR_PTR(-EAGAIN); in __filemap_get_folio()
1869 if (unlikely(folio->mapping != mapping)) { in __filemap_get_folio()
1880 /* Clear idle flag for buffer write */ in __filemap_get_folio()
1908 if (index & ((1UL << order) - 1)) in __filemap_get_folio()
1914 err = -ENOMEM; in __filemap_get_folio()
1932 } while (order-- > 0); in __filemap_get_folio()
1934 if (err == -EEXIST) in __filemap_get_folio()
1947 return ERR_PTR(-ENOENT); in __filemap_get_folio()
1988 * find_get_entries - gang pagecache lookup
1997 * takes a reference on any actual folios it returns.
2000 * due to not-present entries or large folios.
2010 XA_STATE(xas, &mapping->i_pages, *start); in find_get_entries()
2015 indices[fbatch->nr] = xas.xa_index; in find_get_entries()
2023 int idx = folio_batch_count(fbatch) - 1; in find_get_entries()
2025 folio = fbatch->folios[idx]; in find_get_entries()
2034 * find_lock_entries - Find a batch of pagecache entries.
2048 * due to not-present entries, large folios, folios which could not be
2056 XA_STATE(xas, &mapping->i_pages, *start); in find_lock_entries()
2062 if (folio->index < *start) in find_lock_entries()
2064 if (folio_next_index(folio) - 1 > end) in find_lock_entries()
2068 if (folio->mapping != mapping || in find_lock_entries()
2074 indices[fbatch->nr] = xas.xa_index; in find_lock_entries()
2087 int idx = folio_batch_count(fbatch) - 1; in find_lock_entries()
2089 folio = fbatch->folios[idx]; in find_lock_entries()
2098 * filemap_get_folios - Get a batch of folios
2119 * filemap_get_folios_contig - Get a batch of contiguous folios
2136 XA_STATE(xas, &mapping->i_pages, *start); in filemap_get_folios_contig()
2161 *start = folio->index + nr; in filemap_get_folios_contig()
2176 folio = fbatch->folios[nr - 1]; in filemap_get_folios_contig()
2186 * filemap_get_folios_tag - Get a batch of folios matching @tag
2207 XA_STATE(xas, &mapping->i_pages, *start); in filemap_get_folios_tag()
2221 *start = folio->index + nr; in filemap_get_folios_tag()
2228 * breaks the iteration when there is a page at index -1 but that is in filemap_get_folios_tag()
2231 if (end == (pgoff_t)-1) in filemap_get_folios_tag()
2232 *start = (pgoff_t)-1; in filemap_get_folios_tag()
2246 * ---R__________________________________________B__________
2259 ra->ra_pages /= 4; in shrink_readahead_size_eio()
2263 * filemap_get_read_batch - Get a batch of folios for read
2274 XA_STATE(xas, &mapping->i_pages, index); in filemap_get_read_batch()
2297 xas_advance(&xas, folio_next_index(folio) - 1); in filemap_get_read_batch()
2336 shrink_readahead_size_eio(&file->f_ra); in filemap_read_folio()
2337 return -EIO; in filemap_read_folio()
2349 if (!mapping->a_ops->is_partially_uptodate) in filemap_range_uptodate()
2351 if (mapping->host->i_blkbits >= folio_shift(folio)) in filemap_range_uptodate()
2355 count -= folio_pos(folio) - pos; in filemap_range_uptodate()
2358 pos -= folio_pos(folio); in filemap_range_uptodate()
2361 return mapping->a_ops->is_partially_uptodate(folio, pos, count); in filemap_range_uptodate()
2370 if (iocb->ki_flags & IOCB_NOWAIT) { in filemap_update_page()
2372 return -EAGAIN; in filemap_update_page()
2378 error = -EAGAIN; in filemap_update_page()
2379 if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_NOIO)) in filemap_update_page()
2381 if (!(iocb->ki_flags & IOCB_WAITQ)) { in filemap_update_page()
2390 error = __folio_lock_async(folio, iocb->ki_waitq); in filemap_update_page()
2396 if (!folio->mapping) in filemap_update_page()
2400 if (filemap_range_uptodate(mapping, iocb->ki_pos, count, folio, in filemap_update_page()
2404 error = -EAGAIN; in filemap_update_page()
2405 if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) in filemap_update_page()
2408 error = filemap_read_folio(iocb->ki_filp, mapping->a_ops->read_folio, in filemap_update_page()
2429 return -ENOMEM; in filemap_create_folio()
2440 * pages or ->readahead() that need to hold invalidate_lock in filemap_create_folio()
2447 if (error == -EEXIST) in filemap_create_folio()
2452 error = filemap_read_folio(file, mapping->a_ops->read_folio, folio); in filemap_create_folio()
2469 DEFINE_READAHEAD(ractl, file, &file->f_ra, mapping, folio->index); in filemap_readahead()
2471 if (iocb->ki_flags & IOCB_NOIO) in filemap_readahead()
2472 return -EAGAIN; in filemap_readahead()
2473 page_cache_async_ra(&ractl, folio, last_index - folio->index); in filemap_readahead()
2480 struct file *filp = iocb->ki_filp; in filemap_get_pages()
2481 struct address_space *mapping = filp->f_mapping; in filemap_get_pages()
2482 struct file_ra_state *ra = &filp->f_ra; in filemap_get_pages()
2483 pgoff_t index = iocb->ki_pos >> PAGE_SHIFT; in filemap_get_pages()
2489 last_index = DIV_ROUND_UP(iocb->ki_pos + count, PAGE_SIZE); in filemap_get_pages()
2492 return -EINTR; in filemap_get_pages()
2494 filemap_get_read_batch(mapping, index, last_index - 1, fbatch); in filemap_get_pages()
2496 if (iocb->ki_flags & IOCB_NOIO) in filemap_get_pages()
2497 return -EAGAIN; in filemap_get_pages()
2499 last_index - index); in filemap_get_pages()
2500 filemap_get_read_batch(mapping, index, last_index - 1, fbatch); in filemap_get_pages()
2503 if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ)) in filemap_get_pages()
2504 return -EAGAIN; in filemap_get_pages()
2506 iocb->ki_pos >> PAGE_SHIFT, fbatch); in filemap_get_pages()
2512 folio = fbatch->folios[folio_batch_count(fbatch) - 1]; in filemap_get_pages()
2519 if ((iocb->ki_flags & IOCB_WAITQ) && in filemap_get_pages()
2521 iocb->ki_flags |= IOCB_NOWAIT; in filemap_get_pages()
2532 if (likely(--fbatch->nr)) in filemap_get_pages()
2547 * filemap_read - Read data from the page cache.
2562 struct file *filp = iocb->ki_filp; in filemap_read()
2563 struct file_ra_state *ra = &filp->f_ra; in filemap_read()
2564 struct address_space *mapping = filp->f_mapping; in filemap_read()
2565 struct inode *inode = mapping->host; in filemap_read()
2570 loff_t last_pos = ra->prev_pos; in filemap_read()
2572 if (unlikely(iocb->ki_pos >= inode->i_sb->s_maxbytes)) in filemap_read()
2577 iov_iter_truncate(iter, inode->i_sb->s_maxbytes); in filemap_read()
2585 * can no longer safely return -EIOCBQUEUED. Hence mark in filemap_read()
2588 if ((iocb->ki_flags & IOCB_WAITQ) && already_read) in filemap_read()
2589 iocb->ki_flags |= IOCB_NOWAIT; in filemap_read()
2591 if (unlikely(iocb->ki_pos >= i_size_read(inode))) in filemap_read()
2594 error = filemap_get_pages(iocb, iter->count, &fbatch, false); in filemap_read()
2602 * the correct value for "nr", which means the zero-filled in filemap_read()
2604 * another truncate extends the file - this is desired though). in filemap_read()
2607 if (unlikely(iocb->ki_pos >= isize)) in filemap_read()
2609 end_offset = min_t(loff_t, isize, iocb->ki_pos + iter->count); in filemap_read()
2613 * block_write_end()->mark_buffer_dirty() or other page in filemap_read()
2630 if (!pos_same_folio(iocb->ki_pos, last_pos - 1, in filemap_read()
2637 size_t offset = iocb->ki_pos & (fsize - 1); in filemap_read()
2638 size_t bytes = min_t(loff_t, end_offset - iocb->ki_pos, in filemap_read()
2639 fsize - offset); in filemap_read()
2649 * before reading the folio on the kernel side. in filemap_read()
2657 iocb->ki_pos += copied; in filemap_read()
2658 last_pos = iocb->ki_pos; in filemap_read()
2661 error = -EFAULT; in filemap_read()
2669 } while (iov_iter_count(iter) && iocb->ki_pos < isize && !error); in filemap_read()
2672 ra->prev_pos = last_pos; in filemap_read()
2679 struct address_space *mapping = iocb->ki_filp->f_mapping; in kiocb_write_and_wait()
2680 loff_t pos = iocb->ki_pos; in kiocb_write_and_wait()
2681 loff_t end = pos + count - 1; in kiocb_write_and_wait()
2683 if (iocb->ki_flags & IOCB_NOWAIT) { in kiocb_write_and_wait()
2685 return -EAGAIN; in kiocb_write_and_wait()
2695 struct address_space *mapping = iocb->ki_filp->f_mapping; in kiocb_invalidate_pages()
2696 loff_t pos = iocb->ki_pos; in kiocb_invalidate_pages()
2697 loff_t end = pos + count - 1; in kiocb_invalidate_pages()
2700 if (iocb->ki_flags & IOCB_NOWAIT) { in kiocb_invalidate_pages()
2703 return -EAGAIN; in kiocb_invalidate_pages()
2711 * After a write we want buffered reads to be sure to go to disk to get in kiocb_invalidate_pages()
2713 * about to write. We do this *before* the write so that we can return in kiocb_invalidate_pages()
2714 * without clobbering -EIOCBQUEUED from ->direct_IO(). in kiocb_invalidate_pages()
2722 * generic_file_read_iter - generic filesystem read routine
2729 * The IOCB_NOWAIT flag in iocb->ki_flags indicates that -EAGAIN shall
2733 * The IOCB_NOIO flag in iocb->ki_flags indicates that no new I/O
2735 * can be read, -EAGAIN shall be returned. When readahead would be
2751 if (iocb->ki_flags & IOCB_DIRECT) { in generic_file_read_iter()
2752 struct file *file = iocb->ki_filp; in generic_file_read_iter()
2753 struct address_space *mapping = file->f_mapping; in generic_file_read_iter()
2754 struct inode *inode = mapping->host; in generic_file_read_iter()
2761 retval = mapping->a_ops->direct_IO(iocb, iter); in generic_file_read_iter()
2763 iocb->ki_pos += retval; in generic_file_read_iter()
2764 count -= retval; in generic_file_read_iter()
2766 if (retval != -EIOCBQUEUED) in generic_file_read_iter()
2767 iov_iter_revert(iter, count - iov_iter_count(iter)); in generic_file_read_iter()
2780 if (iocb->ki_pos >= i_size_read(inode)) in generic_file_read_iter()
2798 size = min(size, folio_size(folio) - offset); in splice_folio_into_pipe()
2802 !pipe_full(pipe->head, pipe->tail, pipe->max_usage)) { in splice_folio_into_pipe()
2804 size_t part = min_t(size_t, PAGE_SIZE - offset, size - spliced); in splice_folio_into_pipe()
2813 pipe->head++; in splice_folio_into_pipe()
2823 * filemap_splice_read - Splice data from a file's pagecache into a pipe
2834 * Return: On success, the number of bytes read will be returned and *@ppos
2836 * to be read; -EAGAIN will be returned if the pipe had no space, and some
2837 * other negative error code will be returned on error. A short read may occur
2852 if (unlikely(*ppos >= in->f_mapping->host->i_sb->s_maxbytes)) in filemap_splice_read()
2859 used = pipe_occupancy(pipe->head, pipe->tail); in filemap_splice_read()
2860 npages = max_t(ssize_t, pipe->max_usage - used, 0); in filemap_splice_read()
2868 if (*ppos >= i_size_read(in->f_mapping->host)) in filemap_splice_read()
2880 * the correct value for "nr", which means the zero-filled in filemap_splice_read()
2882 * another truncate extends the file - this is desired though). in filemap_splice_read()
2884 isize = i_size_read(in->f_mapping->host); in filemap_splice_read()
2893 writably_mapped = mapping_writably_mapped(in->f_mapping); in filemap_splice_read()
2906 * before reading the folio on the kernel side. in filemap_splice_read()
2911 n = min_t(loff_t, len, isize - *ppos); in filemap_splice_read()
2915 len -= n; in filemap_splice_read()
2918 in->f_ra.prev_pos = *ppos; in filemap_splice_read()
2919 if (pipe_full(pipe->head, pipe->tail, pipe->max_usage)) in filemap_splice_read()
2938 const struct address_space_operations *ops = mapping->a_ops; in folio_seek_hole_data()
2939 size_t offset, bsz = i_blocksize(mapping->host); in folio_seek_hole_data()
2943 if (!ops->is_partially_uptodate) in folio_seek_hole_data()
2949 if (unlikely(folio->mapping != mapping)) in folio_seek_hole_data()
2952 offset = offset_in_folio(folio, start) & ~(bsz - 1); in folio_seek_hole_data()
2955 if (ops->is_partially_uptodate(folio, offset, bsz) == in folio_seek_hole_data()
2958 start = (start + bsz) & ~(bsz - 1); in folio_seek_hole_data()
2970 return PAGE_SIZE << xa_get_order(xas->xa, xas->xa_index); in seek_folio_size()
2975 * mapping_seek_hole_data - Seek for SEEK_DATA / SEEK_HOLE in the page cache.
2984 * entirely memory-based such as tmpfs, and filesystems which support
2987 * Return: The requested offset on success, or -ENXIO if @whence specifies
2989 * after @end - 1, so SEEK_HOLE returns @end if all the bytes between @start
2995 XA_STATE(xas, &mapping->i_pages, start >> PAGE_SHIFT); in mapping_seek_hole_data()
2996 pgoff_t max = (end - 1) >> PAGE_SHIFT; in mapping_seek_hole_data()
3001 return -ENXIO; in mapping_seek_hole_data()
3028 start = -ENXIO; in mapping_seek_hole_data()
3041 * lock_folio_maybe_drop_mmap - lock the page, possibly dropping the mmap_lock
3042 * @vmf - the vm_fault for this fault.
3043 * @folio - the folio to lock.
3044 * @fpin - the pointer to the file we may pin (or is already pinned).
3063 if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT) in lock_folio_maybe_drop_mmap()
3067 if (vmf->flags & FAULT_FLAG_KILLABLE) { in lock_folio_maybe_drop_mmap()
3095 struct file *file = vmf->vma->vm_file; in do_sync_mmap_readahead()
3096 struct file_ra_state *ra = &file->f_ra; in do_sync_mmap_readahead()
3097 struct address_space *mapping = file->f_mapping; in do_sync_mmap_readahead()
3098 DEFINE_READAHEAD(ractl, file, ra, mapping, vmf->pgoff); in do_sync_mmap_readahead()
3100 unsigned long vm_flags = vmf->vma->vm_flags; in do_sync_mmap_readahead()
3107 ractl._index &= ~((unsigned long)HPAGE_PMD_NR - 1); in do_sync_mmap_readahead()
3108 ra->size = HPAGE_PMD_NR; in do_sync_mmap_readahead()
3114 ra->size *= 2; in do_sync_mmap_readahead()
3115 ra->async_size = HPAGE_PMD_NR; in do_sync_mmap_readahead()
3121 /* If we don't want any read-ahead, don't bother */ in do_sync_mmap_readahead()
3124 if (!ra->ra_pages) in do_sync_mmap_readahead()
3129 page_cache_sync_ra(&ractl, ra->ra_pages); in do_sync_mmap_readahead()
3134 mmap_miss = READ_ONCE(ra->mmap_miss); in do_sync_mmap_readahead()
3136 WRITE_ONCE(ra->mmap_miss, ++mmap_miss); in do_sync_mmap_readahead()
3140 * stop bothering with read-ahead. It will only hurt. in do_sync_mmap_readahead()
3146 * mmap read-around in do_sync_mmap_readahead()
3149 ra->start = max_t(long, 0, vmf->pgoff - ra->ra_pages / 2); in do_sync_mmap_readahead()
3150 ra->size = ra->ra_pages; in do_sync_mmap_readahead()
3151 ra->async_size = ra->ra_pages / 4; in do_sync_mmap_readahead()
3152 ractl._index = ra->start; in do_sync_mmap_readahead()
3165 struct file *file = vmf->vma->vm_file; in do_async_mmap_readahead()
3166 struct file_ra_state *ra = &file->f_ra; in do_async_mmap_readahead()
3167 DEFINE_READAHEAD(ractl, file, ra, file->f_mapping, vmf->pgoff); in do_async_mmap_readahead()
3171 /* If we don't want any read-ahead, don't bother */ in do_async_mmap_readahead()
3172 if (vmf->vma->vm_flags & VM_RAND_READ || !ra->ra_pages) in do_async_mmap_readahead()
3175 mmap_miss = READ_ONCE(ra->mmap_miss); in do_async_mmap_readahead()
3177 WRITE_ONCE(ra->mmap_miss, --mmap_miss); in do_async_mmap_readahead()
3181 page_cache_async_ra(&ractl, folio, ra->ra_pages); in do_async_mmap_readahead()
3187 * filemap_fault - read in file data for page fault handling
3197 * vma->vm_mm->mmap_lock must be held on entry.
3207 * Return: bitwise-OR of %VM_FAULT_ codes.
3212 struct file *file = vmf->vma->vm_file; in filemap_fault()
3214 struct address_space *mapping = file->f_mapping; in filemap_fault()
3215 struct inode *inode = mapping->host; in filemap_fault()
3216 pgoff_t max_idx, index = vmf->pgoff; in filemap_fault()
3234 if (!(vmf->flags & FAULT_FLAG_TRIED)) in filemap_fault()
3243 count_memcg_event_mm(vmf->vma->vm_mm, PGMAJFAULT); in filemap_fault()
3257 vmf->gfp_mask); in filemap_fault()
3270 if (unlikely(folio->mapping != mapping)) { in filemap_fault()
3279 * that it's up-to-date. If not, it is going to be due to an error, in filemap_fault()
3305 * time to return to the upper layer and have it re-find the vma and in filemap_fault()
3316 * Found the page and have a reference on it. in filemap_fault()
3326 vmf->page = folio_file_page(folio, index); in filemap_fault()
3331 * Umm, take care of errors if the page isn't up-to-date. in filemap_fault()
3332 * Try to re-read it _once_. We do this synchronously, in filemap_fault()
3337 error = filemap_read_folio(file, mapping->a_ops->read_folio, folio); in filemap_fault()
3351 * re-find the vma and come back and find our hopefully still populated in filemap_fault()
3367 struct mm_struct *mm = vmf->vma->vm_mm; in filemap_map_pmd()
3370 if (pmd_trans_huge(*vmf->pmd)) { in filemap_map_pmd()
3376 if (pmd_none(*vmf->pmd) && folio_test_pmd_mappable(folio)) { in filemap_map_pmd()
3386 if (pmd_none(*vmf->pmd) && vmf->prealloc_pte) in filemap_map_pmd()
3387 pmd_install(mm, vmf->pmd, &vmf->prealloc_pte); in filemap_map_pmd()
3416 if (folio->mapping != mapping) in next_uptodate_folio()
3420 max_idx = DIV_ROUND_UP(i_size_read(mapping->host), PAGE_SIZE); in next_uptodate_folio()
3421 if (xas->xa_index >= max_idx) in next_uptodate_folio()
3445 pte_t *old_ptep = vmf->pte; in filemap_map_folio_range()
3456 * fault-around logic. in filemap_map_folio_range()
3458 if (!pte_none(ptep_get(&vmf->pte[count]))) in filemap_map_folio_range()
3467 if (in_range(vmf->address, addr, count * PAGE_SIZE)) in filemap_map_folio_range()
3473 vmf->pte += count; in filemap_map_folio_range()
3476 } while (--nr_pages > 0); in filemap_map_folio_range()
3481 if (in_range(vmf->address, addr, count * PAGE_SIZE)) in filemap_map_folio_range()
3485 vmf->pte = old_ptep; in filemap_map_folio_range()
3495 struct page *page = &folio->page; in filemap_map_order0_folio()
3505 * the fault-around logic. in filemap_map_order0_folio()
3507 if (!pte_none(ptep_get(vmf->pte))) in filemap_map_order0_folio()
3510 if (vmf->address == addr) in filemap_map_order0_folio()
3522 struct vm_area_struct *vma = vmf->vma; in filemap_map_pages()
3523 struct file *file = vma->vm_file; in filemap_map_pages()
3524 struct address_space *mapping = file->f_mapping; in filemap_map_pages()
3527 XA_STATE(xas, &mapping->i_pages, start_pgoff); in filemap_map_pages()
3542 addr = vma->vm_start + ((start_pgoff - vma->vm_pgoff) << PAGE_SHIFT); in filemap_map_pages()
3543 vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, addr, &vmf->ptl); in filemap_map_pages()
3544 if (!vmf->pte) { in filemap_map_pages()
3552 addr += (xas.xa_index - last_pgoff) << PAGE_SHIFT; in filemap_map_pages()
3553 vmf->pte += xas.xa_index - last_pgoff; in filemap_map_pages()
3555 end = folio_next_index(folio) - 1; in filemap_map_pages()
3556 nr_pages = min(end, end_pgoff) - xas.xa_index + 1; in filemap_map_pages()
3563 xas.xa_index - folio->index, addr, in filemap_map_pages()
3569 pte_unmap_unlock(vmf->pte, vmf->ptl); in filemap_map_pages()
3573 mmap_miss_saved = READ_ONCE(file->f_ra.mmap_miss); in filemap_map_pages()
3575 WRITE_ONCE(file->f_ra.mmap_miss, 0); in filemap_map_pages()
3577 WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss_saved - mmap_miss); in filemap_map_pages()
3585 struct address_space *mapping = vmf->vma->vm_file->f_mapping; in filemap_page_mkwrite()
3586 struct folio *folio = page_folio(vmf->page); in filemap_page_mkwrite()
3589 sb_start_pagefault(mapping->host->i_sb); in filemap_page_mkwrite()
3590 file_update_time(vmf->vma->vm_file); in filemap_page_mkwrite()
3592 if (folio->mapping != mapping) { in filemap_page_mkwrite()
3605 sb_end_pagefault(mapping->host->i_sb); in filemap_page_mkwrite()
3619 struct address_space *mapping = file->f_mapping; in generic_file_mmap()
3621 if (!mapping->a_ops->read_folio) in generic_file_mmap()
3622 return -ENOEXEC; in generic_file_mmap()
3624 vma->vm_ops = &generic_file_vm_ops; in generic_file_mmap()
3629 * This is for filesystems which do not implement ->writepage.
3634 return -EINVAL; in generic_file_readonly_mmap()
3644 return -ENOSYS; in generic_file_mmap()
3648 return -ENOSYS; in generic_file_readonly_mmap()
3663 filler = mapping->a_ops->read_folio; in do_read_cache_folio()
3669 return ERR_PTR(-ENOMEM); in do_read_cache_folio()
3673 if (err == -EEXIST) in do_read_cache_folio()
3690 if (!folio->mapping) { in do_read_cache_folio()
3717 * read_cache_folio - Read into page cache, fill it if needed.
3720 * @filler: Function to perform the read, or NULL to use aops->read_folio().
3729 * Context: May sleep. Expects mapping->invalidate_lock to be held.
3730 * Return: An uptodate folio on success, ERR_PTR() on failure.
3741 * mapping_read_folio_gfp - Read into page cache, using specified allocation flags.
3750 * possible and so is EINTR. If ->read_folio returns another error,
3753 * The function expects mapping->invalidate_lock to be already held.
3755 * Return: Uptodate folio on success, ERR_PTR() on failure.
3771 return &folio->page; in do_read_cache_page()
3784 * read_cache_page_gfp - read into page cache, using specified page allocation flags.
3792 * If the page does not get brought uptodate, return -EIO.
3794 * The function expects mapping->invalidate_lock to be already held.
3796 * Return: up to date page on success, ERR_PTR() on failure.
3807 * Warn about a page cache invalidation failure during a direct I/O write.
3815 errseq_set(&filp->f_mapping->wb_err, -EIO); in dio_warn_stale_pagecache()
3820 …pr_crit("Page cache invalidation failure on direct I/O. Possible data corruption due to collision… in dio_warn_stale_pagecache()
3821 pr_crit("File: %s PID: %d Comm: %.20s\n", path, current->pid, in dio_warn_stale_pagecache()
3822 current->comm); in dio_warn_stale_pagecache()
3828 struct address_space *mapping = iocb->ki_filp->f_mapping; in kiocb_invalidate_post_direct_write()
3830 if (mapping->nrpages && in kiocb_invalidate_post_direct_write()
3832 iocb->ki_pos >> PAGE_SHIFT, in kiocb_invalidate_post_direct_write()
3833 (iocb->ki_pos + count - 1) >> PAGE_SHIFT)) in kiocb_invalidate_post_direct_write()
3834 dio_warn_stale_pagecache(iocb->ki_filp); in kiocb_invalidate_post_direct_write()
3840 struct address_space *mapping = iocb->ki_filp->f_mapping; in generic_file_direct_write()
3846 * to buffered write. in generic_file_direct_write()
3850 if (written == -EBUSY) in generic_file_direct_write()
3855 written = mapping->a_ops->direct_IO(iocb, from); in generic_file_direct_write()
3859 * cached by non-direct readahead, or faulted in by get_user_pages() in generic_file_direct_write()
3860 * if the source of the write was an mmap'ed region of the file in generic_file_direct_write()
3863 * fails, tough, the write still worked... in generic_file_direct_write()
3875 struct inode *inode = mapping->host; in generic_file_direct_write()
3876 loff_t pos = iocb->ki_pos; in generic_file_direct_write()
3880 write_len -= written; in generic_file_direct_write()
3881 if (pos > i_size_read(inode) && !S_ISBLK(inode->i_mode)) { in generic_file_direct_write()
3885 iocb->ki_pos = pos; in generic_file_direct_write()
3887 if (written != -EIOCBQUEUED) in generic_file_direct_write()
3888 iov_iter_revert(from, write_len - iov_iter_count(from)); in generic_file_direct_write()
3895 struct file *file = iocb->ki_filp; in generic_perform_write()
3896 loff_t pos = iocb->ki_pos; in generic_perform_write()
3897 struct address_space *mapping = file->f_mapping; in generic_perform_write()
3898 const struct address_space_operations *a_ops = mapping->a_ops; in generic_perform_write()
3905 unsigned long bytes; /* Bytes to write to page */ in generic_perform_write()
3909 offset = (pos & (PAGE_SIZE - 1)); in generic_perform_write()
3910 bytes = min_t(unsigned long, PAGE_SIZE - offset, in generic_perform_write()
3916 * Otherwise there's a nasty deadlock on copying from the in generic_perform_write()
3918 * up-to-date. in generic_perform_write()
3921 status = -EFAULT; in generic_perform_write()
3926 status = -EINTR; in generic_perform_write()
3930 status = a_ops->write_begin(file, mapping, pos, bytes, in generic_perform_write()
3941 status = a_ops->write_end(file, mapping, pos, bytes, copied, in generic_perform_write()
3944 iov_iter_revert(i, copied - max(status, 0L)); in generic_perform_write()
3952 * A short copy made ->write_end() reject the in generic_perform_write()
3969 iocb->ki_pos += written; in generic_perform_write()
3975 * __generic_file_write_iter - write data to a file
3977 * @from: iov_iter with data to write
3981 * modification times and calls proper subroutines depending on whether we
3982 * do direct IO or a standard buffered write.
3984 * It expects i_rwsem to be grabbed unless we work on a block device or similar
3987 * This function does *not* take care of syncing data in case of O_SYNC write.
3997 struct file *file = iocb->ki_filp; in __generic_file_write_iter()
3998 struct address_space *mapping = file->f_mapping; in __generic_file_write_iter()
3999 struct inode *inode = mapping->host; in __generic_file_write_iter()
4010 if (iocb->ki_flags & IOCB_DIRECT) { in __generic_file_write_iter()
4013 * If the write stopped short of completing, fall back to in __generic_file_write_iter()
4015 * holes, for example. For DAX files, a buffered write will in __generic_file_write_iter()
4017 * page-cache pages correctly). in __generic_file_write_iter()
4030 * generic_file_write_iter - write data to a file
4032 * @from: iov_iter with data to write
4039 * vfs_fsync_range() failed for a synchronous write
4044 struct file *file = iocb->ki_filp; in generic_file_write_iter()
4045 struct inode *inode = file->f_mapping->host; in generic_file_write_iter()
4061 * filemap_release_folio() - Release fs-specific metadata on a folio.
4066 * (presumably at folio->private).
4068 * This will also be called if the private_2 flag is set on a page,
4079 struct address_space * const mapping = folio->mapping; in filemap_release_folio()
4087 if (mapping && mapping->a_ops->release_folio) in filemap_release_folio()
4088 return mapping->a_ops->release_folio(folio, gfp); in filemap_release_folio()
4095 * filemap_cachestat() - compute the page cache statistics of a mapping
4099 * @cs: the cachestat struct to write the result to.
4109 XA_STATE(xas, &mapping->i_pages, first_index); in filemap_cachestat()
4126 * the rcu-protected xarray. in filemap_cachestat()
4135 folio_last_index = folio_first_index + nr_pages - 1; in filemap_cachestat()
4139 nr_pages -= first_index - folio_first_index; in filemap_cachestat()
4142 nr_pages -= folio_last_index - last_index; in filemap_cachestat()
4149 cs->nr_evicted += nr_pages; in filemap_cachestat()
4153 /* shmem file - in swap cache */ in filemap_cachestat()
4160 cs->nr_recently_evicted += nr_pages; in filemap_cachestat()
4166 cs->nr_cache += nr_pages; in filemap_cachestat()
4169 cs->nr_dirty += nr_pages; in filemap_cachestat()
4172 cs->nr_writeback += nr_pages; in filemap_cachestat()
4195 * there is memory pressure on the system.
4197 * `off` and `len` must be non-negative integers. If `len` > 0,
4211 * zero - success
4212 * -EFAULT - cstat or cstat_range points to an illegal address
4213 * -EINVAL - invalid flags
4214 * -EBADF - invalid file descriptor
4215 * -EOPNOTSUPP - file descriptor is of a hugetlbfs file
4228 return -EBADF; in SYSCALL_DEFINE4()
4233 return -EFAULT; in SYSCALL_DEFINE4()
4239 return -EOPNOTSUPP; in SYSCALL_DEFINE4()
4244 return -EINVAL; in SYSCALL_DEFINE4()
4249 csr.len == 0 ? ULONG_MAX : (csr.off + csr.len - 1) >> PAGE_SHIFT; in SYSCALL_DEFINE4()
4251 mapping = f.file->f_mapping; in SYSCALL_DEFINE4()
4256 return -EFAULT; in SYSCALL_DEFINE4()