pagevec.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /* 14 pointers + two long's align the pagevec structure to a power of two */
  11. #define PAGEVEC_SIZE 14
  12. struct page;
  13. struct address_space;
  14. struct pagevec {
  15. unsigned long nr;
  16. bool drained;
  17. struct page *pages[PAGEVEC_SIZE];
  18. };
  19. void __pagevec_release(struct pagevec *pvec);
  20. void __pagevec_lru_add(struct pagevec *pvec);
  21. unsigned pagevec_lookup_entries(struct pagevec *pvec,
  22. struct address_space *mapping,
  23. pgoff_t start, unsigned nr_entries,
  24. pgoff_t *indices);
  25. void pagevec_remove_exceptionals(struct pagevec *pvec);
  26. unsigned pagevec_lookup_range(struct pagevec *pvec,
  27. struct address_space *mapping,
  28. pgoff_t *start, pgoff_t end);
  29. static inline unsigned pagevec_lookup(struct pagevec *pvec,
  30. struct address_space *mapping,
  31. pgoff_t *start)
  32. {
  33. return pagevec_lookup_range(pvec, mapping, start, (pgoff_t)-1);
  34. }
  35. unsigned pagevec_lookup_range_tag(struct pagevec *pvec,
  36. struct address_space *mapping, pgoff_t *index, pgoff_t end,
  37. int tag);
  38. unsigned pagevec_lookup_range_nr_tag(struct pagevec *pvec,
  39. struct address_space *mapping, pgoff_t *index, pgoff_t end,
  40. int tag, unsigned max_pages);
  41. static inline unsigned pagevec_lookup_tag(struct pagevec *pvec,
  42. struct address_space *mapping, pgoff_t *index, int tag)
  43. {
  44. return pagevec_lookup_range_tag(pvec, mapping, index, (pgoff_t)-1, tag);
  45. }
  46. static inline void pagevec_init(struct pagevec *pvec)
  47. {
  48. pvec->nr = 0;
  49. pvec->drained = false;
  50. }
  51. static inline void pagevec_reinit(struct pagevec *pvec)
  52. {
  53. pvec->nr = 0;
  54. }
  55. static inline unsigned pagevec_count(struct pagevec *pvec)
  56. {
  57. return pvec->nr;
  58. }
  59. static inline unsigned pagevec_space(struct pagevec *pvec)
  60. {
  61. return PAGEVEC_SIZE - pvec->nr;
  62. }
  63. /*
  64. * Add a page to a pagevec. Returns the number of slots still available.
  65. */
  66. static inline unsigned pagevec_add(struct pagevec *pvec, struct page *page)
  67. {
  68. pvec->pages[pvec->nr++] = page;
  69. return pagevec_space(pvec);
  70. }
  71. static inline void pagevec_release(struct pagevec *pvec)
  72. {
  73. if (pagevec_count(pvec))
  74. __pagevec_release(pvec);
  75. }
  76. #endif /* _LINUX_PAGEVEC_H */