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> |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 7 | #include <linux/jump_label.h> |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 8 | |
| 9 | struct frontswap_ops { |
Dan Streetman | d1dc6f1 | 2015-06-24 16:58:18 -0700 | [diff] [blame] | 10 | 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 Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 16 | }; |
| 17 | |
Dan Streetman | d1dc6f1 | 2015-06-24 16:58:18 -0700 | [diff] [blame] | 18 | extern void frontswap_register_ops(struct frontswap_ops *ops); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 19 | extern void frontswap_shrink(unsigned long); |
| 20 | extern unsigned long frontswap_curr_pages(void); |
| 21 | extern void frontswap_writethrough(bool); |
Dan Magenheimer | e3483a5 | 2012-09-20 12:16:52 -0700 | [diff] [blame] | 22 | #define FRONTSWAP_HAS_EXCLUSIVE_GETS |
| 23 | extern void frontswap_tmem_exclusive_gets(bool); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 24 | |
Bob Liu | f066ea2 | 2013-04-30 15:26:53 -0700 | [diff] [blame] | 25 | extern bool __frontswap_test(struct swap_info_struct *, pgoff_t); |
Minchan Kim | 4f89849 | 2013-04-30 15:26:54 -0700 | [diff] [blame] | 26 | extern void __frontswap_init(unsigned type, unsigned long *map); |
Konrad Rzeszutek Wilk | 165c8ae | 2012-05-15 11:32:15 -0400 | [diff] [blame] | 27 | extern int __frontswap_store(struct page *page); |
| 28 | extern int __frontswap_load(struct page *page); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 29 | extern void __frontswap_invalidate_page(unsigned, pgoff_t); |
| 30 | extern void __frontswap_invalidate_area(unsigned); |
| 31 | |
| 32 | #ifdef CONFIG_FRONTSWAP |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 33 | extern struct static_key_false frontswap_enabled_key; |
| 34 | |
| 35 | static inline bool frontswap_enabled(void) |
| 36 | { |
| 37 | return static_branch_unlikely(&frontswap_enabled_key); |
| 38 | } |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 39 | |
| 40 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) |
| 41 | { |
Bob Liu | f066ea2 | 2013-04-30 15:26:53 -0700 | [diff] [blame] | 42 | return __frontswap_test(sis, offset); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | static inline void frontswap_map_set(struct swap_info_struct *p, |
| 46 | unsigned long *map) |
| 47 | { |
| 48 | p->frontswap_map = map; |
| 49 | } |
| 50 | |
| 51 | static 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 Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 58 | static inline bool frontswap_enabled(void) |
| 59 | { |
| 60 | return false; |
| 61 | } |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 62 | |
| 63 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) |
| 64 | { |
| 65 | return false; |
| 66 | } |
| 67 | |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 68 | static inline void frontswap_map_set(struct swap_info_struct *p, |
| 69 | unsigned long *map) |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | static inline unsigned long *frontswap_map_get(struct swap_info_struct *p) |
| 74 | { |
| 75 | return NULL; |
| 76 | } |
| 77 | #endif |
| 78 | |
Konrad Rzeszutek Wilk | 165c8ae | 2012-05-15 11:32:15 -0400 | [diff] [blame] | 79 | static inline int frontswap_store(struct page *page) |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 80 | { |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 81 | if (frontswap_enabled()) |
| 82 | return __frontswap_store(page); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 83 | |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 84 | return -1; |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 85 | } |
| 86 | |
Konrad Rzeszutek Wilk | 165c8ae | 2012-05-15 11:32:15 -0400 | [diff] [blame] | 87 | static inline int frontswap_load(struct page *page) |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 88 | { |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 89 | if (frontswap_enabled()) |
| 90 | return __frontswap_load(page); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 91 | |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 92 | return -1; |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset) |
| 96 | { |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 97 | if (frontswap_enabled()) |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 98 | __frontswap_invalidate_page(type, offset); |
| 99 | } |
| 100 | |
| 101 | static inline void frontswap_invalidate_area(unsigned type) |
| 102 | { |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 103 | if (frontswap_enabled()) |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 104 | __frontswap_invalidate_area(type); |
| 105 | } |
| 106 | |
Minchan Kim | 4f89849 | 2013-04-30 15:26:54 -0700 | [diff] [blame] | 107 | static inline void frontswap_init(unsigned type, unsigned long *map) |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 108 | { |
Vlastimil Babka | 5e322be | 2016-11-10 10:46:07 -0800 | [diff] [blame] | 109 | #ifdef CONFIG_FRONTSWAP |
| 110 | __frontswap_init(type, map); |
| 111 | #endif |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | #endif /* _LINUX_FRONTSWAP_H */ |