The patch titled Subject: filemap: add filemap_get_folios_tag() has been added to the -mm mm-unstable branch. Its filename is filemap-added-filemap_get_folios_tag.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/filemap-added-filemap_get_folios_tag.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: "Vishal Moola (Oracle)" <vishal.moola@xxxxxxxxx> Subject: filemap: add filemap_get_folios_tag() Date: Wed, 4 Jan 2023 13:14:27 -0800 This is the equivalent of find_get_pages_range_tag(), except for folios instead of pages. One noteable difference is filemap_get_folios_tag() does not take in a maximum pages argument. It instead tries to fill a folio batch and stops either once full (15 folios) or reaching the end of the search range. The new function supports large folios, the initial function did not since all callers don't use large folios. Link: https://lkml.kernel.org/r/20230104211448.4804-3-vishal.moola@xxxxxxxxx Signed-off-by: Vishal Moola (Oracle) <vishal.moola@xxxxxxxxx> Reviewed-by: Matthew Wilcow (Oracle) <willy@xxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- --- a/include/linux/pagemap.h~filemap-added-filemap_get_folios_tag +++ a/include/linux/pagemap.h @@ -739,6 +739,8 @@ unsigned filemap_get_folios(struct addre pgoff_t end, struct folio_batch *fbatch); unsigned filemap_get_folios_contig(struct address_space *mapping, pgoff_t *start, pgoff_t end, struct folio_batch *fbatch); +unsigned filemap_get_folios_tag(struct address_space *mapping, pgoff_t *start, + pgoff_t end, xa_mark_t tag, struct folio_batch *fbatch); unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index, pgoff_t end, xa_mark_t tag, unsigned int nr_pages, struct page **pages); --- a/mm/filemap.c~filemap-added-filemap_get_folios_tag +++ a/mm/filemap.c @@ -2282,6 +2282,60 @@ out: EXPORT_SYMBOL(filemap_get_folios_contig); /** + * filemap_get_folios_tag - Get a batch of folios matching @tag + * @mapping: The address_space to search + * @start: The starting page index + * @end: The final page index (inclusive) + * @tag: The tag index + * @fbatch: The batch to fill + * + * Same as filemap_get_folios(), but only returning folios tagged with @tag. + * + * Return: The number of folios found. + * Also update @start to index the next folio for traversal. + */ +unsigned filemap_get_folios_tag(struct address_space *mapping, pgoff_t *start, + pgoff_t end, xa_mark_t tag, struct folio_batch *fbatch) +{ + XA_STATE(xas, &mapping->i_pages, *start); + struct folio *folio; + + rcu_read_lock(); + while ((folio = find_get_entry(&xas, end, tag)) != NULL) { + /* + * Shadow entries should never be tagged, but this iteration + * is lockless so there is a window for page reclaim to evict + * a page we saw tagged. Skip over it. + */ + if (xa_is_value(folio)) + continue; + if (!folio_batch_add(fbatch, folio)) { + unsigned long nr = folio_nr_pages(folio); + + if (folio_test_hugetlb(folio)) + nr = 1; + *start = folio->index + nr; + goto out; + } + } + /* + * We come here when there is no page beyond @end. We take care to not + * overflow the index @start as it confuses some of the callers. This + * breaks the iteration when there is a page at index -1 but that is + * already broke anyway. + */ + if (end == (pgoff_t)-1) + *start = (pgoff_t)-1; + else + *start = end + 1; +out: + rcu_read_unlock(); + + return folio_batch_count(fbatch); +} +EXPORT_SYMBOL(filemap_get_folios_tag); + +/** * find_get_pages_range_tag - Find and return head pages matching @tag. * @mapping: the address_space to search * @index: the starting page index _ Patches currently in -mm which might be from vishal.moola@xxxxxxxxx are mm-memory-add-vm_normal_folio.patch madvise-convert-madvise_cold_or_pageout_pte_range-to-use-folios.patch mm-damon-convert-damon_pa_mark_accessed_or_deactivate-to-use-folios.patch mm-swap-convert-deactivate_page-to-folio_deactivate.patch ext4-convert-mext_page_double_lock-to-mext_folio_double_lock.patch mm-khugepaged-introduce-release_pte_folio-to-replace-release_pte_page.patch mm-khugepaged-convert-release_pte_pages-to-use-folios.patch pagemap-add-filemap_grab_folio.patch filemap-added-filemap_get_folios_tag.patch filemap-convert-__filemap_fdatawait_range-to-use-filemap_get_folios_tag.patch page-writeback-convert-write_cache_pages-to-use-filemap_get_folios_tag.patch afs-convert-afs_writepages_region-to-use-filemap_get_folios_tag.patch btrfs-convert-btree_write_cache_pages-to-use-filemap_get_folio_tag.patch btrfs-convert-extent_write_cache_pages-to-use-filemap_get_folios_tag.patch ceph-convert-ceph_writepages_start-to-use-filemap_get_folios_tag.patch cifs-convert-wdata_alloc_and_fillpages-to-use-filemap_get_folios_tag.patch ext4-convert-mpage_prepare_extent_to_map-to-use-filemap_get_folios_tag.patch f2fs-convert-f2fs_fsync_node_pages-to-use-filemap_get_folios_tag.patch f2fs-convert-f2fs_flush_inline_data-to-use-filemap_get_folios_tag.patch f2fs-convert-f2fs_sync_node_pages-to-use-filemap_get_folios_tag.patch f2fs-convert-f2fs_write_cache_pages-to-use-filemap_get_folios_tag.patch f2fs-convert-last_fsync_dnode-to-use-filemap_get_folios_tag.patch f2fs-convert-f2fs_sync_meta_pages-to-use-filemap_get_folios_tag.patch gfs2-convert-gfs2_write_cache_jdata-to-use-filemap_get_folios_tag.patch nilfs2-convert-nilfs_lookup_dirty_data_buffers-to-use-filemap_get_folios_tag.patch nilfs2-convert-nilfs_lookup_dirty_node_buffers-to-use-filemap_get_folios_tag.patch nilfs2-convert-nilfs_btree_lookup_dirty_buffers-to-use-filemap_get_folios_tag.patch nilfs2-convert-nilfs_copy_dirty_pages-to-use-filemap_get_folios_tag.patch nilfs2-convert-nilfs_clear_dirty_pages-to-use-filemap_get_folios_tag.patch filemap-remove-find_get_pages_range_tag.patch