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