Merge tag 'powerpc-6.13-3' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[linux.git] / mm / swap.h
CommitLineData
014bb1de
N
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _MM_SWAP_H
3#define _MM_SWAP_H
4
ddc1a5cb
HD
5struct 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 12int sio_pool_init(void);
5169b844 13struct swap_iocb;
b2d1f38b 14void swap_read_folio(struct folio *folio, struct swap_iocb **plug);
5169b844
N
15void __swap_read_unplug(struct swap_iocb *plug);
16static inline void swap_read_unplug(struct swap_iocb *plug)
17{
18 if (unlikely(plug))
19 __swap_read_unplug(plug);
20}
2282679f 21void swap_write_unplug(struct swap_iocb *sio);
014bb1de 22int swap_writepage(struct page *page, struct writeback_control *wbc);
b99b4e0d 23void __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
30extern 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 */
38static 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 */
46static 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 52void show_swap_cache_info(void);
09c02e56 53bool add_to_swap(struct folio *folio);
014bb1de 54void *get_shadow_from_swap_cache(swp_entry_t entry);
a4c366f0 55int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
014bb1de 56 gfp_t gfp, void **shadowp);
ceff9d33 57void __delete_from_swap_cache(struct folio *folio,
014bb1de 58 swp_entry_t entry, void *shadow);
75fa68a5 59void delete_from_swap_cache(struct folio *folio);
014bb1de
N
60void clear_shadow_from_swap_cache(int type, unsigned long begin,
61 unsigned long end);
9f101bef 62void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry, int nr);
c9edc242
MWO
63struct folio *swap_cache_get_folio(swp_entry_t entry,
64 struct vm_area_struct *vma, unsigned long addr);
524984ff
MWO
65struct folio *filemap_get_incore_folio(struct address_space *mapping,
66 pgoff_t index);
014bb1de 67
6e03492e
MWO
68struct 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
71struct 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
74struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t flag,
75 struct mempolicy *mpol, pgoff_t ilx);
94dc8bff
MWO
76struct folio *swapin_readahead(swp_entry_t entry, gfp_t flag,
77 struct vm_fault *vmf);
014bb1de 78
b98c359f 79static inline unsigned int folio_swap_flags(struct folio *folio)
d791ea67 80{
69fe7d67 81 return swp_swap_info(folio->swap)->flags;
d791ea67 82}
9d57090e
BS
83
84/*
85 * Return the count of contiguous swap entries that share the same
86 * zeromap status as the starting entry. If is_zeromap is not NULL,
87 * it will return the zeromap status of the starting entry.
88 */
89static inline int swap_zeromap_batch(swp_entry_t entry, int max_nr,
90 bool *is_zeromap)
91{
92 struct swap_info_struct *sis = swp_swap_info(entry);
93 unsigned long start = swp_offset(entry);
94 unsigned long end = start + max_nr;
95 bool first_bit;
96
97 first_bit = test_bit(start, sis->zeromap);
98 if (is_zeromap)
99 *is_zeromap = first_bit;
100
101 if (max_nr <= 1)
102 return max_nr;
103 if (first_bit)
104 return find_next_zero_bit(sis->zeromap, end, start) - start;
105 else
106 return find_next_bit(sis->zeromap, end, start) - start;
107}
108
014bb1de 109#else /* CONFIG_SWAP */
5169b844 110struct swap_iocb;
b2d1f38b 111static inline void swap_read_folio(struct folio *folio, struct swap_iocb **plug)
014bb1de 112{
014bb1de 113}
2282679f
N
114static inline void swap_write_unplug(struct swap_iocb *sio)
115{
116}
014bb1de
N
117
118static inline struct address_space *swap_address_space(swp_entry_t entry)
119{
120 return NULL;
121}
122
7aad25b4
KS
123static inline pgoff_t swap_cache_index(swp_entry_t entry)
124{
125 return 0;
126}
127
014bb1de
N
128static inline void show_swap_cache_info(void)
129{
130}
131
a4575c41 132static inline struct folio *swap_cluster_readahead(swp_entry_t entry,
ddc1a5cb 133 gfp_t gfp_mask, struct mempolicy *mpol, pgoff_t ilx)
014bb1de
N
134{
135 return NULL;
136}
137
94dc8bff 138static inline struct folio *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask,
014bb1de
N
139 struct vm_fault *vmf)
140{
141 return NULL;
142}
143
144static inline int swap_writepage(struct page *p, struct writeback_control *wbc)
145{
146 return 0;
147}
148
9f101bef 149static inline void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry, int nr)
13ddaf26
KS
150{
151}
152
c9edc242
MWO
153static inline struct folio *swap_cache_get_folio(swp_entry_t entry,
154 struct vm_area_struct *vma, unsigned long addr)
155{
156 return NULL;
157}
158
014bb1de 159static inline
524984ff
MWO
160struct folio *filemap_get_incore_folio(struct address_space *mapping,
161 pgoff_t index)
014bb1de 162{
524984ff 163 return filemap_get_folio(mapping, index);
014bb1de
N
164}
165
09c02e56 166static inline bool add_to_swap(struct folio *folio)
014bb1de 167{
09c02e56 168 return false;
014bb1de
N
169}
170
171static inline void *get_shadow_from_swap_cache(swp_entry_t entry)
172{
173 return NULL;
174}
175
a4c366f0 176static inline int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
014bb1de
N
177 gfp_t gfp_mask, void **shadowp)
178{
179 return -1;
180}
181
ceff9d33 182static inline void __delete_from_swap_cache(struct folio *folio,
014bb1de
N
183 swp_entry_t entry, void *shadow)
184{
185}
186
75fa68a5 187static inline void delete_from_swap_cache(struct folio *folio)
014bb1de
N
188{
189}
190
191static inline void clear_shadow_from_swap_cache(int type, unsigned long begin,
192 unsigned long end)
193{
194}
195
b98c359f 196static inline unsigned int folio_swap_flags(struct folio *folio)
d791ea67
N
197{
198 return 0;
199}
9d57090e
BS
200
201static inline int swap_zeromap_batch(swp_entry_t entry, int max_nr,
202 bool *has_zeromap)
203{
204 return 0;
205}
206
014bb1de 207#endif /* CONFIG_SWAP */
9f101bef 208
014bb1de 209#endif /* _MM_SWAP_H */
This page took 0.317948 seconds and 4 git commands to generate.