diff options
author | Dan Magenheimer <dan.magenheimer@oracle.com> | 2012-04-09 19:06:54 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2012-05-15 11:33:46 -0400 |
commit | c3ba9698152b17fdc2c7cd0f7cbeb571e3367e9d (patch) | |
tree | b919ee68c3def31afd8aeba49390785d5c635c89 /include | |
parent | 0034102808e0dbbf3a2394b82b1bb40b5778de9e (diff) |
mm: frontswap: add frontswap header file
Frontswap is the alter ego of cleancache, the "yang" to cleancache's
"yin"... and more precisely frontswap is the provider of anonymous
pages to transcendent memory to nicely complement cleancache's providing
of clean pagecache pages to transcendent memory. For optimal use
of transcendent memory, both are necessary... because a kernel
under memory pressure first reclaims clean pagecache pages and,
when under more memory pressure, starts swapping anonymous pages.
Frontswap and cleancache (which was merged at 3.0) are the "frontends"
and the only necessary changes to the core kernel for transcendent memory;
all other supporting code -- the "backends" -- is implemented as drivers.
See the LWN.net article "Transcendent memory in a nutshell" for a detailed
overview of frontswap and related kernel parts:
https://lwn.net/Articles/454795/
Frontswap code was first posted publicly in January 2009 and on LKML in
May 2009, and has remained functionally stable for nearly three years now.
It is barely invasive, touching only the swap subsystem and adds less
than 100 lines of code to existing swap subsystem code files.
It has improved syntactically substantially between V1 and this posting
of V14, thanks to the review of a few kernel developers, and has adapted
easily to at least one major swap subsystem change. As of 3.4, there are
three in-tree users of frontswap patiently waiting for this patchset and
for CONFIG_FRONTSWAP to be enabled: zcache (staging driver merged at
2.6.39), Xen tmem (merged at 3.0 and 3.1) and RAMster (staging driver
merged at 3.4). In addition, a RFC has been posted for a KVM backend.
The frontswap patchset has been in linux-next since next-110603. Earlier
versions of frontswap already ship in the Oracle Unbreakable Enterprise Kernel
and SuSE SLES.
This patch, 1of4, provides the header file for the core code for frontswap
that interfaces between the hooks in the swap subsystem and a frontswap
backend via frontswap_ops.
---
New file added: include/linux/frontswap.h
[v14: add support for writethrough, per suggestion by aarcange@redhat.com]
[v14: rebase to 3.4-rc2]
[v11: konrad.wilk@oracle.com: squashed s/flush/invalidate/ in]
[v10: no change]
[v9: akpm@linux-foundation.org: change "flush" to "invalidate", part 1]
[v8: rebase to 3.0-rc4]
[v7: rebase to 3.0-rc3]
[v7: JBeulich@novell.com: new static inlines resolve to no-ops if not config'd]
[v7: JBeulich@novell.com: avoid redundant shifts/divides for *_bit lib calls]
[v6: rebase to 3.1-rc1]
[v5: no change from v4]
[v4: rebase to 2.6.39]
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Jan Beulich <JBeulich@novell.com>
Acked-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Matthew Wilcox <matthew@wil.cx>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Rik Riel <riel@redhat.com>
[v15: int/bool on some functions]
Signed-off-by: Konrad Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/frontswap.h | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h new file mode 100644 index 000000000000..68ff7af5c5fb --- /dev/null +++ b/include/linux/frontswap.h | |||
@@ -0,0 +1,127 @@ | |||
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 */ | ||