blob: 011965c08b939206fadc0081b3c0c7acc3e065ce [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Dan Magenheimerc3ba9692012-04-09 17:06:54 -06002#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 Babka8ea1d2a2016-07-26 15:24:42 -07008#include <linux/jump_label.h>
Dan Magenheimerc3ba9692012-04-09 17:06:54 -06009
10struct frontswap_ops {
Dan Streetmand1dc6f12015-06-24 16:58:18 -070011 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 Magenheimerc3ba9692012-04-09 17:06:54 -060017};
18
Dan Streetmand1dc6f12015-06-24 16:58:18 -070019extern void frontswap_register_ops(struct frontswap_ops *ops);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060020extern void frontswap_shrink(unsigned long);
21extern unsigned long frontswap_curr_pages(void);
22extern void frontswap_writethrough(bool);
Dan Magenheimere3483a52012-09-20 12:16:52 -070023#define FRONTSWAP_HAS_EXCLUSIVE_GETS
24extern void frontswap_tmem_exclusive_gets(bool);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060025
Bob Liuf066ea22013-04-30 15:26:53 -070026extern bool __frontswap_test(struct swap_info_struct *, pgoff_t);
Minchan Kim4f898492013-04-30 15:26:54 -070027extern void __frontswap_init(unsigned type, unsigned long *map);
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040028extern int __frontswap_store(struct page *page);
29extern int __frontswap_load(struct page *page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060030extern void __frontswap_invalidate_page(unsigned, pgoff_t);
31extern void __frontswap_invalidate_area(unsigned);
32
33#ifdef CONFIG_FRONTSWAP
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070034extern struct static_key_false frontswap_enabled_key;
35
36static inline bool frontswap_enabled(void)
37{
38 return static_branch_unlikely(&frontswap_enabled_key);
39}
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060040
41static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
42{
Bob Liuf066ea22013-04-30 15:26:53 -070043 return __frontswap_test(sis, offset);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060044}
45
46static inline void frontswap_map_set(struct swap_info_struct *p,
47 unsigned long *map)
48{
49 p->frontswap_map = map;
50}
51
52static 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 Babka8ea1d2a2016-07-26 15:24:42 -070059static inline bool frontswap_enabled(void)
60{
61 return false;
62}
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060063
64static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
65{
66 return false;
67}
68
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060069static inline void frontswap_map_set(struct swap_info_struct *p,
70 unsigned long *map)
71{
72}
73
74static inline unsigned long *frontswap_map_get(struct swap_info_struct *p)
75{
76 return NULL;
77}
78#endif
79
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040080static inline int frontswap_store(struct page *page)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060081{
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070082 if (frontswap_enabled())
83 return __frontswap_store(page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060084
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070085 return -1;
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060086}
87
Konrad Rzeszutek Wilk165c8ae2012-05-15 11:32:15 -040088static inline int frontswap_load(struct page *page)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060089{
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070090 if (frontswap_enabled())
91 return __frontswap_load(page);
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060092
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070093 return -1;
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060094}
95
96static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset)
97{
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -070098 if (frontswap_enabled())
Dan Magenheimerc3ba9692012-04-09 17:06:54 -060099 __frontswap_invalidate_page(type, offset);
100}
101
102static inline void frontswap_invalidate_area(unsigned type)
103{
Vlastimil Babka8ea1d2a2016-07-26 15:24:42 -0700104 if (frontswap_enabled())
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600105 __frontswap_invalidate_area(type);
106}
107
Minchan Kim4f898492013-04-30 15:26:54 -0700108static inline void frontswap_init(unsigned type, unsigned long *map)
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600109{
Vlastimil Babka5e322be2016-11-10 10:46:07 -0800110#ifdef CONFIG_FRONTSWAP
111 __frontswap_init(type, map);
112#endif
Dan Magenheimerc3ba9692012-04-09 17:06:54 -0600113}
114
115#endif /* _LINUX_FRONTSWAP_H */