swap.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _MM_SWAP_H
  3. #define _MM_SWAP_H
  4. #ifdef CONFIG_SWAP
  5. #include <linux/blk_types.h> /* for bio_end_io_t */
  6. /* linux/mm/page_io.c */
  7. int sio_pool_init(void);
  8. struct swap_iocb;
  9. int swap_readpage(struct page *page, bool do_poll,
  10. struct swap_iocb **plug);
  11. void __swap_read_unplug(struct swap_iocb *plug);
  12. static inline void swap_read_unplug(struct swap_iocb *plug)
  13. {
  14. if (unlikely(plug))
  15. __swap_read_unplug(plug);
  16. }
  17. void swap_write_unplug(struct swap_iocb *sio);
  18. int swap_writepage(struct page *page, struct writeback_control *wbc);
  19. int __swap_writepage(struct page *page, struct writeback_control *wbc);
  20. /* linux/mm/swap_state.c */
  21. /* One swap address space for each 64M swap space */
  22. #define SWAP_ADDRESS_SPACE_SHIFT 14
  23. #define SWAP_ADDRESS_SPACE_PAGES (1 << SWAP_ADDRESS_SPACE_SHIFT)
  24. extern struct address_space *swapper_spaces[];
  25. #define swap_address_space(entry) \
  26. (&swapper_spaces[swp_type(entry)][swp_offset(entry) \
  27. >> SWAP_ADDRESS_SPACE_SHIFT])
  28. void show_swap_cache_info(void);
  29. bool add_to_swap(struct folio *folio);
  30. void *get_shadow_from_swap_cache(swp_entry_t entry);
  31. int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
  32. gfp_t gfp, void **shadowp);
  33. void __delete_from_swap_cache(struct folio *folio,
  34. swp_entry_t entry, void *shadow);
  35. void delete_from_swap_cache(struct folio *folio);
  36. void clear_shadow_from_swap_cache(int type, unsigned long begin,
  37. unsigned long end);
  38. struct folio *swap_cache_get_folio(swp_entry_t entry,
  39. struct vm_area_struct *vma, unsigned long addr);
  40. struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index);
  41. struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
  42. struct vm_area_struct *vma,
  43. unsigned long addr,
  44. struct swap_iocb **plug);
  45. struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
  46. struct vm_area_struct *vma,
  47. unsigned long addr,
  48. bool *new_page_allocated);
  49. struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t flag,
  50. struct vm_fault *vmf);
  51. struct page *swapin_readahead(swp_entry_t entry, gfp_t flag,
  52. struct vm_fault *vmf);
  53. static inline unsigned int folio_swap_flags(struct folio *folio)
  54. {
  55. return page_swap_info(&folio->page)->flags;
  56. }
  57. #else /* CONFIG_SWAP */
  58. struct swap_iocb;
  59. static inline int swap_readpage(struct page *page, bool do_poll,
  60. struct swap_iocb **plug)
  61. {
  62. return 0;
  63. }
  64. static inline void swap_write_unplug(struct swap_iocb *sio)
  65. {
  66. }
  67. static inline struct address_space *swap_address_space(swp_entry_t entry)
  68. {
  69. return NULL;
  70. }
  71. static inline void show_swap_cache_info(void)
  72. {
  73. }
  74. static inline struct page *swap_cluster_readahead(swp_entry_t entry,
  75. gfp_t gfp_mask, struct vm_fault *vmf)
  76. {
  77. return NULL;
  78. }
  79. static inline struct page *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask,
  80. struct vm_fault *vmf)
  81. {
  82. return NULL;
  83. }
  84. static inline int swap_writepage(struct page *p, struct writeback_control *wbc)
  85. {
  86. return 0;
  87. }
  88. static inline struct folio *swap_cache_get_folio(swp_entry_t entry,
  89. struct vm_area_struct *vma, unsigned long addr)
  90. {
  91. return NULL;
  92. }
  93. static inline
  94. struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index)
  95. {
  96. return find_get_page(mapping, index);
  97. }
  98. static inline bool add_to_swap(struct folio *folio)
  99. {
  100. return false;
  101. }
  102. static inline void *get_shadow_from_swap_cache(swp_entry_t entry)
  103. {
  104. return NULL;
  105. }
  106. static inline int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
  107. gfp_t gfp_mask, void **shadowp)
  108. {
  109. return -1;
  110. }
  111. static inline void __delete_from_swap_cache(struct folio *folio,
  112. swp_entry_t entry, void *shadow)
  113. {
  114. }
  115. static inline void delete_from_swap_cache(struct folio *folio)
  116. {
  117. }
  118. static inline void clear_shadow_from_swap_cache(int type, unsigned long begin,
  119. unsigned long end)
  120. {
  121. }
  122. static inline unsigned int folio_swap_flags(struct folio *folio)
  123. {
  124. return 0;
  125. }
  126. #endif /* CONFIG_SWAP */
  127. #endif /* _MM_SWAP_H */