blob: e65ef959546cd8f35ec4a3a78e4d97d822781f04 [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>
7
8struct frontswap_ops {
Dan Streetmand1dc6f12015-06-24 16:58:18 -07009 void (*init)(unsigned); /* this swap type was just swapon'ed */
10 int (*store)(unsigned, pgoff_t, struct page *); /* store a page */
11 int (*load)(unsigned, pgoff_t, struct page *); /* load a page */
12 void (*invalidate_page)(unsigned, pgoff_t); /* page no longer needed */
13 void (*invalidate_area)(unsigned); /* swap type just swapoff'ed */
14 struct frontswap_ops *next; /* private pointer to next ops */
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060015};
16
17extern bool frontswap_enabled;
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
Bob Liuf066ea22013-04-30 15:26:53 -070033#define frontswap_enabled (1)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060034
35static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
36{
Bob Liuf066ea22013-04-30 15:26:53 -070037 return __frontswap_test(sis, offset);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060038}
39
40static inline void frontswap_map_set(struct swap_info_struct *p,
41 unsigned long *map)
42{
43 p->frontswap_map = map;
44}
45
46static inline unsigned long *frontswap_map_get(struct swap_info_struct *p)
47{
48 return p->frontswap_map;
49}
50#else
51/* all inline routines become no-ops and all externs are ignored */
52
53#define frontswap_enabled (0)
54
55static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
56{
57 return false;
58}
59
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060060static inline void frontswap_map_set(struct swap_info_struct *p,
61 unsigned long *map)
62{
63}
64
65static inline unsigned long *frontswap_map_get(struct swap_info_struct *p)
66{
67 return NULL;
68}
69#endif
70
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040071static inline int frontswap_store(struct page *page)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060072{
73 int ret = -1;
74
75 if (frontswap_enabled)
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040076 ret = __frontswap_store(page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060077 return ret;
78}
79
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040080static inline int frontswap_load(struct page *page)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060081{
82 int ret = -1;
83
84 if (frontswap_enabled)
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040085 ret = __frontswap_load(page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060086 return ret;
87}
88
89static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset)
90{
91 if (frontswap_enabled)
92 __frontswap_invalidate_page(type, offset);
93}
94
95static inline void frontswap_invalidate_area(unsigned type)
96{
97 if (frontswap_enabled)
98 __frontswap_invalidate_area(type);
99}
100
Minchan Kim4f898492013-04-30 15:26:54 -0700101static inline void frontswap_init(unsigned type, unsigned long *map)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600102{
103 if (frontswap_enabled)
Minchan Kim4f898492013-04-30 15:26:54 -0700104 __frontswap_init(type, map);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600105}
106
107#endif /* _LINUX_FRONTSWAP_H */