blob: 30442547b9e6b8b8aed1d17ecff37fb6298b18e2 [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 {
9 void (*init)(unsigned);
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040010 int (*store)(unsigned, pgoff_t, struct page *);
11 int (*load)(unsigned, pgoff_t, struct page *);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060012 void (*invalidate_page)(unsigned, pgoff_t);
13 void (*invalidate_area)(unsigned);
14};
15
16extern bool frontswap_enabled;
17extern struct frontswap_ops
18 frontswap_register_ops(struct frontswap_ops *ops);
19extern 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
25extern void __frontswap_init(unsigned type);
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040026extern int __frontswap_store(struct page *page);
27extern int __frontswap_load(struct page *page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060028extern void __frontswap_invalidate_page(unsigned, pgoff_t);
29extern void __frontswap_invalidate_area(unsigned);
30
31#ifdef CONFIG_FRONTSWAP
32
33static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
34{
35 bool ret = false;
36
37 if (frontswap_enabled && sis->frontswap_map)
38 ret = test_bit(offset, sis->frontswap_map);
39 return ret;
40}
41
42static inline void frontswap_set(struct swap_info_struct *sis, pgoff_t offset)
43{
44 if (frontswap_enabled && sis->frontswap_map)
45 set_bit(offset, sis->frontswap_map);
46}
47
48static inline void frontswap_clear(struct swap_info_struct *sis, pgoff_t offset)
49{
50 if (frontswap_enabled && sis->frontswap_map)
51 clear_bit(offset, sis->frontswap_map);
52}
53
54static inline void frontswap_map_set(struct swap_info_struct *p,
55 unsigned long *map)
56{
57 p->frontswap_map = map;
58}
59
60static inline unsigned long *frontswap_map_get(struct swap_info_struct *p)
61{
62 return p->frontswap_map;
63}
64#else
65/* all inline routines become no-ops and all externs are ignored */
66
67#define frontswap_enabled (0)
68
69static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
70{
71 return false;
72}
73
74static inline void frontswap_set(struct swap_info_struct *sis, pgoff_t offset)
75{
76}
77
78static inline void frontswap_clear(struct swap_info_struct *sis, pgoff_t offset)
79{
80}
81
82static inline void frontswap_map_set(struct swap_info_struct *p,
83 unsigned long *map)
84{
85}
86
87static inline unsigned long *frontswap_map_get(struct swap_info_struct *p)
88{
89 return NULL;
90}
91#endif
92
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040093static inline int frontswap_store(struct page *page)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060094{
95 int ret = -1;
96
97 if (frontswap_enabled)
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040098 ret = __frontswap_store(page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060099 return ret;
100}
101
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -0400102static inline int frontswap_load(struct page *page)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600103{
104 int ret = -1;
105
106 if (frontswap_enabled)
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -0400107 ret = __frontswap_load(page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600108 return ret;
109}
110
111static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset)
112{
113 if (frontswap_enabled)
114 __frontswap_invalidate_page(type, offset);
115}
116
117static inline void frontswap_invalidate_area(unsigned type)
118{
119 if (frontswap_enabled)
120 __frontswap_invalidate_area(type);
121}
122
123static inline void frontswap_init(unsigned type)
124{
125 if (frontswap_enabled)
126 __frontswap_init(type);
127}
128
129#endif /* _LINUX_FRONTSWAP_H */