Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame^] | 1 | #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 | |
| 8 | struct frontswap_ops { |
| 9 | void (*init)(unsigned); |
| 10 | int (*put_page)(unsigned, pgoff_t, struct page *); |
| 11 | int (*get_page)(unsigned, pgoff_t, struct page *); |
| 12 | void (*invalidate_page)(unsigned, pgoff_t); |
| 13 | void (*invalidate_area)(unsigned); |
| 14 | }; |
| 15 | |
| 16 | extern bool frontswap_enabled; |
| 17 | extern struct frontswap_ops |
| 18 | frontswap_register_ops(struct frontswap_ops *ops); |
| 19 | extern void frontswap_shrink(unsigned long); |
| 20 | extern unsigned long frontswap_curr_pages(void); |
| 21 | extern void frontswap_writethrough(bool); |
| 22 | |
| 23 | extern void __frontswap_init(unsigned type); |
| 24 | extern int __frontswap_put_page(struct page *page); |
| 25 | extern int __frontswap_get_page(struct page *page); |
| 26 | extern void __frontswap_invalidate_page(unsigned, pgoff_t); |
| 27 | extern void __frontswap_invalidate_area(unsigned); |
| 28 | |
| 29 | #ifdef CONFIG_FRONTSWAP |
| 30 | |
| 31 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) |
| 32 | { |
| 33 | bool ret = false; |
| 34 | |
| 35 | if (frontswap_enabled && sis->frontswap_map) |
| 36 | ret = test_bit(offset, sis->frontswap_map); |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | static inline void frontswap_set(struct swap_info_struct *sis, pgoff_t offset) |
| 41 | { |
| 42 | if (frontswap_enabled && sis->frontswap_map) |
| 43 | set_bit(offset, sis->frontswap_map); |
| 44 | } |
| 45 | |
| 46 | static inline void frontswap_clear(struct swap_info_struct *sis, pgoff_t offset) |
| 47 | { |
| 48 | if (frontswap_enabled && sis->frontswap_map) |
| 49 | clear_bit(offset, sis->frontswap_map); |
| 50 | } |
| 51 | |
| 52 | static inline void frontswap_map_set(struct swap_info_struct *p, |
| 53 | unsigned long *map) |
| 54 | { |
| 55 | p->frontswap_map = map; |
| 56 | } |
| 57 | |
| 58 | static inline unsigned long *frontswap_map_get(struct swap_info_struct *p) |
| 59 | { |
| 60 | return p->frontswap_map; |
| 61 | } |
| 62 | #else |
| 63 | /* all inline routines become no-ops and all externs are ignored */ |
| 64 | |
| 65 | #define frontswap_enabled (0) |
| 66 | |
| 67 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) |
| 68 | { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | static inline void frontswap_set(struct swap_info_struct *sis, pgoff_t offset) |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | static inline void frontswap_clear(struct swap_info_struct *sis, pgoff_t offset) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | static inline void frontswap_map_set(struct swap_info_struct *p, |
| 81 | unsigned long *map) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | static inline unsigned long *frontswap_map_get(struct swap_info_struct *p) |
| 86 | { |
| 87 | return NULL; |
| 88 | } |
| 89 | #endif |
| 90 | |
| 91 | static inline int frontswap_put_page(struct page *page) |
| 92 | { |
| 93 | int ret = -1; |
| 94 | |
| 95 | if (frontswap_enabled) |
| 96 | ret = __frontswap_put_page(page); |
| 97 | return ret; |
| 98 | } |
| 99 | |
| 100 | static inline int frontswap_get_page(struct page *page) |
| 101 | { |
| 102 | int ret = -1; |
| 103 | |
| 104 | if (frontswap_enabled) |
| 105 | ret = __frontswap_get_page(page); |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset) |
| 110 | { |
| 111 | if (frontswap_enabled) |
| 112 | __frontswap_invalidate_page(type, offset); |
| 113 | } |
| 114 | |
| 115 | static inline void frontswap_invalidate_area(unsigned type) |
| 116 | { |
| 117 | if (frontswap_enabled) |
| 118 | __frontswap_invalidate_area(type); |
| 119 | } |
| 120 | |
| 121 | static inline void frontswap_init(unsigned type) |
| 122 | { |
| 123 | if (frontswap_enabled) |
| 124 | __frontswap_init(type); |
| 125 | } |
| 126 | |
| 127 | #endif /* _LINUX_FRONTSWAP_H */ |