Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 2 | #ifndef _LINUX_FRONTSWAP_H |
| 3 | #define _LINUX_FRONTSWAP_H |
| 4 | |
| 5 | #include <linux/swap.h> |
| 6 | #include <linux/mm.h> |
| 7 | #include <linux/bitops.h> |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 8 | #include <linux/jump_label.h> |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 9 | |
| 10 | struct frontswap_ops { |
Dan Streetman | d1dc6f1 | 2015-06-24 16:58:18 -0700 | [diff] [blame] | 11 | void (*init)(unsigned); /* this swap type was just swapon'ed */ |
| 12 | int (*store)(unsigned, pgoff_t, struct page *); /* store a page */ |
| 13 | int (*load)(unsigned, pgoff_t, struct page *); /* load a page */ |
| 14 | void (*invalidate_page)(unsigned, pgoff_t); /* page no longer needed */ |
| 15 | void (*invalidate_area)(unsigned); /* swap type just swapoff'ed */ |
| 16 | struct frontswap_ops *next; /* private pointer to next ops */ |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 17 | }; |
| 18 | |
Dan Streetman | d1dc6f1 | 2015-06-24 16:58:18 -0700 | [diff] [blame] | 19 | extern void frontswap_register_ops(struct frontswap_ops *ops); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 20 | extern void frontswap_shrink(unsigned long); |
| 21 | extern unsigned long frontswap_curr_pages(void); |
| 22 | extern void frontswap_writethrough(bool); |
Dan Magenheimer | e3483a5 | 2012-09-20 12:16:52 -0700 | [diff] [blame] | 23 | #define FRONTSWAP_HAS_EXCLUSIVE_GETS |
| 24 | extern void frontswap_tmem_exclusive_gets(bool); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 25 | |
Bob Liu | f066ea2 | 2013-04-30 15:26:53 -0700 | [diff] [blame] | 26 | extern bool __frontswap_test(struct swap_info_struct *, pgoff_t); |
Minchan Kim | 4f89849 | 2013-04-30 15:26:54 -0700 | [diff] [blame] | 27 | extern void __frontswap_init(unsigned type, unsigned long *map); |
Konrad Rzeszutek Wilk | 165c8ae | 2012-05-15 11:32:15 -0400 | [diff] [blame] | 28 | extern int __frontswap_store(struct page *page); |
| 29 | extern int __frontswap_load(struct page *page); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 30 | extern void __frontswap_invalidate_page(unsigned, pgoff_t); |
| 31 | extern void __frontswap_invalidate_area(unsigned); |
| 32 | |
| 33 | #ifdef CONFIG_FRONTSWAP |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 34 | extern struct static_key_false frontswap_enabled_key; |
| 35 | |
| 36 | static inline bool frontswap_enabled(void) |
| 37 | { |
| 38 | return static_branch_unlikely(&frontswap_enabled_key); |
| 39 | } |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 40 | |
| 41 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) |
| 42 | { |
Bob Liu | f066ea2 | 2013-04-30 15:26:53 -0700 | [diff] [blame] | 43 | return __frontswap_test(sis, offset); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static inline void frontswap_map_set(struct swap_info_struct *p, |
| 47 | unsigned long *map) |
| 48 | { |
| 49 | p->frontswap_map = map; |
| 50 | } |
| 51 | |
| 52 | static inline unsigned long *frontswap_map_get(struct swap_info_struct *p) |
| 53 | { |
| 54 | return p->frontswap_map; |
| 55 | } |
| 56 | #else |
| 57 | /* all inline routines become no-ops and all externs are ignored */ |
| 58 | |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 59 | static inline bool frontswap_enabled(void) |
| 60 | { |
| 61 | return false; |
| 62 | } |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 63 | |
| 64 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) |
| 65 | { |
| 66 | return false; |
| 67 | } |
| 68 | |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 69 | static inline void frontswap_map_set(struct swap_info_struct *p, |
| 70 | unsigned long *map) |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | static inline unsigned long *frontswap_map_get(struct swap_info_struct *p) |
| 75 | { |
| 76 | return NULL; |
| 77 | } |
| 78 | #endif |
| 79 | |
Konrad Rzeszutek Wilk | 165c8ae | 2012-05-15 11:32:15 -0400 | [diff] [blame] | 80 | static inline int frontswap_store(struct page *page) |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 81 | { |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 82 | if (frontswap_enabled()) |
| 83 | return __frontswap_store(page); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 84 | |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 85 | return -1; |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 86 | } |
| 87 | |
Konrad Rzeszutek Wilk | 165c8ae | 2012-05-15 11:32:15 -0400 | [diff] [blame] | 88 | static inline int frontswap_load(struct page *page) |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 89 | { |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 90 | if (frontswap_enabled()) |
| 91 | return __frontswap_load(page); |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 92 | |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 93 | return -1; |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset) |
| 97 | { |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 98 | if (frontswap_enabled()) |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 99 | __frontswap_invalidate_page(type, offset); |
| 100 | } |
| 101 | |
| 102 | static inline void frontswap_invalidate_area(unsigned type) |
| 103 | { |
Vlastimil Babka | 8ea1d2a | 2016-07-26 15:24:42 -0700 | [diff] [blame] | 104 | if (frontswap_enabled()) |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 105 | __frontswap_invalidate_area(type); |
| 106 | } |
| 107 | |
Minchan Kim | 4f89849 | 2013-04-30 15:26:54 -0700 | [diff] [blame] | 108 | static inline void frontswap_init(unsigned type, unsigned long *map) |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 109 | { |
Vlastimil Babka | 5e322be | 2016-11-10 10:46:07 -0800 | [diff] [blame] | 110 | #ifdef CONFIG_FRONTSWAP |
| 111 | __frontswap_init(type, map); |
| 112 | #endif |
Dan Magenheimer | c3ba969 | 2012-04-09 17:06:54 -0600 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | #endif /* _LINUX_FRONTSWAP_H */ |