diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-06-05 16:44:53 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2022-06-05 16:44:53 -0400 |
commit | 5d370ea0a95804da1d533cc806040f78b0a6f297 (patch) | |
tree | ea333d8344734f33d79cbcf8d4e7049c655b93a4 /include/linux/pagevec.h | |
parent | 6fc5ba99ee0db14f86d99db929210e21b68b9ab2 (diff) |
filemap: for_each_folio_batched()folio_iter_batched
This adds a cleaner interface around iterating over folios with batched
lookup, and a new iterator type (folio_iter_batched), and converts most
users of filemap_get_folios() to the new interface.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'include/linux/pagevec.h')
-rw-r--r-- | include/linux/pagevec.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h index 6649154a2115..c6d2eb946812 100644 --- a/include/linux/pagevec.h +++ b/include/linux/pagevec.h @@ -137,4 +137,36 @@ static inline void folio_batch_release(struct folio_batch *fbatch) } void folio_batch_remove_exceptionals(struct folio_batch *fbatch); + +struct folio_iter_batched { + struct folio_batch batch; + unsigned batch_idx; + struct address_space *mapping; + pgoff_t pos; + pgoff_t end; +}; + +static inline struct folio_iter_batched +folio_iter_batched_init(struct address_space *mapping, pgoff_t start, pgoff_t end) +{ + return (struct folio_iter_batched) { + .mapping = mapping, + .pos = start, + .end = end, + }; +} + +static inline void folio_iter_batched_exit(struct folio_iter_batched *iter) +{ + folio_batch_release(&iter->batch); +} + +struct folio *folio_iter_batched_peek(struct folio_iter_batched *); +void folio_iter_batched_advance(struct folio_iter_batched *); + +#define for_each_folio_batched(_mapping, _iter, _start, _end, _folio) \ + for (_iter = folio_iter_batched_init(_mapping, _start, _end); \ + (_folio = folio_iter_batched_peek(&(_iter))); \ + folio_iter_batched_advance(&(_iter))) + #endif /* _LINUX_PAGEVEC_H */ |