14 #include <linux/mman.h>
18 #include <linux/module.h>
52 static bool frontswap_tmem_exclusive_gets_enabled
__read_mostly;
54 #ifdef CONFIG_DEBUG_FS
60 static u64 frontswap_loads;
61 static u64 frontswap_succ_stores;
62 static u64 frontswap_failed_stores;
63 static u64 frontswap_invalidates;
65 static inline void inc_frontswap_loads(
void) {
68 static inline void inc_frontswap_succ_stores(
void) {
69 frontswap_succ_stores++;
71 static inline void inc_frontswap_failed_stores(
void) {
72 frontswap_failed_stores++;
74 static inline void inc_frontswap_invalidates(
void) {
75 frontswap_invalidates++;
78 static inline void inc_frontswap_loads(
void) { }
79 static inline void inc_frontswap_succ_stores(
void) { }
80 static inline void inc_frontswap_failed_stores(
void) { }
81 static inline void inc_frontswap_invalidates(
void) { }
102 frontswap_writethrough_enabled =
enable;
111 frontswap_tmem_exclusive_gets_enabled =
enable;
123 if (sis->frontswap_map ==
NULL)
129 static inline void __frontswap_clear(
struct swap_info_struct *sis,
pgoff_t offset)
131 frontswap_clear(sis, offset);
144 int ret = -1, dup = 0;
146 int type = swp_type(entry);
150 BUG_ON(!PageLocked(page));
152 if (frontswap_test(sis, offset))
156 frontswap_set(sis, offset);
157 inc_frontswap_succ_stores();
165 inc_frontswap_failed_stores();
167 __frontswap_clear(sis, offset);
169 if (frontswap_writethrough_enabled)
185 int type = swp_type(entry);
189 BUG_ON(!PageLocked(page));
191 if (frontswap_test(sis, offset))
194 inc_frontswap_loads();
195 if (frontswap_tmem_exclusive_gets_enabled) {
197 frontswap_clear(sis, offset);
213 if (frontswap_test(sis, offset)) {
215 __frontswap_clear(sis, offset);
216 inc_frontswap_invalidates();
230 if (sis->frontswap_map ==
NULL)
234 memset(sis->frontswap_map, 0, sis->max /
sizeof(
long));
238 static unsigned long __frontswap_curr_pages(
void)
241 unsigned long totalpages = 0;
242 struct swap_info_struct *si =
NULL;
245 for (type =
swap_list.head; type >= 0; type = si->next) {
252 static int __frontswap_unuse_pages(
unsigned long total,
unsigned long *
unused,
256 struct swap_info_struct *si =
NULL;
257 int si_frontswap_pages;
258 unsigned long total_pages_to_unuse = total;
259 unsigned long pages = 0, pages_to_unuse = 0;
263 for (type =
swap_list.head; type >= 0; type = si->next) {
265 si_frontswap_pages =
atomic_read(&si->frontswap_pages);
266 if (total_pages_to_unuse < si_frontswap_pages) {
267 pages = pages_to_unuse = total_pages_to_unuse;
269 pages = si_frontswap_pages;
277 vm_unacct_memory(pages);
278 *unused = pages_to_unuse;
292 static int __frontswap_shrink(
unsigned long target_pages,
293 unsigned long *pages_to_unuse,
296 unsigned long total_pages = 0, total_pages_to_unuse;
300 total_pages = __frontswap_curr_pages();
301 if (total_pages <= target_pages) {
306 total_pages_to_unuse = total_pages - target_pages;
307 return __frontswap_unuse_pages(total_pages_to_unuse, pages_to_unuse, type);
320 unsigned long pages_to_unuse = 0;
329 ret = __frontswap_shrink(target_pages, &pages_to_unuse, &type);
344 unsigned long totalpages = 0;
347 totalpages = __frontswap_curr_pages();
354 static int __init init_frontswap(
void)
356 #ifdef CONFIG_DEBUG_FS
363 &frontswap_failed_stores);
365 root, &frontswap_invalidates);