Merge tag '6.11-rc-smb-client-fixes-part2' of git://git.samba.org/sfrench/cifs-2.6
[linux-stable.git] / mm / swap.h
blobbaa1fa946b347b3464962283160f8bd9cf6e9bf0
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _MM_SWAP_H
3 #define _MM_SWAP_H
5 struct mempolicy;
7 #ifdef CONFIG_SWAP
8 #include <linux/swapops.h> /* for swp_offset */
9 #include <linux/blk_types.h> /* for bio_end_io_t */
11 /* linux/mm/page_io.c */
12 int sio_pool_init(void);
13 struct swap_iocb;
14 void swap_read_folio(struct folio *folio, struct swap_iocb **plug);
15 void __swap_read_unplug(struct swap_iocb *plug);
16 static inline void swap_read_unplug(struct swap_iocb *plug)
18 if (unlikely(plug))
19 __swap_read_unplug(plug);
21 void swap_write_unplug(struct swap_iocb *sio);
22 int swap_writepage(struct page *page, struct writeback_control *wbc);
23 void __swap_writepage(struct folio *folio, struct writeback_control *wbc);
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)
29 #define SWAP_ADDRESS_SPACE_MASK (SWAP_ADDRESS_SPACE_PAGES - 1)
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])
36 * Return the swap device position of the swap entry.
38 static inline loff_t swap_dev_pos(swp_entry_t entry)
40 return ((loff_t)swp_offset(entry)) << PAGE_SHIFT;
44 * Return the swap cache index of the swap entry.
46 static inline pgoff_t swap_cache_index(swp_entry_t entry)
48 BUILD_BUG_ON((SWP_OFFSET_MASK | SWAP_ADDRESS_SPACE_MASK) != SWP_OFFSET_MASK);
49 return swp_offset(entry) & SWAP_ADDRESS_SPACE_MASK;
52 void show_swap_cache_info(void);
53 bool add_to_swap(struct folio *folio);
54 void *get_shadow_from_swap_cache(swp_entry_t entry);
55 int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
56 gfp_t gfp, void **shadowp);
57 void __delete_from_swap_cache(struct folio *folio,
58 swp_entry_t entry, void *shadow);
59 void delete_from_swap_cache(struct folio *folio);
60 void clear_shadow_from_swap_cache(int type, unsigned long begin,
61 unsigned long end);
62 void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry);
63 struct folio *swap_cache_get_folio(swp_entry_t entry,
64 struct vm_area_struct *vma, unsigned long addr);
65 struct folio *filemap_get_incore_folio(struct address_space *mapping,
66 pgoff_t index);
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);
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);
74 struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t flag,
75 struct mempolicy *mpol, pgoff_t ilx);
76 struct page *swapin_readahead(swp_entry_t entry, gfp_t flag,
77 struct vm_fault *vmf);
79 static inline unsigned int folio_swap_flags(struct folio *folio)
81 return swp_swap_info(folio->swap)->flags;
83 #else /* CONFIG_SWAP */
84 struct swap_iocb;
85 static inline void swap_read_folio(struct folio *folio, struct swap_iocb **plug)
88 static inline void swap_write_unplug(struct swap_iocb *sio)
92 static inline struct address_space *swap_address_space(swp_entry_t entry)
94 return NULL;
97 static inline pgoff_t swap_cache_index(swp_entry_t entry)
99 return 0;
102 static inline void show_swap_cache_info(void)
106 static inline struct folio *swap_cluster_readahead(swp_entry_t entry,
107 gfp_t gfp_mask, struct mempolicy *mpol, pgoff_t ilx)
109 return NULL;
112 static inline struct page *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask,
113 struct vm_fault *vmf)
115 return NULL;
118 static inline int swap_writepage(struct page *p, struct writeback_control *wbc)
120 return 0;
123 static inline void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry)
127 static inline struct folio *swap_cache_get_folio(swp_entry_t entry,
128 struct vm_area_struct *vma, unsigned long addr)
130 return NULL;
133 static inline
134 struct folio *filemap_get_incore_folio(struct address_space *mapping,
135 pgoff_t index)
137 return filemap_get_folio(mapping, index);
140 static inline bool add_to_swap(struct folio *folio)
142 return false;
145 static inline void *get_shadow_from_swap_cache(swp_entry_t entry)
147 return NULL;
150 static inline int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
151 gfp_t gfp_mask, void **shadowp)
153 return -1;
156 static inline void __delete_from_swap_cache(struct folio *folio,
157 swp_entry_t entry, void *shadow)
161 static inline void delete_from_swap_cache(struct folio *folio)
165 static inline void clear_shadow_from_swap_cache(int type, unsigned long begin,
166 unsigned long end)
170 static inline unsigned int folio_swap_flags(struct folio *folio)
172 return 0;
174 #endif /* CONFIG_SWAP */
175 #endif /* _MM_SWAP_H */