]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
c3ba9698 DM |
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> | |
8ea1d2a1 | 8 | #include <linux/jump_label.h> |
c3ba9698 | 9 | |
b56a2d8a VRP |
10 | /* |
11 | * Return code to denote that requested number of | |
12 | * frontswap pages are unused(moved to page cache). | |
c82f16b5 | 13 | * Used in shmem_unuse and try_to_unuse. |
b56a2d8a VRP |
14 | */ |
15 | #define FRONTSWAP_PAGES_UNUSED 2 | |
16 | ||
c3ba9698 | 17 | struct frontswap_ops { |
d1dc6f1b DS |
18 | void (*init)(unsigned); /* this swap type was just swapon'ed */ |
19 | int (*store)(unsigned, pgoff_t, struct page *); /* store a page */ | |
20 | int (*load)(unsigned, pgoff_t, struct page *); /* load a page */ | |
21 | void (*invalidate_page)(unsigned, pgoff_t); /* page no longer needed */ | |
22 | void (*invalidate_area)(unsigned); /* swap type just swapoff'ed */ | |
23 | struct frontswap_ops *next; /* private pointer to next ops */ | |
c3ba9698 DM |
24 | }; |
25 | ||
d1dc6f1b | 26 | extern void frontswap_register_ops(struct frontswap_ops *ops); |
c3ba9698 DM |
27 | extern void frontswap_shrink(unsigned long); |
28 | extern unsigned long frontswap_curr_pages(void); | |
29 | extern void frontswap_writethrough(bool); | |
e3483a5f DM |
30 | #define FRONTSWAP_HAS_EXCLUSIVE_GETS |
31 | extern void frontswap_tmem_exclusive_gets(bool); | |
c3ba9698 | 32 | |
f066ea23 | 33 | extern bool __frontswap_test(struct swap_info_struct *, pgoff_t); |
4f89849d | 34 | extern void __frontswap_init(unsigned type, unsigned long *map); |
165c8aed KRW |
35 | extern int __frontswap_store(struct page *page); |
36 | extern int __frontswap_load(struct page *page); | |
c3ba9698 DM |
37 | extern void __frontswap_invalidate_page(unsigned, pgoff_t); |
38 | extern void __frontswap_invalidate_area(unsigned); | |
39 | ||
40 | #ifdef CONFIG_FRONTSWAP | |
8ea1d2a1 VB |
41 | extern struct static_key_false frontswap_enabled_key; |
42 | ||
43 | static inline bool frontswap_enabled(void) | |
44 | { | |
45 | return static_branch_unlikely(&frontswap_enabled_key); | |
46 | } | |
c3ba9698 DM |
47 | |
48 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) | |
49 | { | |
f066ea23 | 50 | return __frontswap_test(sis, offset); |
c3ba9698 DM |
51 | } |
52 | ||
53 | static inline void frontswap_map_set(struct swap_info_struct *p, | |
54 | unsigned long *map) | |
55 | { | |
56 | p->frontswap_map = map; | |
57 | } | |
58 | ||
59 | static inline unsigned long *frontswap_map_get(struct swap_info_struct *p) | |
60 | { | |
61 | return p->frontswap_map; | |
62 | } | |
63 | #else | |
64 | /* all inline routines become no-ops and all externs are ignored */ | |
65 | ||
8ea1d2a1 VB |
66 | static inline bool frontswap_enabled(void) |
67 | { | |
68 | return false; | |
69 | } | |
c3ba9698 DM |
70 | |
71 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) | |
72 | { | |
73 | return false; | |
74 | } | |
75 | ||
c3ba9698 DM |
76 | static inline void frontswap_map_set(struct swap_info_struct *p, |
77 | unsigned long *map) | |
78 | { | |
79 | } | |
80 | ||
81 | static inline unsigned long *frontswap_map_get(struct swap_info_struct *p) | |
82 | { | |
83 | return NULL; | |
84 | } | |
85 | #endif | |
86 | ||
165c8aed | 87 | static inline int frontswap_store(struct page *page) |
c3ba9698 | 88 | { |
8ea1d2a1 VB |
89 | if (frontswap_enabled()) |
90 | return __frontswap_store(page); | |
c3ba9698 | 91 | |
8ea1d2a1 | 92 | return -1; |
c3ba9698 DM |
93 | } |
94 | ||
165c8aed | 95 | static inline int frontswap_load(struct page *page) |
c3ba9698 | 96 | { |
8ea1d2a1 VB |
97 | if (frontswap_enabled()) |
98 | return __frontswap_load(page); | |
c3ba9698 | 99 | |
8ea1d2a1 | 100 | return -1; |
c3ba9698 DM |
101 | } |
102 | ||
103 | static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset) | |
104 | { | |
8ea1d2a1 | 105 | if (frontswap_enabled()) |
c3ba9698 DM |
106 | __frontswap_invalidate_page(type, offset); |
107 | } | |
108 | ||
109 | static inline void frontswap_invalidate_area(unsigned type) | |
110 | { | |
8ea1d2a1 | 111 | if (frontswap_enabled()) |
c3ba9698 DM |
112 | __frontswap_invalidate_area(type); |
113 | } | |
114 | ||
4f89849d | 115 | static inline void frontswap_init(unsigned type, unsigned long *map) |
c3ba9698 | 116 | { |
5e322bee VB |
117 | #ifdef CONFIG_FRONTSWAP |
118 | __frontswap_init(type, map); | |
119 | #endif | |
c3ba9698 DM |
120 | } |
121 | ||
122 | #endif /* _LINUX_FRONTSWAP_H */ |