]>
Commit | Line | Data |
---|---|---|
014bb1de N |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | #ifndef _MM_SWAP_H | |
3 | #define _MM_SWAP_H | |
4 | ||
ddc1a5cb HD |
5 | struct mempolicy; |
6 | ||
014bb1de | 7 | #ifdef CONFIG_SWAP |
545ebe71 | 8 | #include <linux/swapops.h> /* for swp_offset */ |
014bb1de N |
9 | #include <linux/blk_types.h> /* for bio_end_io_t */ |
10 | ||
11 | /* linux/mm/page_io.c */ | |
e1209d3a | 12 | int sio_pool_init(void); |
5169b844 | 13 | struct swap_iocb; |
b2d1f38b | 14 | void swap_read_folio(struct folio *folio, struct swap_iocb **plug); |
5169b844 N |
15 | void __swap_read_unplug(struct swap_iocb *plug); |
16 | static inline void swap_read_unplug(struct swap_iocb *plug) | |
17 | { | |
18 | if (unlikely(plug)) | |
19 | __swap_read_unplug(plug); | |
20 | } | |
2282679f | 21 | void swap_write_unplug(struct swap_iocb *sio); |
014bb1de | 22 | int swap_writepage(struct page *page, struct writeback_control *wbc); |
b99b4e0d | 23 | void __swap_writepage(struct folio *folio, struct writeback_control *wbc); |
014bb1de N |
24 | |
25 | /* linux/mm/swap_state.c */ | |
26 | /* One swap address space for each 64M swap space */ | |
27 | #define SWAP_ADDRESS_SPACE_SHIFT 14 | |
28 | #define SWAP_ADDRESS_SPACE_PAGES (1 << SWAP_ADDRESS_SPACE_SHIFT) | |
7aad25b4 | 29 | #define SWAP_ADDRESS_SPACE_MASK (SWAP_ADDRESS_SPACE_PAGES - 1) |
014bb1de N |
30 | extern struct address_space *swapper_spaces[]; |
31 | #define swap_address_space(entry) \ | |
32 | (&swapper_spaces[swp_type(entry)][swp_offset(entry) \ | |
33 | >> SWAP_ADDRESS_SPACE_SHIFT]) | |
34 | ||
545ebe71 KS |
35 | /* |
36 | * Return the swap device position of the swap entry. | |
37 | */ | |
38 | static inline loff_t swap_dev_pos(swp_entry_t entry) | |
39 | { | |
40 | return ((loff_t)swp_offset(entry)) << PAGE_SHIFT; | |
41 | } | |
42 | ||
7aad25b4 KS |
43 | /* |
44 | * Return the swap cache index of the swap entry. | |
45 | */ | |
46 | static inline pgoff_t swap_cache_index(swp_entry_t entry) | |
47 | { | |
48 | BUILD_BUG_ON((SWP_OFFSET_MASK | SWAP_ADDRESS_SPACE_MASK) != SWP_OFFSET_MASK); | |
49 | return swp_offset(entry) & SWAP_ADDRESS_SPACE_MASK; | |
50 | } | |
51 | ||
014bb1de | 52 | void show_swap_cache_info(void); |
09c02e56 | 53 | bool add_to_swap(struct folio *folio); |
014bb1de | 54 | void *get_shadow_from_swap_cache(swp_entry_t entry); |
a4c366f0 | 55 | int add_to_swap_cache(struct folio *folio, swp_entry_t entry, |
014bb1de | 56 | gfp_t gfp, void **shadowp); |
ceff9d33 | 57 | void __delete_from_swap_cache(struct folio *folio, |
014bb1de | 58 | swp_entry_t entry, void *shadow); |
75fa68a5 | 59 | void delete_from_swap_cache(struct folio *folio); |
014bb1de N |
60 | void clear_shadow_from_swap_cache(int type, unsigned long begin, |
61 | unsigned long end); | |
13ddaf26 | 62 | void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry); |
c9edc242 MWO |
63 | struct folio *swap_cache_get_folio(swp_entry_t entry, |
64 | struct vm_area_struct *vma, unsigned long addr); | |
524984ff MWO |
65 | struct folio *filemap_get_incore_folio(struct address_space *mapping, |
66 | pgoff_t index); | |
014bb1de | 67 | |
6e03492e MWO |
68 | struct folio *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, |
69 | struct vm_area_struct *vma, unsigned long addr, | |
70 | struct swap_iocb **plug); | |
96c7b0b4 MWO |
71 | struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_flags, |
72 | struct mempolicy *mpol, pgoff_t ilx, bool *new_page_allocated, | |
73 | bool skip_if_exists); | |
a4575c41 MWO |
74 | struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t flag, |
75 | struct mempolicy *mpol, pgoff_t ilx); | |
014bb1de N |
76 | struct page *swapin_readahead(swp_entry_t entry, gfp_t flag, |
77 | struct vm_fault *vmf); | |
78 | ||
b98c359f | 79 | static inline unsigned int folio_swap_flags(struct folio *folio) |
d791ea67 | 80 | { |
69fe7d67 | 81 | return swp_swap_info(folio->swap)->flags; |
d791ea67 | 82 | } |
014bb1de | 83 | #else /* CONFIG_SWAP */ |
5169b844 | 84 | struct swap_iocb; |
b2d1f38b | 85 | static inline void swap_read_folio(struct folio *folio, struct swap_iocb **plug) |
014bb1de | 86 | { |
014bb1de | 87 | } |
2282679f N |
88 | static inline void swap_write_unplug(struct swap_iocb *sio) |
89 | { | |
90 | } | |
014bb1de N |
91 | |
92 | static inline struct address_space *swap_address_space(swp_entry_t entry) | |
93 | { | |
94 | return NULL; | |
95 | } | |
96 | ||
7aad25b4 KS |
97 | static inline pgoff_t swap_cache_index(swp_entry_t entry) |
98 | { | |
99 | return 0; | |
100 | } | |
101 | ||
014bb1de N |
102 | static inline void show_swap_cache_info(void) |
103 | { | |
104 | } | |
105 | ||
a4575c41 | 106 | static inline struct folio *swap_cluster_readahead(swp_entry_t entry, |
ddc1a5cb | 107 | gfp_t gfp_mask, struct mempolicy *mpol, pgoff_t ilx) |
014bb1de N |
108 | { |
109 | return NULL; | |
110 | } | |
111 | ||
112 | static inline struct page *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask, | |
113 | struct vm_fault *vmf) | |
114 | { | |
115 | return NULL; | |
116 | } | |
117 | ||
118 | static inline int swap_writepage(struct page *p, struct writeback_control *wbc) | |
119 | { | |
120 | return 0; | |
121 | } | |
122 | ||
13ddaf26 KS |
123 | static inline void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry) |
124 | { | |
125 | } | |
126 | ||
c9edc242 MWO |
127 | static inline struct folio *swap_cache_get_folio(swp_entry_t entry, |
128 | struct vm_area_struct *vma, unsigned long addr) | |
129 | { | |
130 | return NULL; | |
131 | } | |
132 | ||
014bb1de | 133 | static inline |
524984ff MWO |
134 | struct folio *filemap_get_incore_folio(struct address_space *mapping, |
135 | pgoff_t index) | |
014bb1de | 136 | { |
524984ff | 137 | return filemap_get_folio(mapping, index); |
014bb1de N |
138 | } |
139 | ||
09c02e56 | 140 | static inline bool add_to_swap(struct folio *folio) |
014bb1de | 141 | { |
09c02e56 | 142 | return false; |
014bb1de N |
143 | } |
144 | ||
145 | static inline void *get_shadow_from_swap_cache(swp_entry_t entry) | |
146 | { | |
147 | return NULL; | |
148 | } | |
149 | ||
a4c366f0 | 150 | static inline int add_to_swap_cache(struct folio *folio, swp_entry_t entry, |
014bb1de N |
151 | gfp_t gfp_mask, void **shadowp) |
152 | { | |
153 | return -1; | |
154 | } | |
155 | ||
ceff9d33 | 156 | static inline void __delete_from_swap_cache(struct folio *folio, |
014bb1de N |
157 | swp_entry_t entry, void *shadow) |
158 | { | |
159 | } | |
160 | ||
75fa68a5 | 161 | static inline void delete_from_swap_cache(struct folio *folio) |
014bb1de N |
162 | { |
163 | } | |
164 | ||
165 | static inline void clear_shadow_from_swap_cache(int type, unsigned long begin, | |
166 | unsigned long end) | |
167 | { | |
168 | } | |
169 | ||
b98c359f | 170 | static inline unsigned int folio_swap_flags(struct folio *folio) |
d791ea67 N |
171 | { |
172 | return 0; | |
173 | } | |
014bb1de N |
174 | #endif /* CONFIG_SWAP */ |
175 | #endif /* _MM_SWAP_H */ |