xref: /openbmc/linux/mm/swap.h (revision 8d81cd1a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _MM_SWAP_H
3 #define _MM_SWAP_H
4 
5 #ifdef CONFIG_SWAP
6 #include <linux/blk_types.h> /* for bio_end_io_t */
7 
8 /* linux/mm/page_io.c */
9 int sio_pool_init(void);
10 struct swap_iocb;
11 void swap_readpage(struct page *page, bool do_poll, struct swap_iocb **plug);
12 void __swap_read_unplug(struct swap_iocb *plug);
13 static inline void swap_read_unplug(struct swap_iocb *plug)
14 {
15 	if (unlikely(plug))
16 		__swap_read_unplug(plug);
17 }
18 void swap_write_unplug(struct swap_iocb *sio);
19 int swap_writepage(struct page *page, struct writeback_control *wbc);
20 void __swap_writepage(struct page *page, struct writeback_control *wbc);
21 
22 /* linux/mm/swap_state.c */
23 /* One swap address space for each 64M swap space */
24 #define SWAP_ADDRESS_SPACE_SHIFT	14
25 #define SWAP_ADDRESS_SPACE_PAGES	(1 << SWAP_ADDRESS_SPACE_SHIFT)
26 extern struct address_space *swapper_spaces[];
27 #define swap_address_space(entry)			    \
28 	(&swapper_spaces[swp_type(entry)][swp_offset(entry) \
29 		>> SWAP_ADDRESS_SPACE_SHIFT])
30 
31 void show_swap_cache_info(void);
32 bool add_to_swap(struct folio *folio);
33 void *get_shadow_from_swap_cache(swp_entry_t entry);
34 int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
35 		      gfp_t gfp, void **shadowp);
36 void __delete_from_swap_cache(struct folio *folio,
37 			      swp_entry_t entry, void *shadow);
38 void delete_from_swap_cache(struct folio *folio);
39 void clear_shadow_from_swap_cache(int type, unsigned long begin,
40 				  unsigned long end);
41 void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry);
42 struct folio *swap_cache_get_folio(swp_entry_t entry,
43 		struct vm_area_struct *vma, unsigned long addr);
44 struct folio *filemap_get_incore_folio(struct address_space *mapping,
45 		pgoff_t index);
46 
47 struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
48 				   struct vm_area_struct *vma,
49 				   unsigned long addr,
50 				   struct swap_iocb **plug);
51 struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
52 				     struct vm_area_struct *vma,
53 				     unsigned long addr,
54 				     bool *new_page_allocated);
55 struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t flag,
56 				    struct vm_fault *vmf);
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 vm_fault *vmf)
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 void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry)
101 {
102 }
103 
104 static inline struct folio *swap_cache_get_folio(swp_entry_t entry,
105 		struct vm_area_struct *vma, unsigned long addr)
106 {
107 	return NULL;
108 }
109 
110 static inline
111 struct folio *filemap_get_incore_folio(struct address_space *mapping,
112 		pgoff_t index)
113 {
114 	return filemap_get_folio(mapping, index);
115 }
116 
117 static inline bool add_to_swap(struct folio *folio)
118 {
119 	return false;
120 }
121 
122 static inline void *get_shadow_from_swap_cache(swp_entry_t entry)
123 {
124 	return NULL;
125 }
126 
127 static inline int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
128 					gfp_t gfp_mask, void **shadowp)
129 {
130 	return -1;
131 }
132 
133 static inline void __delete_from_swap_cache(struct folio *folio,
134 					swp_entry_t entry, void *shadow)
135 {
136 }
137 
138 static inline void delete_from_swap_cache(struct folio *folio)
139 {
140 }
141 
142 static inline void clear_shadow_from_swap_cache(int type, unsigned long begin,
143 				unsigned long end)
144 {
145 }
146 
147 static inline unsigned int folio_swap_flags(struct folio *folio)
148 {
149 	return 0;
150 }
151 #endif /* CONFIG_SWAP */
152 #endif /* _MM_SWAP_H */
153