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