/** * filemap_set_wb_err - set a writeback error on an address_space * @mapping: mapping in which to set writeback error * @err: error to be set in mapping * * When writeback fails in some way, we must record that error so that * userspace can be informed when fsync and the like are called. We endeavor * to report errors on any file that was open at the time of the error. Some * internal callers also need to know when writeback errors have occurred. * * When a writeback error occurs, most filesystems will want to call * filemap_set_wb_err to record the error in the mapping so that it will be * automatically reported whenever fsync is called on the file.
*/ staticinlinevoid filemap_set_wb_err(struct address_space *mapping, int err)
{ /* Fastpath for common case of no error */ if (unlikely(err))
__filemap_set_wb_err(mapping, err);
}
/** * filemap_check_wb_err - has an error occurred since the mark was sampled? * @mapping: mapping to check for writeback errors * @since: previously-sampled errseq_t * * Grab the errseq_t value from the mapping, and see if it has changed "since" * the given value was sampled. * * If it has then report the latest error set, otherwise return 0.
*/ staticinlineint filemap_check_wb_err(struct address_space *mapping,
errseq_t since)
{ return errseq_check(&mapping->wb_err, since);
}
/** * filemap_sample_wb_err - sample the current errseq_t to test for later errors * @mapping: mapping to be sampled * * Writeback errors are always reported relative to a particular sample point * in the past. This function provides those sample points.
*/ staticinline errseq_t filemap_sample_wb_err(struct address_space *mapping)
{ return errseq_sample(&mapping->wb_err);
}
/** * file_sample_sb_err - sample the current errseq_t to test for later errors * @file: file pointer to be sampled * * Grab the most current superblock-level errseq_t value for the given * struct file.
*/ staticinline errseq_t file_sample_sb_err(struct file *file)
{ return errseq_sample(&file->f_path.dentry->d_sb->s_wb_err);
}
/* * Flush file data before changing attributes. Caller must hold any locks * required to prevent further writes to this file until we're done setting * flags.
*/ staticinlineint inode_drain_writes(struct inode *inode)
{
inode_dio_wait(inode); return filemap_write_and_wait(inode->i_mapping);
}
/* * mapping_shrinkable - test if page cache state allows inode reclaim * @mapping: the page cache mapping * * This checks the mapping's cache state for the pupose of inode * reclaim and LRU management. * * The caller is expected to hold the i_lock, but is not required to * hold the i_pages lock, which usually protects cache state. That's * because the i_lock and the list_lru lock that protect the inode and * its LRU state don't nest inside the irq-safe i_pages lock. * * Cache deletions are performed under the i_lock, which ensures that * when an inode goes empty, it will reliably get queued on the LRU. * * Cache additions do not acquire the i_lock and may race with this * check, in which case we'll report the inode as shrinkable when it * has cache pages. This is okay: the shrinker also checks the * refcount and the referenced bit, which will be elevated or set in * the process of adding new cache pages to an inode.
*/ staticinlinebool mapping_shrinkable(struct address_space *mapping)
{ void *head;
/* * On highmem systems, there could be lowmem pressure from the * inodes before there is highmem pressure from the page * cache. Make inodes shrinkable regardless of cache state.
*/ if (IS_ENABLED(CONFIG_HIGHMEM)) returntrue;
/* Cache completely empty? Shrink away. */
head = rcu_access_pointer(mapping->i_pages.xa_head); if (!head) returntrue;
/* * The xarray stores single offset-0 entries directly in the * head pointer, which allows non-resident page cache entries * to escape the shadow shrinker's list of xarray nodes. The * inode shrinker needs to pick them up under memory pressure.
*/ if (!xa_is_node(head) && xa_is_value(head)) returntrue;
returnfalse;
}
/* * Bits in mapping->flags.
*/ enum mapping_flags {
AS_EIO = 0, /* IO error on async write */
AS_ENOSPC = 1, /* ENOSPC on async write */
AS_MM_ALL_LOCKS = 2, /* under mm_take_all_locks() */
AS_UNEVICTABLE = 3, /* e.g., ramdisk, SHM_LOCK */
AS_EXITING = 4, /* final truncate in progress */ /* writeback related tags are not used */
AS_NO_WRITEBACK_TAGS = 5,
AS_RELEASE_ALWAYS = 6, /* Call ->release_folio(), even if no private data */
AS_STABLE_WRITES = 7, /* must wait for writeback before modifying
folio contents */
AS_INACCESSIBLE = 8, /* Do not attempt direct R/W access to the mapping */
AS_WRITEBACK_MAY_DEADLOCK_ON_RECLAIM = 9, /* Bits 16-25 are used for FOLIO_ORDER */
AS_FOLIO_ORDER_BITS = 5,
AS_FOLIO_ORDER_MIN = 16,
AS_FOLIO_ORDER_MAX = AS_FOLIO_ORDER_MIN + AS_FOLIO_ORDER_BITS,
};
/** * mapping_set_error - record a writeback error in the address_space * @mapping: the mapping in which an error should be set * @error: the error to set in the mapping * * When writeback fails in some way, we must record that error so that * userspace can be informed when fsync and the like are called. We endeavor * to report errors on any file that was open at the time of the error. Some * internal callers also need to know when writeback errors have occurred. * * When a writeback error occurs, most filesystems will want to call * mapping_set_error to record the error in the mapping so that it can be * reported when the application calls fsync(2).
*/ staticinlinevoid mapping_set_error(struct address_space *mapping, int error)
{ if (likely(!error)) return;
/* Record in wb_err for checkers using errseq_t based tracking */
__filemap_set_wb_err(mapping, error);
/* Record it in superblock */ if (mapping->host)
errseq_set(&mapping->host->i_sb->s_wb_err, error);
/* Record it in flags for now, for legacy callers */ if (error == -ENOSPC)
set_bit(AS_ENOSPC, &mapping->flags); else
set_bit(AS_EIO, &mapping->flags);
}
/* Restricts the given gfp_mask to what the mapping allows. */ staticinline gfp_t mapping_gfp_constraint(struct address_space *mapping,
gfp_t gfp_mask)
{ return mapping_gfp_mask(mapping) & gfp_mask;
}
/* * This is non-atomic. Only to be used before the mapping is activated. * Probably needs a barrier...
*/ staticinlinevoid mapping_set_gfp_mask(struct address_space *m, gfp_t mask)
{
m->gfp_mask = mask;
}
/* * There are some parts of the kernel which assume that PMD entries * are exactly HPAGE_PMD_ORDER. Those should be fixed, but until then, * limit the maximum allocation order to PMD size. I'm not aware of any * assumptions about maximum order if THP are disabled, but 8 seems like * a good order (that's 1MB if you're using 4kB pages)
*/ #ifdef CONFIG_TRANSPARENT_HUGEPAGE #define PREFERRED_MAX_PAGECACHE_ORDER HPAGE_PMD_ORDER #else #define PREFERRED_MAX_PAGECACHE_ORDER 8 #endif
/* * xas_split_alloc() does not support arbitrary orders. This implies no * 512MB THP on ARM64 with 64KB base page size.
*/ #define MAX_XAS_ORDER (XA_CHUNK_SHIFT * 2 - 1) #define MAX_PAGECACHE_ORDER min(MAX_XAS_ORDER, PREFERRED_MAX_PAGECACHE_ORDER)
/* * mapping_max_folio_size_supported() - Check the max folio size supported * * The filesystem should call this function at mount time if there is a * requirement on the folio mapping size in the page cache.
*/ staticinline size_t mapping_max_folio_size_supported(void)
{ if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) return 1U << (PAGE_SHIFT + MAX_PAGECACHE_ORDER); return PAGE_SIZE;
}
/* * mapping_set_folio_order_range() - Set the orders supported by a file. * @mapping: The address space of the file. * @min: Minimum folio order (between 0-MAX_PAGECACHE_ORDER inclusive). * @max: Maximum folio order (between @min-MAX_PAGECACHE_ORDER inclusive). * * The filesystem should call this function in its inode constructor to * indicate which base size (min) and maximum size (max) of folio the VFS * can use to cache the contents of the file. This should only be used * if the filesystem needs special handling of folio sizes (ie there is * something the core cannot know). * Do not tune it based on, eg, i_size. * * Context: This should not be called while the inode is active as it * is non-atomic.
*/ staticinlinevoid mapping_set_folio_order_range(struct address_space *mapping, unsignedint min, unsignedint max)
{ if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) return;
if (min > MAX_PAGECACHE_ORDER)
min = MAX_PAGECACHE_ORDER;
if (max > MAX_PAGECACHE_ORDER)
max = MAX_PAGECACHE_ORDER;
/** * mapping_set_large_folios() - Indicate the file supports large folios. * @mapping: The address space of the file. * * The filesystem should call this function in its inode constructor to * indicate that the VFS can use large folios to cache the contents of * the file. * * Context: This should not be called while the inode is active as it * is non-atomic.
*/ staticinlinevoid mapping_set_large_folios(struct address_space *mapping)
{
mapping_set_folio_order_range(mapping, 0, MAX_PAGECACHE_ORDER);
}
/** * mapping_align_index() - Align index for this mapping. * @mapping: The address_space. * @index: The page index. * * The index of a folio must be naturally aligned. If you are adding a * new folio to the page cache and need to know what index to give it, * call this function.
*/ staticinline pgoff_t mapping_align_index(struct address_space *mapping,
pgoff_t index)
{ return round_down(index, mapping_min_folio_nrpages(mapping));
}
/* * Large folio support currently depends on THP. These dependencies are * being worked on but are not yet fixed.
*/ staticinlinebool mapping_large_folio_support(struct address_space *mapping)
{ /* AS_FOLIO_ORDER is only reasonable for pagecache folios */
VM_WARN_ONCE((unsignedlong)mapping & FOLIO_MAPPING_ANON, "Anonymous mapping always supports large folio");
return mapping_max_folio_order(mapping) > 0;
}
/* Return the maximum folio size for this pagecache mapping, in bytes. */ staticinline size_t mapping_max_folio_size(conststruct address_space *mapping)
{ return PAGE_SIZE << mapping_max_folio_order(mapping);
}
/** * folio_flush_mapping - Find the file mapping this folio belongs to. * @folio: The folio. * * For folios which are in the page cache, return the mapping that this * page belongs to. Anonymous folios return NULL, even if they're in * the swap cache. Other kinds of folio also return NULL. * * This is ONLY used by architecture cache flushing code. If you aren't * writing cache flushing code, you want either folio_mapping() or * folio_file_mapping().
*/ staticinlinestruct address_space *folio_flush_mapping(struct folio *folio)
{ if (unlikely(folio_test_swapcache(folio))) return NULL;
return folio_mapping(folio);
}
/** * folio_inode - Get the host inode for this folio. * @folio: The folio. * * For folios which are in the page cache, return the inode that this folio * belongs to. * * Do not call this for folios which aren't in the page cache.
*/ staticinlinestruct inode *folio_inode(struct folio *folio)
{ return folio->mapping->host;
}
/** * folio_attach_private - Attach private data to a folio. * @folio: Folio to attach data to. * @data: Data to attach to folio. * * Attaching private data to a folio increments the page's reference count. * The data must be detached before the folio will be freed.
*/ staticinlinevoid folio_attach_private(struct folio *folio, void *data)
{
folio_get(folio);
folio->private = data;
folio_set_private(folio);
}
/** * folio_change_private - Change private data on a folio. * @folio: Folio to change the data on. * @data: Data to set on the folio. * * Change the private data attached to a folio and return the old * data. The page must previously have had data attached and the data * must be detached before the folio will be freed. * * Return: Data that was previously attached to the folio.
*/ staticinlinevoid *folio_change_private(struct folio *folio, void *data)
{ void *old = folio_get_private(folio);
folio->private = data; return old;
}
/** * folio_detach_private - Detach private data from a folio. * @folio: Folio to detach data from. * * Removes the data that was previously attached to the folio and decrements * the refcount on the page. * * Return: Data that was attached to the folio.
*/ staticinlinevoid *folio_detach_private(struct folio *folio)
{ void *data = folio_get_private(folio);
if (!folio_test_private(folio)) return NULL;
folio_clear_private(folio);
folio->private = NULL;
folio_put(folio);
/** * typedef fgf_t - Flags for getting folios from the page cache. * * Most users of the page cache will not need to use these flags; * there are convenience functions such as filemap_get_folio() and * filemap_lock_folio(). For users which need more control over exactly * what is done with the folios, these flags to __filemap_get_folio() * are available. * * * %FGP_ACCESSED - The folio will be marked accessed. * * %FGP_LOCK - The folio is returned locked. * * %FGP_CREAT - If no folio is present then a new folio is allocated, * added to the page cache and the VM's LRU list. The folio is * returned locked. * * %FGP_FOR_MMAP - The caller wants to do its own locking dance if the * folio is already in cache. If the folio was allocated, unlock it * before returning so the caller can do the same dance. * * %FGP_WRITE - The folio will be written to by the caller. * * %FGP_NOFS - __GFP_FS will get cleared in gfp. * * %FGP_NOWAIT - Don't block on the folio lock. * * %FGP_STABLE - Wait for the folio to be stable (finished writeback) * * %FGP_DONTCACHE - Uncached buffered IO * * %FGP_WRITEBEGIN - The flags to use in a filesystem write_begin() * implementation.
*/ typedefunsignedint __bitwise fgf_t;
/** * fgf_set_order - Encode a length in the fgf_t flags. * @size: The suggested size of the folio to create. * * The caller of __filemap_get_folio() can use this to suggest a preferred * size for the folio that is created. If there is already a folio at * the index, it will be returned, no matter what its size. If a folio * is freshly created, it may be of a different size than requested * due to alignment constraints, memory pressure, or the presence of * other folios at nearby indices.
*/ staticinline fgf_t fgf_set_order(size_t size)
{ unsignedint order = filemap_get_order(size);
if (!order) return 0; return (__force fgf_t)(order << 26);
}
/** * write_begin_get_folio - Get folio for write_begin with flags. * @iocb: The kiocb passed from write_begin (may be NULL). * @mapping: The address space to search. * @index: The page cache index. * @len: Length of data being written. * * This is a helper for filesystem write_begin() implementations. * It wraps __filemap_get_folio(), setting appropriate flags in * the write begin context. * * Return: A folio or an ERR_PTR.
*/ staticinlinestruct folio *write_begin_get_folio(conststruct kiocb *iocb, struct address_space *mapping, pgoff_t index, size_t len)
{
fgf_t fgp_flags = FGP_WRITEBEGIN;
fgp_flags |= fgf_set_order(len);
if (iocb && iocb->ki_flags & IOCB_DONTCACHE)
fgp_flags |= FGP_DONTCACHE;
/** * filemap_get_folio - Find and get a folio. * @mapping: The address_space to search. * @index: The page index. * * Looks up the page cache entry at @mapping & @index. If a folio is * present, it is returned with an increased refcount. * * Return: A folio or ERR_PTR(-ENOENT) if there is no folio in the cache for * this index. Will not return a shadow, swap or DAX entry.
*/ staticinlinestruct folio *filemap_get_folio(struct address_space *mapping,
pgoff_t index)
{ return __filemap_get_folio(mapping, index, 0, 0);
}
/** * filemap_lock_folio - Find and lock a folio. * @mapping: The address_space to search. * @index: The page index. * * Looks up the page cache entry at @mapping & @index. If a folio is * present, it is returned locked with an increased refcount. * * Context: May sleep. * Return: A folio or ERR_PTR(-ENOENT) if there is no folio in the cache for * this index. Will not return a shadow, swap or DAX entry.
*/ staticinlinestruct folio *filemap_lock_folio(struct address_space *mapping,
pgoff_t index)
{ return __filemap_get_folio(mapping, index, FGP_LOCK, 0);
}
/** * filemap_grab_folio - grab a folio from the page cache * @mapping: The address space to search * @index: The page index * * Looks up the page cache entry at @mapping & @index. If no folio is found, * a new folio is created. The folio is locked, marked as accessed, and * returned. * * Return: A found or created folio. ERR_PTR(-ENOMEM) if no folio is found * and failed to create a folio.
*/ staticinlinestruct folio *filemap_grab_folio(struct address_space *mapping,
pgoff_t index)
{ return __filemap_get_folio(mapping, index,
FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
mapping_gfp_mask(mapping));
}
/** * find_get_page - find and get a page reference * @mapping: the address_space to search * @offset: the page index * * Looks up the page cache slot at @mapping & @offset. If there is a * page cache page, it is returned with an increased refcount. * * Otherwise, %NULL is returned.
*/ staticinlinestruct page *find_get_page(struct address_space *mapping,
pgoff_t offset)
{ return pagecache_get_page(mapping, offset, 0, 0);
}
/** * find_lock_page - locate, pin and lock a pagecache page * @mapping: the address_space to search * @index: the page index * * Looks up the page cache entry at @mapping & @index. If there is a * page cache page, it is returned locked and with an increased * refcount. * * Context: May sleep. * Return: A struct page or %NULL if there is no page in the cache for this * index.
*/ staticinlinestruct page *find_lock_page(struct address_space *mapping,
pgoff_t index)
{ return pagecache_get_page(mapping, index, FGP_LOCK, 0);
}
/** * find_or_create_page - locate or add a pagecache page * @mapping: the page's address_space * @index: the page's index into the mapping * @gfp_mask: page allocation mode * * Looks up the page cache slot at @mapping & @offset. If there is a * page cache page, it is returned locked and with an increased * refcount. * * If the page is not present, a new page is allocated using @gfp_mask * and added to the page cache and the VM's LRU list. The page is * returned locked and with an increased refcount. * * On memory exhaustion, %NULL is returned. * * find_or_create_page() may sleep, even if @gfp_flags specifies an * atomic allocation!
*/ staticinlinestruct page *find_or_create_page(struct address_space *mapping,
pgoff_t index, gfp_t gfp_mask)
{ return pagecache_get_page(mapping, index,
FGP_LOCK|FGP_ACCESSED|FGP_CREAT,
gfp_mask);
}
/** * grab_cache_page_nowait - returns locked page at given index in given cache * @mapping: target address_space * @index: the page index * * Returns locked page at given index in given cache, creating it if * needed, but do not wait if the page is locked or to reclaim memory. * This is intended for speculative data generators, where the data can * be regenerated if the page couldn't be grabbed. This routine should * be safe to call while holding the lock for another page. * * Clear __GFP_FS when allocating the page to avoid recursion into the fs * and deadlock against the caller's locked page.
*/ staticinlinestruct page *grab_cache_page_nowait(struct address_space *mapping,
pgoff_t index)
{ return pagecache_get_page(mapping, index,
FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT,
mapping_gfp_mask(mapping));
}
/** * folio_next_index - Get the index of the next folio. * @folio: The current folio. * * Return: The index of the folio which follows this folio in the file.
*/ staticinline pgoff_t folio_next_index(struct folio *folio)
{ return folio->index + folio_nr_pages(folio);
}
/** * folio_file_page - The page for a particular index. * @folio: The folio which contains this index. * @index: The index we want to look up. * * Sometimes after looking up a folio in the page cache, we need to * obtain the specific page for an index (eg a page fault). * * Return: The page containing the file data for this index.
*/ staticinlinestruct page *folio_file_page(struct folio *folio, pgoff_t index)
{ return folio_page(folio, index & (folio_nr_pages(folio) - 1));
}
/** * folio_contains - Does this folio contain this index? * @folio: The folio. * @index: The page index within the file. * * Context: The caller should have the folio locked and ensure * e.g., shmem did not move this folio to the swap cache. * Return: true or false.
*/ staticinlinebool folio_contains(struct folio *folio, pgoff_t index)
{
VM_WARN_ON_ONCE_FOLIO(folio_test_swapcache(folio), folio); return index - folio->index < folio_nr_pages(folio);
}
/** * page_pgoff - Calculate the logical page offset of this page. * @folio: The folio containing this page. * @page: The page which we need the offset of. * * For file pages, this is the offset from the beginning of the file * in units of PAGE_SIZE. For anonymous pages, this is the offset from * the beginning of the anon_vma in units of PAGE_SIZE. This will * return nonsense for KSM pages. * * Context: Caller must have a reference on the folio or otherwise * prevent it from being split or freed. * * Return: The offset in units of PAGE_SIZE.
*/ staticinline pgoff_t page_pgoff(conststruct folio *folio, conststruct page *page)
{ return folio->index + folio_page_idx(folio, page);
}
/** * folio_pos - Returns the byte position of this folio in its file. * @folio: The folio.
*/ staticinline loff_t folio_pos(conststruct folio *folio)
{ return ((loff_t)folio->index) * PAGE_SIZE;
}
/** * folio_trylock() - Attempt to lock a folio. * @folio: The folio to attempt to lock. * * Sometimes it is undesirable to wait for a folio to be unlocked (eg * when the locks are being taken in the wrong order, or if making * progress through a batch of folios is more important than processing * them in order). Usually folio_lock() is the correct function to call. * * Context: Any context. * Return: Whether the lock was successfully acquired.
*/ staticinlinebool folio_trylock(struct folio *folio)
{ return likely(!test_and_set_bit_lock(PG_locked, folio_flags(folio, 0)));
}
/* * Return true if the page was successfully locked
*/ staticinlinebool trylock_page(struct page *page)
{ return folio_trylock(page_folio(page));
}
/** * folio_lock() - Lock this folio. * @folio: The folio to lock. * * The folio lock protects against many things, probably more than it * should. It is primarily held while a folio is being brought uptodate, * either from its backing file or from swap. It is also held while a * folio is being truncated from its address_space, so holding the lock * is sufficient to keep folio->mapping stable. * * The folio lock is also held while write() is modifying the page to * provide POSIX atomicity guarantees (as long as the write does not * cross a page boundary). Other modifications to the data in the folio * do not hold the folio lock and can race with writes, eg DMA and stores * to mapped pages. * * Context: May sleep. If you need to acquire the locks of two or * more folios, they must be in order of ascending index, if they are * in the same address_space. If they are in different address_spaces, * acquire the lock of the folio which belongs to the address_space which * has the lowest address in memory first.
*/ staticinlinevoid folio_lock(struct folio *folio)
{
might_sleep(); if (!folio_trylock(folio))
__folio_lock(folio);
}
/** * lock_page() - Lock the folio containing this page. * @page: The page to lock. * * See folio_lock() for a description of what the lock protects. * This is a legacy function and new code should probably use folio_lock() * instead. * * Context: May sleep. Pages in the same folio share a lock, so do not * attempt to lock two pages which share a folio.
*/ staticinlinevoid lock_page(struct page *page)
{ struct folio *folio;
might_sleep();
folio = page_folio(page); if (!folio_trylock(folio))
__folio_lock(folio);
}
/** * folio_lock_killable() - Lock this folio, interruptible by a fatal signal. * @folio: The folio to lock. * * Attempts to lock the folio, like folio_lock(), except that the sleep * to acquire the lock is interruptible by a fatal signal. * * Context: May sleep; see folio_lock(). * Return: 0 if the lock was acquired; -EINTR if a fatal signal was received.
*/ staticinlineint folio_lock_killable(struct folio *folio)
{
might_sleep(); if (!folio_trylock(folio)) return __folio_lock_killable(folio); return 0;
}
/* * folio_lock_or_retry - Lock the folio, unless this would block and the * caller indicated that it can handle a retry. * * Return value and mmap_lock implications depend on flags; see * __folio_lock_or_retry().
*/ staticinline vm_fault_t folio_lock_or_retry(struct folio *folio, struct vm_fault *vmf)
{
might_sleep(); if (!folio_trylock(folio)) return __folio_lock_or_retry(folio, vmf); return 0;
}
/* * This is exported only for folio_wait_locked/folio_wait_writeback, etc., * and should not be used directly.
*/ void folio_wait_bit(struct folio *folio, int bit_nr); int folio_wait_bit_killable(struct folio *folio, int bit_nr);
/* * Wait for a folio to be unlocked. * * This must be called with the caller "holding" the folio, * ie with increased folio reference count so that the folio won't * go away during the wait.
*/ staticinlinevoid folio_wait_locked(struct folio *folio)
{ if (folio_test_locked(folio))
folio_wait_bit(folio, PG_locked);
}
/** * filemap_range_needs_writeback - check if range potentially needs writeback * @mapping: address space within which to check * @start_byte: offset in bytes where the range starts * @end_byte: offset in bytes where the range ends (inclusive) * * Find at least one page in the range supplied, usually used to check if * direct writing in this range will trigger a writeback. Used by O_DIRECT * read/write with IOCB_NOWAIT, to see if the caller needs to do * filemap_write_and_wait_range() before proceeding. * * Return: %true if the caller should do filemap_write_and_wait_range() before * doing O_DIRECT to a page in this range, %false otherwise.
*/ staticinlinebool filemap_range_needs_writeback(struct address_space *mapping,
loff_t start_byte,
loff_t end_byte)
{ if (!mapping->nrpages) returnfalse; if (!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) &&
!mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) returnfalse; return filemap_range_has_writeback(mapping, start_byte, end_byte);
}
/** * struct readahead_control - Describes a readahead request. * * A readahead request is for consecutive pages. Filesystems which * implement the ->readahead method should call readahead_folio() or * __readahead_batch() in a loop and attempt to start reads into each * folio in the request. * * Most of the fields in this struct are private and should be accessed * by the functions below. * * @file: The file, used primarily by network filesystems for authentication. * May be NULL if invoked internally by the filesystem. * @mapping: Readahead this filesystem object. * @ra: File readahead state. May be NULL.
*/ struct readahead_control { struct file *file; struct address_space *mapping; struct file_ra_state *ra; /* private: use the readahead_* accessors instead */
pgoff_t _index; unsignedint _nr_pages; unsignedint _batch_count; bool dropbehind; bool _workingset; unsignedlong _pflags;
};
#define DEFINE_READAHEAD(ractl, f, r, m, i) \ struct readahead_control ractl = { \
.file = f, \
.mapping = m, \
.ra = r, \
._index = i, \
}
/** * page_cache_sync_readahead - generic file readahead * @mapping: address_space which holds the pagecache and I/O vectors * @ra: file_ra_state which holds the readahead state * @file: Used by the filesystem for authentication. * @index: Index of first page to be read. * @req_count: Total number of pages being read by the caller. * * page_cache_sync_readahead() should be called when a cache miss happened: * it will submit the read. The readahead logic may decide to piggyback more * pages onto the read request if access patterns suggest it will improve * performance.
*/ staticinline void page_cache_sync_readahead(struct address_space *mapping, struct file_ra_state *ra, struct file *file, pgoff_t index, unsignedlong req_count)
{
DEFINE_READAHEAD(ractl, file, ra, mapping, index);
page_cache_sync_ra(&ractl, req_count);
}
/** * page_cache_async_readahead - file readahead for marked pages * @mapping: address_space which holds the pagecache and I/O vectors * @ra: file_ra_state which holds the readahead state * @file: Used by the filesystem for authentication. * @folio: The folio which triggered the readahead call. * @req_count: Total number of pages being read by the caller. * * page_cache_async_readahead() should be called when a page is used which * is marked as PageReadahead; this is a marker to suggest that the application * has used up enough of the readahead window that we should start pulling in * more pages.
*/ staticinline void page_cache_async_readahead(struct address_space *mapping, struct file_ra_state *ra, struct file *file, struct folio *folio, unsignedlong req_count)
{
DEFINE_READAHEAD(ractl, file, ra, mapping, folio->index);
page_cache_async_ra(&ractl, folio, req_count);
}
/** * readahead_folio - Get the next folio to read. * @ractl: The current readahead request. * * Context: The folio is locked. The caller should unlock the folio once * all I/O to that folio has completed. * Return: A pointer to the next folio, or %NULL if we are done.
*/ staticinlinestruct folio *readahead_folio(struct readahead_control *ractl)
{ struct folio *folio = __readahead_folio(ractl);
/** * readahead_pos - The byte offset into the file of this readahead request. * @rac: The readahead request.
*/ staticinline loff_t readahead_pos(struct readahead_control *rac)
{ return (loff_t)rac->_index * PAGE_SIZE;
}
/** * readahead_length - The number of bytes in this readahead request. * @rac: The readahead request.
*/ staticinline size_t readahead_length(struct readahead_control *rac)
{ return rac->_nr_pages * PAGE_SIZE;
}
/** * readahead_index - The index of the first page in this readahead request. * @rac: The readahead request.
*/ staticinline pgoff_t readahead_index(struct readahead_control *rac)
{ return rac->_index;
}
/** * readahead_count - The number of pages in this readahead request. * @rac: The readahead request.
*/ staticinlineunsignedint readahead_count(struct readahead_control *rac)
{ return rac->_nr_pages;
}
/** * readahead_batch_length - The number of bytes in the current batch. * @rac: The readahead request.
*/ staticinline size_t readahead_batch_length(struct readahead_control *rac)
{ return rac->_batch_count * PAGE_SIZE;
}
/** * folio_mkwrite_check_truncate - check if folio was truncated * @folio: the folio to check * @inode: the inode to check the folio against * * Return: the number of bytes in the folio up to EOF, * or -EFAULT if the folio was truncated.
*/ staticinline ssize_t folio_mkwrite_check_truncate(struct folio *folio, struct inode *inode)
{
loff_t size = i_size_read(inode);
pgoff_t index = size >> PAGE_SHIFT;
size_t offset = offset_in_folio(folio, size);
if (!folio->mapping) return -EFAULT;
/* folio is wholly inside EOF */ if (folio_next_index(folio) - 1 < index) return folio_size(folio); /* folio is wholly past EOF */ if (folio->index > index || !offset) return -EFAULT; /* folio is partially inside EOF */ return offset;
}
/** * i_blocks_per_folio - How many blocks fit in this folio. * @inode: The inode which contains the blocks. * @folio: The folio. * * If the block size is larger than the size of this folio, return zero. * * Context: The caller should hold a refcount on the folio to prevent it * from being split. * Return: The number of filesystem blocks covered by this folio.
*/ staticinline unsignedint i_blocks_per_folio(struct inode *inode, struct folio *folio)
{ return folio_size(folio) >> inode->i_blkbits;
} #endif/* _LINUX_PAGEMAP_H */
Messung V0.5
¤ Dauer der Verarbeitung: 0.38 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.