Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs: Pass a folio to page_put_link()

All callers now have a folio. Pass it to page_put_link(), saving a
hidden call to compound_head(). Also add kernel-doc for page_get_link()
and page_put_link().

Signed-off-by: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Link: https://lore.kernel.org/20250514171316.3002934-4-willy@infradead.org
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Matthew Wilcox (Oracle) and committed by
Christian Brauner
4ec373b7 cc8e87f3

+29 -5
+1 -1
fs/fuse/dir.c
··· 1676 1676 goto out_err; 1677 1677 } 1678 1678 1679 - set_delayed_call(callback, page_put_link, &folio->page); 1679 + set_delayed_call(callback, page_put_link, folio); 1680 1680 1681 1681 return folio_address(folio); 1682 1682
+27 -3
fs/namei.c
··· 5387 5387 if (IS_ERR(folio)) 5388 5388 return ERR_CAST(folio); 5389 5389 } 5390 - set_delayed_call(callback, page_put_link, &folio->page); 5390 + set_delayed_call(callback, page_put_link, folio); 5391 5391 BUG_ON(mapping_gfp_mask(mapping) & __GFP_HIGHMEM); 5392 5392 return folio_address(folio); 5393 5393 } ··· 5399 5399 } 5400 5400 EXPORT_SYMBOL_GPL(page_get_link_raw); 5401 5401 5402 + /** 5403 + * page_get_link() - An implementation of the get_link inode_operation. 5404 + * @dentry: The directory entry which is the symlink. 5405 + * @inode: The inode for the symlink. 5406 + * @callback: Used to drop the reference to the symlink. 5407 + * 5408 + * Filesystems which store their symlinks in the page cache should use 5409 + * this to implement the get_link() member of their inode_operations. 5410 + * 5411 + * Return: A pointer to the NUL-terminated symlink. 5412 + */ 5402 5413 const char *page_get_link(struct dentry *dentry, struct inode *inode, 5403 5414 struct delayed_call *callback) 5404 5415 { ··· 5419 5408 nd_terminate_link(kaddr, inode->i_size, PAGE_SIZE - 1); 5420 5409 return kaddr; 5421 5410 } 5422 - 5423 5411 EXPORT_SYMBOL(page_get_link); 5424 5412 5413 + /** 5414 + * page_put_link() - Drop the reference to the symlink. 5415 + * @arg: The folio which contains the symlink. 5416 + * 5417 + * This is used internally by page_get_link(). It is exported for use 5418 + * by filesystems which need to implement a variant of page_get_link() 5419 + * themselves. Despite the apparent symmetry, filesystems which use 5420 + * page_get_link() do not need to call page_put_link(). 5421 + * 5422 + * The argument, while it has a void pointer type, must be a pointer to 5423 + * the folio which was retrieved from the page cache. The delayed_call 5424 + * infrastructure is used to drop the reference count once the caller 5425 + * is done with the symlink. 5426 + */ 5425 5427 void page_put_link(void *arg) 5426 5428 { 5427 - put_page(arg); 5429 + folio_put(arg); 5428 5430 } 5429 5431 EXPORT_SYMBOL(page_put_link); 5430 5432
+1 -1
fs/nfs/symlink.c
··· 63 63 if (IS_ERR(folio)) 64 64 return ERR_CAST(folio); 65 65 } 66 - set_delayed_call(done, page_put_link, &folio->page); 66 + set_delayed_call(done, page_put_link, folio); 67 67 return folio_address(folio); 68 68 } 69 69