1 /* SPDX-License-Identifier: GPL-2.0 */
3 * include/linux/pagevec.h
5 * In many places it is efficient to batch an operation up against multiple
6 * folios. A folio_batch is a container which is used for that.
9 #ifndef _LINUX_PAGEVEC_H
10 #define _LINUX_PAGEVEC_H
12 #include <linux/types.h>
14 /* 15 pointers + header align the folio_batch structure to a power of two */
15 #define PAGEVEC_SIZE 15
20 * struct folio_batch - A collection of folios.
22 * The folio_batch is used to amortise the cost of retrieving and
23 * operating on a set of folios. The order of folios in the batch may be
24 * significant (eg delete_from_page_cache_batch()). Some users of the
25 * folio_batch store "exceptional" entries in it which can be removed
26 * by calling folio_batch_remove_exceptionals().
30 bool percpu_pvec_drained;
31 struct folio *folios[PAGEVEC_SIZE];
35 * folio_batch_init() - Initialise a batch of folios
36 * @fbatch: The folio batch.
38 * A freshly initialised folio_batch contains zero folios.
40 static inline void folio_batch_init(struct folio_batch *fbatch)
43 fbatch->percpu_pvec_drained = false;
46 static inline void folio_batch_reinit(struct folio_batch *fbatch)
51 static inline unsigned int folio_batch_count(struct folio_batch *fbatch)
56 static inline unsigned int folio_batch_space(struct folio_batch *fbatch)
58 return PAGEVEC_SIZE - fbatch->nr;
62 * folio_batch_add() - Add a folio to a batch.
63 * @fbatch: The folio batch.
64 * @folio: The folio to add.
66 * The folio is added to the end of the batch.
67 * The batch must have previously been initialised using folio_batch_init().
69 * Return: The number of slots still available.
71 static inline unsigned folio_batch_add(struct folio_batch *fbatch,
74 fbatch->folios[fbatch->nr++] = folio;
75 return folio_batch_space(fbatch);
78 void __folio_batch_release(struct folio_batch *pvec);
80 static inline void folio_batch_release(struct folio_batch *fbatch)
82 if (folio_batch_count(fbatch))
83 __folio_batch_release(fbatch);
86 void folio_batch_remove_exceptionals(struct folio_batch *fbatch);
87 #endif /* _LINUX_PAGEVEC_H */