pagevec.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * include/linux/pagevec.h
  4. *
  5. * In many places it is efficient to batch an operation up against multiple
  6. * pages. A pagevec is a multipage container which is used for that.
  7. */
  8. #ifndef _LINUX_PAGEVEC_H
  9. #define _LINUX_PAGEVEC_H
  10. #include <linux/xarray.h>
  11. /* 15 pointers + header align the pagevec structure to a power of two */
  12. #define PAGEVEC_SIZE 15
  13. struct page;
  14. struct address_space;
  15. struct pagevec {
  16. unsigned char nr;
  17. bool percpu_pvec_drained;
  18. struct page *pages[PAGEVEC_SIZE];
  19. };
  20. void __pagevec_release(struct pagevec *pvec);
  21. void __pagevec_lru_add(struct pagevec *pvec);
  22. unsigned pagevec_lookup_entries(struct pagevec *pvec,
  23. struct address_space *mapping,
  24. pgoff_t start, unsigned nr_entries,
  25. pgoff_t *indices);
  26. void pagevec_remove_exceptionals(struct pagevec *pvec);
  27. unsigned pagevec_lookup_range(struct pagevec *pvec,
  28. struct address_space *mapping,
  29. pgoff_t *start, pgoff_t end);
  30. static inline unsigned pagevec_lookup(struct pagevec *pvec,
  31. struct address_space *mapping,
  32. pgoff_t *start)
  33. {
  34. return pagevec_lookup_range(pvec, mapping, start, (pgoff_t)-1);
  35. }
  36. unsigned pagevec_lookup_range_tag(struct pagevec *pvec,
  37. struct address_space *mapping, pgoff_t *index, pgoff_t end,
  38. xa_mark_t tag);
  39. unsigned pagevec_lookup_range_nr_tag(struct pagevec *pvec,
  40. struct address_space *mapping, pgoff_t *index, pgoff_t end,
  41. xa_mark_t tag, unsigned max_pages);
  42. static inline unsigned pagevec_lookup_tag(struct pagevec *pvec,
  43. struct address_space *mapping, pgoff_t *index, xa_mark_t tag)
  44. {
  45. return pagevec_lookup_range_tag(pvec, mapping, index, (pgoff_t)-1, tag);
  46. }
  47. static inline void pagevec_init(struct pagevec *pvec)
  48. {
  49. pvec->nr = 0;
  50. pvec->percpu_pvec_drained = false;
  51. }
  52. static inline void pagevec_reinit(struct pagevec *pvec)
  53. {
  54. pvec->nr = 0;
  55. }
  56. static inline unsigned pagevec_count(struct pagevec *pvec)
  57. {
  58. return pvec->nr;
  59. }
  60. static inline unsigned pagevec_space(struct pagevec *pvec)
  61. {
  62. return PAGEVEC_SIZE - pvec->nr;
  63. }
  64. /*
  65. * Add a page to a pagevec. Returns the number of slots still available.
  66. */
  67. static inline unsigned pagevec_add(struct pagevec *pvec, struct page *page)
  68. {
  69. pvec->pages[pvec->nr++] = page;
  70. return pagevec_space(pvec);
  71. }
  72. static inline void pagevec_release(struct pagevec *pvec)
  73. {
  74. if (pagevec_count(pvec))
  75. __pagevec_release(pvec);
  76. }
  77. #endif /* _LINUX_PAGEVEC_H */