1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_FRONTSWAP_H
3 #define _LINUX_FRONTSWAP_H
5 #include <linux/swap.h>
7 #include <linux/bitops.h>
8 #include <linux/jump_label.h>
11 * Return code to denote that requested number of
12 * frontswap pages are unused(moved to page cache).
13 * Used in in shmem_unuse and try_to_unuse.
15 #define FRONTSWAP_PAGES_UNUSED 2
17 struct frontswap_ops
{
18 void (*init
)(unsigned); /* this swap type was just swapon'ed */
19 int (*store
)(unsigned, pgoff_t
, struct page
*); /* store a page */
20 int (*load
)(unsigned, pgoff_t
, struct page
*); /* load a page */
21 void (*invalidate_page
)(unsigned, pgoff_t
); /* page no longer needed */
22 void (*invalidate_area
)(unsigned); /* swap type just swapoff'ed */
23 struct frontswap_ops
*next
; /* private pointer to next ops */
26 extern void frontswap_register_ops(struct frontswap_ops
*ops
);
27 extern void frontswap_shrink(unsigned long);
28 extern unsigned long frontswap_curr_pages(void);
29 extern void frontswap_writethrough(bool);
30 #define FRONTSWAP_HAS_EXCLUSIVE_GETS
31 extern void frontswap_tmem_exclusive_gets(bool);
33 extern bool __frontswap_test(struct swap_info_struct
*, pgoff_t
);
34 extern void __frontswap_init(unsigned type
, unsigned long *map
);
35 extern int __frontswap_store(struct page
*page
);
36 extern int __frontswap_load(struct page
*page
);
37 extern void __frontswap_invalidate_page(unsigned, pgoff_t
);
38 extern void __frontswap_invalidate_area(unsigned);
40 #ifdef CONFIG_FRONTSWAP
41 extern struct static_key_false frontswap_enabled_key
;
43 static inline bool frontswap_enabled(void)
45 return static_branch_unlikely(&frontswap_enabled_key
);
48 static inline bool frontswap_test(struct swap_info_struct
*sis
, pgoff_t offset
)
50 return __frontswap_test(sis
, offset
);
53 static inline void frontswap_map_set(struct swap_info_struct
*p
,
56 p
->frontswap_map
= map
;
59 static inline unsigned long *frontswap_map_get(struct swap_info_struct
*p
)
61 return p
->frontswap_map
;
64 /* all inline routines become no-ops and all externs are ignored */
66 static inline bool frontswap_enabled(void)
71 static inline bool frontswap_test(struct swap_info_struct
*sis
, pgoff_t offset
)
76 static inline void frontswap_map_set(struct swap_info_struct
*p
,
81 static inline unsigned long *frontswap_map_get(struct swap_info_struct
*p
)
87 static inline int frontswap_store(struct page
*page
)
89 if (frontswap_enabled())
90 return __frontswap_store(page
);
95 static inline int frontswap_load(struct page
*page
)
97 if (frontswap_enabled())
98 return __frontswap_load(page
);
103 static inline void frontswap_invalidate_page(unsigned type
, pgoff_t offset
)
105 if (frontswap_enabled())
106 __frontswap_invalidate_page(type
, offset
);
109 static inline void frontswap_invalidate_area(unsigned type
)
111 if (frontswap_enabled())
112 __frontswap_invalidate_area(type
);
115 static inline void frontswap_init(unsigned type
, unsigned long *map
)
117 #ifdef CONFIG_FRONTSWAP
118 __frontswap_init(type
, map
);
122 #endif /* _LINUX_FRONTSWAP_H */