[1/8] pagevec: Add an iterator
diff mbox series

Message ID 20200113153746.26654-2-willy@infradead.org
State New
Headers show
Series
  • Replacing the readpages a_op
Related show

Commit Message

Matthew Wilcox Jan. 13, 2020, 3:37 p.m. UTC
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>

There's plenty of space in the pagevec for a loop counter, and
that will come in handy later.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/pagevec.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Patch
diff mbox series

diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h
index 081d934eda64..9b8c43661ab3 100644
--- a/include/linux/pagevec.h
+++ b/include/linux/pagevec.h
@@ -19,6 +19,7 @@  struct address_space;
 
 struct pagevec {
 	unsigned char nr;
+	unsigned char first;
 	bool percpu_pvec_drained;
 	struct page *pages[PAGEVEC_SIZE];
 };
@@ -55,12 +56,14 @@  static inline unsigned pagevec_lookup_tag(struct pagevec *pvec,
 static inline void pagevec_init(struct pagevec *pvec)
 {
 	pvec->nr = 0;
+	pvec->first = 0;
 	pvec->percpu_pvec_drained = false;
 }
 
 static inline void pagevec_reinit(struct pagevec *pvec)
 {
 	pvec->nr = 0;
+	pvec->first = 0;
 }
 
 static inline unsigned pagevec_count(struct pagevec *pvec)
@@ -88,4 +91,21 @@  static inline void pagevec_release(struct pagevec *pvec)
 		__pagevec_release(pvec);
 }
 
+static inline struct page *pagevec_last(struct pagevec *pvec)
+{
+	if (pvec->nr == 0)
+		return NULL;
+	return pvec->pages[pvec->nr - 1];
+}
+
+static inline struct page *pagevec_next(struct pagevec *pvec)
+{
+	if (pvec->first >= pvec->nr)
+		return NULL;
+	return pvec->pages[pvec->first++];
+}
+
+#define pagevec_for_each(pvec, page)	\
+	while ((page = pagevec_next(pvec)))
+
 #endif /* _LINUX_PAGEVEC_H */