blob: 1d18af0345543aaecbfc46a04230735c2b0b0cf7 [file] [log] [blame]
Dan Magenheimerc3ba9692012-04-09 17:06:54 -06001#ifndef _LINUX_FRONTSWAP_H
2#define _LINUX_FRONTSWAP_H
3
4#include <linux/swap.h>
5#include <linux/mm.h>
6#include <linux/bitops.h>
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -07007#include <linux/jump_label.h>
Dan Magenheimerc3ba9692012-04-09 17:06:54 -06008
9struct frontswap_ops {
Dan Streetmand1dc6f12015-06-24 16:58:18 -070010 void (*init)(unsigned); /* this swap type was just swapon'ed */
11 int (*store)(unsigned, pgoff_t, struct page *); /* store a page */
12 int (*load)(unsigned, pgoff_t, struct page *); /* load a page */
13 void (*invalidate_page)(unsigned, pgoff_t); /* page no longer needed */
14 void (*invalidate_area)(unsigned); /* swap type just swapoff'ed */
15 struct frontswap_ops *next; /* private pointer to next ops */
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060016};
17
Dan Streetmand1dc6f12015-06-24 16:58:18 -070018extern void frontswap_register_ops(struct frontswap_ops *ops);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060019extern void frontswap_shrink(unsigned long);
20extern unsigned long frontswap_curr_pages(void);
21extern void frontswap_writethrough(bool);
Dan Magenheimere3483a52012-09-20 12:16:52 -070022#define FRONTSWAP_HAS_EXCLUSIVE_GETS
23extern void frontswap_tmem_exclusive_gets(bool);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060024
Bob Liuf066ea22013-04-30 15:26:53 -070025extern bool __frontswap_test(struct swap_info_struct *, pgoff_t);
Minchan Kim4f898492013-04-30 15:26:54 -070026extern void __frontswap_init(unsigned type, unsigned long *map);
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040027extern int __frontswap_store(struct page *page);
28extern int __frontswap_load(struct page *page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060029extern void __frontswap_invalidate_page(unsigned, pgoff_t);
30extern void __frontswap_invalidate_area(unsigned);
31
32#ifdef CONFIG_FRONTSWAP
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070033extern struct static_key_false frontswap_enabled_key;
34
35static inline bool frontswap_enabled(void)
36{
37 return static_branch_unlikely(&frontswap_enabled_key);
38}
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060039
40static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
41{
Bob Liuf066ea22013-04-30 15:26:53 -070042 return __frontswap_test(sis, offset);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060043}
44
45static inline void frontswap_map_set(struct swap_info_struct *p,
46 unsigned long *map)
47{
48 p->frontswap_map = map;
49}
50
51static inline unsigned long *frontswap_map_get(struct swap_info_struct *p)
52{
53 return p->frontswap_map;
54}
55#else
56/* all inline routines become no-ops and all externs are ignored */
57
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070058static inline bool frontswap_enabled(void)
59{
60 return false;
61}
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060062
63static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
64{
65 return false;
66}
67
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060068static inline void frontswap_map_set(struct swap_info_struct *p,
69 unsigned long *map)
70{
71}
72
73static inline unsigned long *frontswap_map_get(struct swap_info_struct *p)
74{
75 return NULL;
76}
77#endif
78
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040079static inline int frontswap_store(struct page *page)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060080{
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070081 if (frontswap_enabled())
82 return __frontswap_store(page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060083
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070084 return -1;
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060085}
86
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040087static inline int frontswap_load(struct page *page)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060088{
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070089 if (frontswap_enabled())
90 return __frontswap_load(page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060091
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070092 return -1;
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060093}
94
95static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset)
96{
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070097 if (frontswap_enabled())
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060098 __frontswap_invalidate_page(type, offset);
99}
100
101static inline void frontswap_invalidate_area(unsigned type)
102{
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -0700103 if (frontswap_enabled())
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600104 __frontswap_invalidate_area(type);
105}
106
Minchan Kim4f898492013-04-30 15:26:54 -0700107static inline void frontswap_init(unsigned type, unsigned long *map)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600108{
Vlastimil Babka5e322be2016-11-10 10:46:07 -0800109#ifdef CONFIG_FRONTSWAP
110 __frontswap_init(type, map);
111#endif
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600112}
113
114#endif /* _LINUX_FRONTSWAP_H */