Loading...
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 */
9int sio_pool_init(void);
10struct swap_iocb;
11int swap_readpage(struct page *page, bool do_poll,
12 struct swap_iocb **plug);
13void __swap_read_unplug(struct swap_iocb *plug);
14static inline void swap_read_unplug(struct swap_iocb *plug)
15{
16 if (unlikely(plug))
17 __swap_read_unplug(plug);
18}
19void swap_write_unplug(struct swap_iocb *sio);
20int swap_writepage(struct page *page, struct writeback_control *wbc);
21int __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)
27extern 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
32void show_swap_cache_info(void);
33bool add_to_swap(struct folio *folio);
34void *get_shadow_from_swap_cache(swp_entry_t entry);
35int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
36 gfp_t gfp, void **shadowp);
37void __delete_from_swap_cache(struct folio *folio,
38 swp_entry_t entry, void *shadow);
39void delete_from_swap_cache(struct folio *folio);
40void clear_shadow_from_swap_cache(int type, unsigned long begin,
41 unsigned long end);
42struct folio *swap_cache_get_folio(swp_entry_t entry,
43 struct vm_area_struct *vma, unsigned long addr);
44struct folio *filemap_get_incore_folio(struct address_space *mapping,
45 pgoff_t index);
46
47struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
48 struct vm_area_struct *vma,
49 unsigned long addr,
50 bool do_poll,
51 struct swap_iocb **plug);
52struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
53 struct vm_area_struct *vma,
54 unsigned long addr,
55 bool *new_page_allocated);
56struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t flag,
57 struct vm_fault *vmf);
58struct page *swapin_readahead(swp_entry_t entry, gfp_t flag,
59 struct vm_fault *vmf);
60
61static inline unsigned int folio_swap_flags(struct folio *folio)
62{
63 return page_swap_info(&folio->page)->flags;
64}
65#else /* CONFIG_SWAP */
66struct swap_iocb;
67static inline int swap_readpage(struct page *page, bool do_poll,
68 struct swap_iocb **plug)
69{
70 return 0;
71}
72static inline void swap_write_unplug(struct swap_iocb *sio)
73{
74}
75
76static inline struct address_space *swap_address_space(swp_entry_t entry)
77{
78 return NULL;
79}
80
81static inline void show_swap_cache_info(void)
82{
83}
84
85static inline struct page *swap_cluster_readahead(swp_entry_t entry,
86 gfp_t gfp_mask, struct vm_fault *vmf)
87{
88 return NULL;
89}
90
91static inline struct page *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask,
92 struct vm_fault *vmf)
93{
94 return NULL;
95}
96
97static inline int swap_writepage(struct page *p, struct writeback_control *wbc)
98{
99 return 0;
100}
101
102static inline struct folio *swap_cache_get_folio(swp_entry_t entry,
103 struct vm_area_struct *vma, unsigned long addr)
104{
105 return NULL;
106}
107
108static inline
109struct folio *filemap_get_incore_folio(struct address_space *mapping,
110 pgoff_t index)
111{
112 return filemap_get_folio(mapping, index);
113}
114
115static inline bool add_to_swap(struct folio *folio)
116{
117 return false;
118}
119
120static inline void *get_shadow_from_swap_cache(swp_entry_t entry)
121{
122 return NULL;
123}
124
125static inline int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
126 gfp_t gfp_mask, void **shadowp)
127{
128 return -1;
129}
130
131static inline void __delete_from_swap_cache(struct folio *folio,
132 swp_entry_t entry, void *shadow)
133{
134}
135
136static inline void delete_from_swap_cache(struct folio *folio)
137{
138}
139
140static inline void clear_shadow_from_swap_cache(int type, unsigned long begin,
141 unsigned long end)
142{
143}
144
145static inline unsigned int folio_swap_flags(struct folio *folio)
146{
147 return 0;
148}
149#endif /* CONFIG_SWAP */
150#endif /* _MM_SWAP_H */
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _MM_SWAP_H
3#define _MM_SWAP_H
4
5struct mempolicy;
6
7#ifdef CONFIG_SWAP
8#include <linux/blk_types.h> /* for bio_end_io_t */
9
10/* linux/mm/page_io.c */
11int sio_pool_init(void);
12struct swap_iocb;
13void swap_read_folio(struct folio *folio, bool do_poll,
14 struct swap_iocb **plug);
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}
21void swap_write_unplug(struct swap_iocb *sio);
22int swap_writepage(struct page *page, struct writeback_control *wbc);
23void __swap_writepage(struct folio *folio, struct writeback_control *wbc);
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)
29extern struct address_space *swapper_spaces[];
30#define swap_address_space(entry) \
31 (&swapper_spaces[swp_type(entry)][swp_offset(entry) \
32 >> SWAP_ADDRESS_SPACE_SHIFT])
33
34void show_swap_cache_info(void);
35bool add_to_swap(struct folio *folio);
36void *get_shadow_from_swap_cache(swp_entry_t entry);
37int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
38 gfp_t gfp, void **shadowp);
39void __delete_from_swap_cache(struct folio *folio,
40 swp_entry_t entry, void *shadow);
41void delete_from_swap_cache(struct folio *folio);
42void clear_shadow_from_swap_cache(int type, unsigned long begin,
43 unsigned long end);
44void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry);
45struct folio *swap_cache_get_folio(swp_entry_t entry,
46 struct vm_area_struct *vma, unsigned long addr);
47struct folio *filemap_get_incore_folio(struct address_space *mapping,
48 pgoff_t index);
49
50struct folio *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
51 struct vm_area_struct *vma, unsigned long addr,
52 struct swap_iocb **plug);
53struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_flags,
54 struct mempolicy *mpol, pgoff_t ilx, bool *new_page_allocated,
55 bool skip_if_exists);
56struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t flag,
57 struct mempolicy *mpol, pgoff_t ilx);
58struct page *swapin_readahead(swp_entry_t entry, gfp_t flag,
59 struct vm_fault *vmf);
60
61static inline unsigned int folio_swap_flags(struct folio *folio)
62{
63 return swp_swap_info(folio->swap)->flags;
64}
65#else /* CONFIG_SWAP */
66struct swap_iocb;
67static inline void swap_read_folio(struct folio *folio, bool do_poll,
68 struct swap_iocb **plug)
69{
70}
71static inline void swap_write_unplug(struct swap_iocb *sio)
72{
73}
74
75static inline struct address_space *swap_address_space(swp_entry_t entry)
76{
77 return NULL;
78}
79
80static inline void show_swap_cache_info(void)
81{
82}
83
84static inline struct folio *swap_cluster_readahead(swp_entry_t entry,
85 gfp_t gfp_mask, struct mempolicy *mpol, pgoff_t ilx)
86{
87 return NULL;
88}
89
90static inline struct page *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask,
91 struct vm_fault *vmf)
92{
93 return NULL;
94}
95
96static inline int swap_writepage(struct page *p, struct writeback_control *wbc)
97{
98 return 0;
99}
100
101static inline void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry)
102{
103}
104
105static inline struct folio *swap_cache_get_folio(swp_entry_t entry,
106 struct vm_area_struct *vma, unsigned long addr)
107{
108 return NULL;
109}
110
111static inline
112struct folio *filemap_get_incore_folio(struct address_space *mapping,
113 pgoff_t index)
114{
115 return filemap_get_folio(mapping, index);
116}
117
118static inline bool add_to_swap(struct folio *folio)
119{
120 return false;
121}
122
123static inline void *get_shadow_from_swap_cache(swp_entry_t entry)
124{
125 return NULL;
126}
127
128static inline int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
129 gfp_t gfp_mask, void **shadowp)
130{
131 return -1;
132}
133
134static inline void __delete_from_swap_cache(struct folio *folio,
135 swp_entry_t entry, void *shadow)
136{
137}
138
139static inline void delete_from_swap_cache(struct folio *folio)
140{
141}
142
143static inline void clear_shadow_from_swap_cache(int type, unsigned long begin,
144 unsigned long end)
145{
146}
147
148static inline unsigned int folio_swap_flags(struct folio *folio)
149{
150 return 0;
151}
152#endif /* CONFIG_SWAP */
153#endif /* _MM_SWAP_H */