15 #include <linux/module.h>
18 #include <linux/list.h>
19 #include <linux/slab.h>
21 #include <linux/types.h>
35 #define ramster_enabled 0
38 #ifndef __PG_WAS_ACTIVE
39 static inline bool PageWasActive(
struct page *
page)
44 static inline void SetPageWasActive(
struct page *
page)
49 #ifdef FRONTSWAP_HAS_EXCLUSIVE_GETS
50 static bool frontswap_has_exclusive_gets
__read_mostly =
true;
53 static inline void frontswap_tmem_exclusive_gets(
bool b)
65 #define ZCACHE_GFP_MASK \
66 (__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC)
71 #define ZCACHE_COMP_NAME_SZ CRYPTO_MAX_ALG_NAME
80 static inline int zcache_comp_op(
enum comp_op op,
81 const u8 *
src,
unsigned int slen,
87 BUG_ON(!zcache_comp_pcpu_tfms);
92 ret = crypto_comp_compress(tfm, src, slen, dst, dlen);
95 ret = crypto_comp_decompress(tfm, src, slen, dst, dlen);
125 static struct kmem_cache *zcache_objnode_cache;
131 static long zcache_obj_count;
133 static long zcache_obj_count_max;
134 static long zcache_objnode_count;
136 static long zcache_objnode_count_max;
137 static u64 zcache_eph_zbytes;
139 static u64 zcache_eph_zbytes_max;
140 static u64 zcache_pers_zbytes;
142 static u64 zcache_pers_zbytes_max;
143 static long zcache_eph_pageframes;
145 static long zcache_eph_pageframes_max;
146 static long zcache_pers_pageframes;
148 static long zcache_pers_pageframes_max;
149 static long zcache_pageframes_alloced;
151 static long zcache_pageframes_freed;
153 static long zcache_eph_zpages;
155 static long zcache_eph_zpages_max;
156 static long zcache_pers_zpages;
158 static long zcache_pers_zpages_max;
161 static unsigned long zcache_flush_total;
162 static unsigned long zcache_flush_found;
163 static unsigned long zcache_flobj_total;
164 static unsigned long zcache_flobj_found;
165 static unsigned long zcache_failed_eph_puts;
166 static unsigned long zcache_failed_pers_puts;
167 static unsigned long zcache_failed_getfreepages;
168 static unsigned long zcache_failed_alloc;
169 static unsigned long zcache_put_to_flush;
170 static unsigned long zcache_compress_poor;
171 static unsigned long zcache_mean_compress_poor;
172 static unsigned long zcache_eph_ate_tail;
173 static unsigned long zcache_eph_ate_tail_failed;
174 static unsigned long zcache_pers_ate_eph;
175 static unsigned long zcache_pers_ate_eph_failed;
176 static unsigned long zcache_evicted_eph_zpages;
177 static unsigned long zcache_evicted_eph_pageframes;
178 static unsigned long zcache_last_active_file_pageframes;
179 static unsigned long zcache_last_inactive_file_pageframes;
180 static unsigned long zcache_last_active_anon_pageframes;
181 static unsigned long zcache_last_inactive_anon_pageframes;
182 static unsigned long zcache_eph_nonactive_puts_ignored;
183 static unsigned long zcache_pers_nonactive_puts_ignored;
185 #ifdef CONFIG_DEBUG_FS
187 #define zdfs debugfs_create_size_t
188 #define zdfs64 debugfs_create_u64
189 static int zcache_debugfs_init(
void)
195 zdfs(
"obj_count",
S_IRUGO, root, &zcache_obj_count);
196 zdfs(
"obj_count_max",
S_IRUGO, root, &zcache_obj_count_max);
197 zdfs(
"objnode_count",
S_IRUGO, root, &zcache_objnode_count);
198 zdfs(
"objnode_count_max",
S_IRUGO, root, &zcache_objnode_count_max);
199 zdfs(
"flush_total",
S_IRUGO, root, &zcache_flush_total);
200 zdfs(
"flush_found",
S_IRUGO, root, &zcache_flush_found);
201 zdfs(
"flobj_total",
S_IRUGO, root, &zcache_flobj_total);
202 zdfs(
"flobj_found",
S_IRUGO, root, &zcache_flobj_found);
203 zdfs(
"failed_eph_puts",
S_IRUGO, root, &zcache_failed_eph_puts);
204 zdfs(
"failed_pers_puts",
S_IRUGO, root, &zcache_failed_pers_puts);
205 zdfs(
"failed_get_free_pages",
S_IRUGO, root,
206 &zcache_failed_getfreepages);
207 zdfs(
"failed_alloc",
S_IRUGO, root, &zcache_failed_alloc);
208 zdfs(
"put_to_flush",
S_IRUGO, root, &zcache_put_to_flush);
209 zdfs(
"compress_poor",
S_IRUGO, root, &zcache_compress_poor);
210 zdfs(
"mean_compress_poor",
S_IRUGO, root, &zcache_mean_compress_poor);
211 zdfs(
"eph_ate_tail",
S_IRUGO, root, &zcache_eph_ate_tail);
212 zdfs(
"eph_ate_tail_failed",
S_IRUGO, root, &zcache_eph_ate_tail_failed);
213 zdfs(
"pers_ate_eph",
S_IRUGO, root, &zcache_pers_ate_eph);
214 zdfs(
"pers_ate_eph_failed",
S_IRUGO, root, &zcache_pers_ate_eph_failed);
215 zdfs(
"evicted_eph_zpages",
S_IRUGO, root, &zcache_evicted_eph_zpages);
216 zdfs(
"evicted_eph_pageframes",
S_IRUGO, root,
217 &zcache_evicted_eph_pageframes);
218 zdfs(
"eph_pageframes",
S_IRUGO, root, &zcache_eph_pageframes);
219 zdfs(
"eph_pageframes_max",
S_IRUGO, root, &zcache_eph_pageframes_max);
220 zdfs(
"pers_pageframes",
S_IRUGO, root, &zcache_pers_pageframes);
221 zdfs(
"pers_pageframes_max",
S_IRUGO, root, &zcache_pers_pageframes_max);
222 zdfs(
"eph_zpages",
S_IRUGO, root, &zcache_eph_zpages);
223 zdfs(
"eph_zpages_max",
S_IRUGO, root, &zcache_eph_zpages_max);
224 zdfs(
"pers_zpages",
S_IRUGO, root, &zcache_pers_zpages);
225 zdfs(
"pers_zpages_max",
S_IRUGO, root, &zcache_pers_zpages_max);
226 zdfs(
"last_active_file_pageframes",
S_IRUGO, root,
227 &zcache_last_active_file_pageframes);
228 zdfs(
"last_inactive_file_pageframes",
S_IRUGO, root,
229 &zcache_last_inactive_file_pageframes);
230 zdfs(
"last_active_anon_pageframes",
S_IRUGO, root,
231 &zcache_last_active_anon_pageframes);
232 zdfs(
"last_inactive_anon_pageframes",
S_IRUGO, root,
233 &zcache_last_inactive_anon_pageframes);
234 zdfs(
"eph_nonactive_puts_ignored",
S_IRUGO, root,
235 &zcache_eph_nonactive_puts_ignored);
236 zdfs(
"pers_nonactive_puts_ignored",
S_IRUGO, root,
237 &zcache_pers_nonactive_puts_ignored);
238 zdfs64(
"eph_zbytes",
S_IRUGO, root, &zcache_eph_zbytes);
239 zdfs64(
"eph_zbytes_max",
S_IRUGO, root, &zcache_eph_zbytes_max);
240 zdfs64(
"pers_zbytes",
S_IRUGO, root, &zcache_pers_zbytes);
241 zdfs64(
"pers_zbytes_max",
S_IRUGO, root, &zcache_pers_zbytes_max);
253 pr_info(
"zcache: obj_count=%lu\n", zcache_obj_count);
254 pr_info(
"zcache: obj_count_max=%lu\n", zcache_obj_count_max);
255 pr_info(
"zcache: objnode_count=%lu\n", zcache_objnode_count);
256 pr_info(
"zcache: objnode_count_max=%lu\n", zcache_objnode_count_max);
257 pr_info(
"zcache: flush_total=%lu\n", zcache_flush_total);
258 pr_info(
"zcache: flush_found=%lu\n", zcache_flush_found);
259 pr_info(
"zcache: flobj_total=%lu\n", zcache_flobj_total);
260 pr_info(
"zcache: flobj_found=%lu\n", zcache_flobj_found);
261 pr_info(
"zcache: failed_eph_puts=%lu\n", zcache_failed_eph_puts);
262 pr_info(
"zcache: failed_pers_puts=%lu\n", zcache_failed_pers_puts);
263 pr_info(
"zcache: failed_get_free_pages=%lu\n",
264 zcache_failed_getfreepages);
265 pr_info(
"zcache: failed_alloc=%lu\n", zcache_failed_alloc);
266 pr_info(
"zcache: put_to_flush=%lu\n", zcache_put_to_flush);
267 pr_info(
"zcache: compress_poor=%lu\n", zcache_compress_poor);
268 pr_info(
"zcache: mean_compress_poor=%lu\n",
269 zcache_mean_compress_poor);
270 pr_info(
"zcache: eph_ate_tail=%lu\n", zcache_eph_ate_tail);
271 pr_info(
"zcache: eph_ate_tail_failed=%lu\n",
272 zcache_eph_ate_tail_failed);
273 pr_info(
"zcache: pers_ate_eph=%lu\n", zcache_pers_ate_eph);
274 pr_info(
"zcache: pers_ate_eph_failed=%lu\n",
275 zcache_pers_ate_eph_failed);
276 pr_info(
"zcache: evicted_eph_zpages=%lu\n", zcache_evicted_eph_zpages);
277 pr_info(
"zcache: evicted_eph_pageframes=%lu\n",
278 zcache_evicted_eph_pageframes);
279 pr_info(
"zcache: eph_pageframes=%lu\n", zcache_eph_pageframes);
280 pr_info(
"zcache: eph_pageframes_max=%lu\n", zcache_eph_pageframes_max);
281 pr_info(
"zcache: pers_pageframes=%lu\n", zcache_pers_pageframes);
282 pr_info(
"zcache: pers_pageframes_max=%lu\n",
283 zcache_pers_pageframes_max);
284 pr_info(
"zcache: eph_zpages=%lu\n", zcache_eph_zpages);
285 pr_info(
"zcache: eph_zpages_max=%lu\n", zcache_eph_zpages_max);
286 pr_info(
"zcache: pers_zpages=%lu\n", zcache_pers_zpages);
287 pr_info(
"zcache: pers_zpages_max=%lu\n", zcache_pers_zpages_max);
288 pr_info(
"zcache: eph_zbytes=%llu\n",
289 (
unsigned long long)zcache_eph_zbytes);
290 pr_info(
"zcache: eph_zbytes_max=%llu\n",
291 (
unsigned long long)zcache_eph_zbytes_max);
292 pr_info(
"zcache: pers_zbytes=%llu\n",
293 (
unsigned long long)zcache_pers_zbytes);
294 pr_info(
"zcache: pers_zbytes_max=%llu\n",
295 (
unsigned long long)zcache_pers_zbytes_max);
306 static inline bool is_local_client(
struct zcache_client *cli)
308 return cli == &zcache_host;
318 cli = &zcache_clients[cli_id];
336 cli = zcache_get_client_by_id(cli_id);
339 if (!is_local_client(cli))
358 if (!is_local_client(cli))
367 cli = zcache_get_client_by_id(cli_id);
391 if (objnode !=
NULL) {
398 if (zcache_objnode_count > zcache_objnode_count_max)
399 zcache_objnode_count_max = zcache_objnode_count;
403 static void zcache_objnode_free(
struct tmem_objnode *objnode,
406 zcache_objnode_count =
408 BUG_ON(zcache_objnode_count < 0);
422 if (zcache_obj_count > zcache_obj_count_max)
423 zcache_obj_count_max = zcache_obj_count;
431 BUG_ON(zcache_obj_count < 0);
436 .obj_alloc = zcache_obj_alloc,
437 .obj_free = zcache_obj_free,
438 .objnode_alloc = zcache_objnode_alloc,
439 .objnode_free = zcache_objnode_free,
442 static struct page *zcache_alloc_page(
void)
447 zcache_pageframes_alloced =
452 #ifdef FRONTSWAP_HAS_UNUSE
453 static void zcache_unacct_page(
void)
455 zcache_pageframes_freed =
460 static void zcache_free_page(
struct page *page)
462 long curr_pageframes;
463 static long max_pageframes, min_pageframes;
468 zcache_pageframes_freed =
470 curr_pageframes = zcache_pageframes_alloced -
474 if (curr_pageframes > max_pageframes)
475 max_pageframes = curr_pageframes;
476 if (curr_pageframes < min_pageframes)
477 min_pageframes = curr_pageframes;
479 if (curr_pageframes > 2L || curr_pageframes < -2L) {
490 static void zcache_compress(
struct page *
from,
491 void **out_va,
unsigned *
out_len);
493 static struct page *zcache_evict_eph_pageframe(
void);
495 static void *zcache_pampd_eph_create(
char *
data,
size_t size,
bool raw,
500 struct page *page = (
struct page *)(data), *newpage;
503 zcache_compress(page, &cdata, &clen);
505 zcache_compress_poor++;
518 newpage = zcache_alloc_page();
520 goto create_in_new_page;
522 zcache_failed_getfreepages++;
524 newpage = zcache_evict_eph_pageframe();
525 if (newpage ==
NULL) {
526 zcache_eph_ate_tail_failed++;
529 zcache_eph_ate_tail++;
534 zcache_eph_pageframes =
536 if (zcache_eph_pageframes > zcache_eph_pageframes_max)
537 zcache_eph_pageframes_max = zcache_eph_pageframes;
541 atomic_long_add_return(clen, &zcache_eph_zbytes_atomic);
542 if (zcache_eph_zbytes > zcache_eph_zbytes_max)
543 zcache_eph_zbytes_max = zcache_eph_zbytes;
545 if (zcache_eph_zpages > zcache_eph_zpages_max)
546 zcache_eph_zpages_max = zcache_eph_zpages;
553 static void *zcache_pampd_pers_create(
char *data,
size_t size,
bool raw,
557 unsigned clen =
size;
558 struct page *page = (
struct page *)(data), *newpage;
559 unsigned long zbud_mean_zsize;
560 unsigned long curr_pers_zpages, total_zsize;
566 curr_pers_zpages = zcache_pers_zpages;
569 zcache_compress(page, &cdata, &clen);
571 if (clen > zbud_max_zsize) {
572 zcache_compress_poor++;
576 if ((clen > zbud_max_mean_zsize) && (curr_pers_zpages > 0)) {
577 total_zsize = zcache_pers_zbytes;
578 if ((
long)total_zsize < 0)
580 zbud_mean_zsize = div_u64(total_zsize,
582 if (zbud_mean_zsize > zbud_max_mean_zsize) {
583 zcache_mean_compress_poor++;
595 newpage = zcache_alloc_page();
597 goto create_in_new_page;
604 zcache_failed_getfreepages++;
606 newpage = zcache_evict_eph_pageframe();
607 if (newpage ==
NULL) {
608 zcache_pers_ate_eph_failed++;
611 zcache_pers_ate_eph++;
616 zcache_pers_pageframes =
618 if (zcache_pers_pageframes > zcache_pers_pageframes_max)
619 zcache_pers_pageframes_max = zcache_pers_pageframes;
623 if (zcache_pers_zpages > zcache_pers_zpages_max)
624 zcache_pers_zpages_max = zcache_pers_zpages;
626 atomic_long_add_return(clen, &zcache_pers_zbytes_atomic);
627 if (zcache_pers_zbytes > zcache_pers_zbytes_max)
628 zcache_pers_zbytes_max = zcache_pers_zbytes;
655 if (objnode ==
NULL) {
659 zcache_failed_alloc++;
670 zcache_failed_alloc++;
679 pampd = zcache_pampd_eph_create(data, size, raw, th);
681 pampd = zcache_pampd_pers_create(data, size, raw, th);
701 static void zcache_decompress(
char *from_va,
unsigned int size,
char *to_va)
716 struct page *to_page)
719 zcache_decompress(from_va, size, to_va);
727 static int zcache_pampd_get_data(
char *data,
size_t *sizep,
bool raw,
736 BUG_ON(pampd_is_remote(pampd));
742 (
struct zbudref *)pampd,
false,
753 static int zcache_pampd_get_data_and_free(
char *data,
size_t *sizep,
bool raw,
759 struct page *page =
NULL;
760 unsigned int zsize, zpages;
763 BUG_ON(pampd_is_remote(pampd));
777 zcache_eph_pageframes =
782 atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic);
785 zcache_pers_pageframes =
790 atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic);
792 if (!is_local_client(pool->
client))
795 zcache_free_page(page);
803 static void zcache_pampd_free(
void *pampd,
struct tmem_pool *pool,
806 struct page *page =
NULL;
807 unsigned int zsize, zpages;
810 if (pampd_is_remote(pampd)) {
818 true, &zsize, &zpages);
820 zcache_eph_pageframes =
825 atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic);
829 false, &zsize, &zpages);
831 zcache_pers_pageframes =
836 atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic);
838 if (!is_local_client(pool->
client))
841 zcache_free_page(page);
846 .get_data = zcache_pampd_get_data,
847 .get_data_and_free = zcache_pampd_get_data_and_free,
848 .free = zcache_pampd_free,
856 #define ZCACHE_DSTMEM_ORDER 1
858 static void zcache_compress(
struct page *
from,
void **out_va,
unsigned *
out_len)
877 static int zcache_comp_cpu_up(
int cpu)
881 tfm = crypto_alloc_comp(zcache_comp_name, 0, 0);
888 static void zcache_comp_cpu_down(
int cpu)
893 crypto_free_comp(tfm);
905 ret = zcache_comp_cpu_up(cpu);
906 if (ret != NOTIFY_OK) {
907 pr_err(
"%s: can't allocate compressor xform\n",
918 zcache_comp_cpu_down(cpu);
922 kp = &
per_cpu(zcache_preloads, cpu);
942 .notifier_call = zcache_cpu_notifier
950 static struct page *zcache_evict_eph_pageframe(
void)
953 unsigned int zsize = 0, zpages = 0;
958 zcache_eph_zbytes = atomic_long_sub_return(zsize,
959 &zcache_eph_zbytes_atomic);
961 &zcache_eph_zpages_atomic);
962 zcache_evicted_eph_zpages++;
963 zcache_eph_pageframes =
965 zcache_evicted_eph_pageframes++;
970 #ifdef FRONTSWAP_HAS_UNUSE
981 static int zcache_frontswap_unuse(
void)
985 int nzbuds, unuse_ret;
987 struct page *newpage1 =
NULL, *newpage2 =
NULL;
988 struct page *evictpage1 =
NULL, *evictpage2 =
NULL;
993 if (newpage1 ==
NULL)
994 evictpage1 = zcache_evict_eph_pageframe();
995 if (newpage2 ==
NULL)
996 evictpage2 = zcache_evict_eph_pageframe();
997 if (evictpage1 ==
NULL || evictpage2 ==
NULL)
1005 unswiz(th[0].oid, th[0].index, &type, &offset);
1006 unuse_ret = frontswap_unuse(type, offset,
1007 newpage1 !=
NULL ? newpage1 : evictpage1,
1011 else if (evictpage1 !=
NULL)
1012 zcache_unacct_page();
1016 unswiz(th[1].oid, th[1].index, &type, &offset);
1017 unuse_ret = frontswap_unuse(type, offset,
1018 newpage2 !=
NULL ? newpage2 : evictpage2,
1020 if (unuse_ret != 0) {
1022 }
else if (evictpage2 !=
NULL) {
1023 zcache_unacct_page();
1030 if (newpage1 !=
NULL)
1032 if (newpage2 !=
NULL)
1034 if (evictpage1 !=
NULL)
1035 zcache_free_page(evictpage1);
1036 if (evictpage2 !=
NULL)
1037 zcache_free_page(evictpage2);
1050 static bool zcache_freeze;
1060 static bool in_progress;
1066 #ifdef FRONTSWAP_HAS_UNUSE
1080 zcache_last_active_file_pageframes =
1082 zcache_last_inactive_file_pageframes =
1084 nr_evict = zcache_eph_pageframes - zcache_last_active_file_pageframes +
1085 zcache_last_inactive_file_pageframes;
1086 while (nr_evict-- > 0) {
1087 page = zcache_evict_eph_pageframe();
1090 zcache_free_page(page);
1093 zcache_last_active_anon_pageframes =
1095 zcache_last_inactive_anon_pageframes =
1097 nr_unuse = zcache_pers_pageframes - zcache_last_active_anon_pageframes +
1098 zcache_last_inactive_anon_pageframes;
1099 #ifdef FRONTSWAP_HAS_UNUSE
1103 while (nr_unuse-- > 0) {
1104 unuse_ret = zcache_frontswap_unuse();
1105 if (unuse_ret == -
ENOMEM)
1109 in_progress =
false;
1113 zcache_last_active_file_pageframes =
1115 zcache_last_inactive_file_pageframes =
1117 ret = zcache_eph_pageframes - zcache_last_active_file_pageframes +
1118 zcache_last_inactive_file_pageframes;
1124 static struct shrinker zcache_shrinker = {
1125 .shrink = shrink_zcache_memory,
1136 unsigned int size,
bool raw,
int ephemeral)
1147 if (!zcache_freeze) {
1155 if (pampd ==
NULL) {
1158 zcache_failed_eph_puts++;
1160 zcache_failed_pers_puts++;
1164 ret =
tmem_put(pool, oidp, index, 0, pampd);
1170 zcache_put_to_flush++;
1184 size_t *sizep,
bool raw,
int get_and_free)
1198 ret =
tmem_get(pool, oidp, index, (
char *)(page),
1199 sizep, raw, get_and_free);
1203 "zcache_get fails on persistent pool, "
1204 "bad things are very likely to happen soon\n");
1205 #ifdef RAMSTER_TESTING
1207 pr_err(
"TESTING zcache_get tmem_get returns ret=%d\n", ret);
1217 unsigned long flags;
1220 zcache_flush_total++;
1230 zcache_flush_found++;
1240 unsigned long flags;
1243 zcache_flobj_total++;
1253 zcache_flobj_found++;
1258 static int zcache_client_destroy_pool(
int cli_id,
int pool_id)
1269 cli = &zcache_clients[cli_id];
1286 pr_info(
"%s: destroyed local pool id=%d\n", namestr, pool_id);
1288 pr_info(
"%s: destroyed pool id=%d, client=%d\n",
1289 namestr, pool_id, cli_id);
1303 cli = &zcache_clients[cli_id];
1309 pr_info(
"%s: pool creation failed: out of memory\n", namestr);
1316 if (poolid >= MAX_POOLS_PER_CLIENT) {
1317 pr_info(
"%s: pool creation failed: max exceeded\n", namestr);
1328 pr_info(
"%s: created %s local tmem pool, id=%d\n", namestr,
1332 pr_info(
"%s: created %s tmem pool, id=%d, client=%d\n", namestr,
1333 flags & TMEM_POOL_PERSIST ?
"persistent" :
"ephemeral",
1361 cli = &zcache_clients[cli_id];
1362 if ((eph && disable_cleancache) || (!eph && disable_frontswap)) {
1363 pr_err(
"zcache_autocreate_pool: pool type disabled\n");
1368 pr_err(
"zcache_autocreate_pool: can't create client\n");
1371 cli = &zcache_clients[cli_id];
1377 pr_err(
"zcache_autocreate_pool: type mismatch\n");
1385 pr_info(
"%s: pool creation failed: out of memory\n", namestr);
1393 pr_info(
"%s: AUTOcreated %s tmem poolid=%d, for remote client=%d\n",
1411 static void zcache_cleancache_put_page(
int pool_id,
1413 pgoff_t index,
struct page *page)
1418 if (!disable_cleancache_ignore_nonactive && !PageWasActive(page)) {
1419 zcache_eph_nonactive_puts_ignored++;
1422 if (
likely(ind == index))
1427 static int zcache_cleancache_get_page(
int pool_id,
1429 pgoff_t index,
struct page *page)
1436 if (
likely(ind == index)) {
1438 page, &size,
false, 0);
1441 SetPageWasActive(page);
1446 static void zcache_cleancache_flush_page(
int pool_id,
1453 if (
likely(ind == index))
1457 static void zcache_cleancache_flush_inode(
int pool_id,
1465 static void zcache_cleancache_flush_fs(
int pool_id)
1471 static int zcache_cleancache_init_fs(
size_t pagesize)
1476 return zcache_local_new_pool(0);
1479 static int zcache_cleancache_init_shared_fs(
char *
uuid,
size_t pagesize)
1485 return zcache_local_new_pool(0);
1489 .put_page = zcache_cleancache_put_page,
1490 .get_page = zcache_cleancache_get_page,
1491 .invalidate_page = zcache_cleancache_flush_page,
1492 .invalidate_inode = zcache_cleancache_flush_inode,
1493 .invalidate_fs = zcache_cleancache_flush_fs,
1494 .init_shared_fs = zcache_cleancache_init_shared_fs,
1495 .init_fs = zcache_cleancache_init_fs
1516 #define SWIZ_MASK ((1 << SWIZ_BITS) - 1)
1517 #define _oswiz(_type, _ind) ((_type << SWIZ_BITS) | (_ind & SWIZ_MASK))
1518 #define iswiz(_ind) (_ind >> SWIZ_BITS)
1520 static inline struct tmem_oid oswiz(unsigned type,
u32 ind)
1527 #ifdef FRONTSWAP_HAS_UNUSE
1528 static void unswiz(
struct tmem_oid oid,
u32 index,
1529 unsigned *type,
pgoff_t *offset)
1537 static int zcache_frontswap_put_page(
unsigned type,
pgoff_t offset,
1542 struct tmem_oid oid = oswiz(type, ind);
1544 unsigned long flags;
1546 BUG_ON(!PageLocked(page));
1547 if (!disable_frontswap_ignore_nonactive && !PageWasActive(page)) {
1548 zcache_pers_nonactive_puts_ignored++;
1552 if (
likely(ind64 == ind)) {
1565 static int zcache_frontswap_get_page(
unsigned type,
pgoff_t offset,
1570 struct tmem_oid oid = oswiz(type, ind);
1572 int ret = -1, get_and_free;
1574 if (frontswap_has_exclusive_gets)
1578 BUG_ON(!PageLocked(page));
1579 if (
likely(ind64 == ind)) {
1582 page, &size,
false, get_and_free);
1589 static void zcache_frontswap_flush_page(
unsigned type,
pgoff_t offset)
1593 struct tmem_oid oid = oswiz(type, ind);
1595 if (
likely(ind64 == ind))
1601 static void zcache_frontswap_flush_area(
unsigned type)
1606 for (ind =
SWIZ_MASK; ind >= 0; ind--) {
1607 oid = oswiz(type, ind);
1609 zcache_frontswap_poolid, &oid);
1613 static void zcache_frontswap_init(
unsigned ignored)
1616 if (zcache_frontswap_poolid < 0)
1617 zcache_frontswap_poolid =
1622 .store = zcache_frontswap_put_page,
1623 .load = zcache_frontswap_get_page,
1624 .invalidate_page = zcache_frontswap_flush_page,
1625 .invalidate_area = zcache_frontswap_flush_area,
1626 .init = zcache_frontswap_init
1643 static int __init enable_zcache(
char *
s)
1648 __setup(
"zcache", enable_zcache);
1650 static int __init enable_ramster(
char *
s)
1653 #ifdef CONFIG_RAMSTER
1658 __setup(
"ramster", enable_ramster);
1662 static int __init no_cleancache(
char *
s)
1664 disable_cleancache = 1;
1668 __setup(
"nocleancache", no_cleancache);
1670 static int __init no_frontswap(
char *
s)
1672 disable_frontswap = 1;
1676 __setup(
"nofrontswap", no_frontswap);
1678 static int __init no_frontswap_exclusive_gets(
char *
s)
1680 frontswap_has_exclusive_gets =
false;
1684 __setup(
"nofrontswapexclusivegets", no_frontswap_exclusive_gets);
1686 static int __init no_frontswap_ignore_nonactive(
char *
s)
1688 disable_frontswap_ignore_nonactive = 1;
1692 __setup(
"nofrontswapignorenonactive", no_frontswap_ignore_nonactive);
1694 static int __init no_cleancache_ignore_nonactive(
char *
s)
1696 disable_cleancache_ignore_nonactive = 1;
1700 __setup(
"nocleancacheignorenonactive", no_cleancache_ignore_nonactive);
1702 static int __init enable_zcache_compressor(
char *
s)
1708 __setup(
"zcache=", enable_zcache_compressor);
1711 static int __init zcache_comp_init(
void)
1716 if (*zcache_comp_name !=
'\0') {
1717 ret = crypto_has_comp(zcache_comp_name, 0, 0);
1719 pr_info(
"zcache: %s not supported\n",
1723 strcpy(zcache_comp_name,
"lzo");
1724 ret = crypto_has_comp(zcache_comp_name, 0, 0);
1729 pr_info(
"zcache: using %s compressor\n", zcache_comp_name);
1734 if (!zcache_comp_pcpu_tfms)
1740 static int __init zcache_init(
void)
1745 namestr =
"ramster";
1748 #ifdef CONFIG_DEBUG_FS
1749 zcache_debugfs_init();
1751 if (zcache_enabled) {
1756 ret = register_cpu_notifier(&zcache_cpu_notifier_block);
1758 pr_err(
"%s: can't register cpu notifier\n", namestr);
1761 ret = zcache_comp_init();
1763 pr_err(
"%s: compressor initialization failed\n",
1768 void *pcpu = (
void *)(
long)
cpu;
1769 zcache_cpu_notifier(&zcache_cpu_notifier_block,
1779 pr_err(
"%s: can't create client\n", namestr);
1783 if (zcache_enabled && !disable_cleancache) {
1788 pr_info(
"%s: cleancache enabled using kernel transcendent "
1789 "memory and compression buddies\n", namestr);
1791 pr_info(
"%s: cleancache: ignorenonactive = %d\n",
1792 namestr, !disable_cleancache_ignore_nonactive);
1794 if (old_ops.init_fs !=
NULL)
1795 pr_warn(
"%s: cleancache_ops overridden\n", namestr);
1797 if (zcache_enabled && !disable_frontswap) {
1801 if (frontswap_has_exclusive_gets)
1802 frontswap_tmem_exclusive_gets(
true);
1803 pr_info(
"%s: frontswap enabled using kernel transcendent "
1804 "memory and compression buddies\n", namestr);
1806 pr_info(
"%s: frontswap: excl gets = %d active only = %d\n",
1807 namestr, frontswap_has_exclusive_gets,
1808 !disable_frontswap_ignore_nonactive);
1810 if (old_ops.init !=
NULL)
1811 pr_warn(
"%s: frontswap_ops overridden\n", namestr);
1815 frontswap_has_exclusive_gets);