zswap.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. /*
  2. * zswap.c - zswap driver file
  3. *
  4. * zswap is a backend for frontswap that takes pages that are in the process
  5. * of being swapped out and attempts to compress and store them in a
  6. * RAM-based memory pool. This can result in a significant I/O reduction on
  7. * the swap device and, in the case where decompressing from RAM is faster
  8. * than reading from the swap device, can also improve workload performance.
  9. *
  10. * Copyright (C) 2012 Seth Jennings <sjenning@linux.vnet.ibm.com>
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. */
  22. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  23. #include <linux/module.h>
  24. #include <linux/cpu.h>
  25. #include <linux/highmem.h>
  26. #include <linux/slab.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/types.h>
  29. #include <linux/atomic.h>
  30. #include <linux/frontswap.h>
  31. #include <linux/rbtree.h>
  32. #include <linux/swap.h>
  33. #include <linux/crypto.h>
  34. #include <linux/mempool.h>
  35. #include <linux/zpool.h>
  36. #include <linux/mm_types.h>
  37. #include <linux/page-flags.h>
  38. #include <linux/swapops.h>
  39. #include <linux/writeback.h>
  40. #include <linux/pagemap.h>
  41. /*********************************
  42. * statistics
  43. **********************************/
  44. /* Total bytes used by the compressed storage */
  45. static u64 zswap_pool_total_size;
  46. /* The number of compressed pages currently stored in zswap */
  47. static atomic_t zswap_stored_pages = ATOMIC_INIT(0);
  48. /*
  49. * The statistics below are not protected from concurrent access for
  50. * performance reasons so they may not be a 100% accurate. However,
  51. * they do provide useful information on roughly how many times a
  52. * certain event is occurring.
  53. */
  54. /* Pool limit was hit (see zswap_max_pool_percent) */
  55. static u64 zswap_pool_limit_hit;
  56. /* Pages written back when pool limit was reached */
  57. static u64 zswap_written_back_pages;
  58. /* Store failed due to a reclaim failure after pool limit was reached */
  59. static u64 zswap_reject_reclaim_fail;
  60. /* Compressed page was too big for the allocator to (optimally) store */
  61. static u64 zswap_reject_compress_poor;
  62. /* Store failed because underlying allocator could not get memory */
  63. static u64 zswap_reject_alloc_fail;
  64. /* Store failed because the entry metadata could not be allocated (rare) */
  65. static u64 zswap_reject_kmemcache_fail;
  66. /* Duplicate store was encountered (rare) */
  67. static u64 zswap_duplicate_entry;
  68. /*********************************
  69. * tunables
  70. **********************************/
  71. /* Enable/disable zswap (disabled by default) */
  72. static bool zswap_enabled;
  73. static int zswap_enabled_param_set(const char *,
  74. const struct kernel_param *);
  75. static struct kernel_param_ops zswap_enabled_param_ops = {
  76. .set = zswap_enabled_param_set,
  77. .get = param_get_bool,
  78. };
  79. module_param_cb(enabled, &zswap_enabled_param_ops, &zswap_enabled, 0644);
  80. /* Crypto compressor to use */
  81. #define ZSWAP_COMPRESSOR_DEFAULT "lzo"
  82. static char *zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT;
  83. static int zswap_compressor_param_set(const char *,
  84. const struct kernel_param *);
  85. static struct kernel_param_ops zswap_compressor_param_ops = {
  86. .set = zswap_compressor_param_set,
  87. .get = param_get_charp,
  88. .free = param_free_charp,
  89. };
  90. module_param_cb(compressor, &zswap_compressor_param_ops,
  91. &zswap_compressor, 0644);
  92. /* Compressed storage zpool to use */
  93. #define ZSWAP_ZPOOL_DEFAULT "zbud"
  94. static char *zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT;
  95. static int zswap_zpool_param_set(const char *, const struct kernel_param *);
  96. static struct kernel_param_ops zswap_zpool_param_ops = {
  97. .set = zswap_zpool_param_set,
  98. .get = param_get_charp,
  99. .free = param_free_charp,
  100. };
  101. module_param_cb(zpool, &zswap_zpool_param_ops, &zswap_zpool_type, 0644);
  102. /* The maximum percentage of memory that the compressed pool can occupy */
  103. static unsigned int zswap_max_pool_percent = 20;
  104. module_param_named(max_pool_percent, zswap_max_pool_percent, uint, 0644);
  105. /*********************************
  106. * data structures
  107. **********************************/
  108. struct zswap_pool {
  109. struct zpool *zpool;
  110. struct crypto_comp * __percpu *tfm;
  111. struct kref kref;
  112. struct list_head list;
  113. struct work_struct work;
  114. struct notifier_block notifier;
  115. char tfm_name[CRYPTO_MAX_ALG_NAME];
  116. };
  117. /*
  118. * struct zswap_entry
  119. *
  120. * This structure contains the metadata for tracking a single compressed
  121. * page within zswap.
  122. *
  123. * rbnode - links the entry into red-black tree for the appropriate swap type
  124. * offset - the swap offset for the entry. Index into the red-black tree.
  125. * refcount - the number of outstanding reference to the entry. This is needed
  126. * to protect against premature freeing of the entry by code
  127. * concurrent calls to load, invalidate, and writeback. The lock
  128. * for the zswap_tree structure that contains the entry must
  129. * be held while changing the refcount. Since the lock must
  130. * be held, there is no reason to also make refcount atomic.
  131. * length - the length in bytes of the compressed page data. Needed during
  132. * decompression
  133. * pool - the zswap_pool the entry's data is in
  134. * handle - zpool allocation handle that stores the compressed page data
  135. */
  136. struct zswap_entry {
  137. struct rb_node rbnode;
  138. pgoff_t offset;
  139. int refcount;
  140. unsigned int length;
  141. struct zswap_pool *pool;
  142. unsigned long handle;
  143. };
  144. struct zswap_header {
  145. swp_entry_t swpentry;
  146. };
  147. /*
  148. * The tree lock in the zswap_tree struct protects a few things:
  149. * - the rbtree
  150. * - the refcount field of each entry in the tree
  151. */
  152. struct zswap_tree {
  153. struct rb_root rbroot;
  154. spinlock_t lock;
  155. };
  156. static struct zswap_tree *zswap_trees[MAX_SWAPFILES];
  157. /* RCU-protected iteration */
  158. static LIST_HEAD(zswap_pools);
  159. /* protects zswap_pools list modification */
  160. static DEFINE_SPINLOCK(zswap_pools_lock);
  161. /* pool counter to provide unique names to zpool */
  162. static atomic_t zswap_pools_count = ATOMIC_INIT(0);
  163. /* used by param callback function */
  164. static bool zswap_init_started;
  165. /* fatal error during init */
  166. static bool zswap_init_failed;
  167. /*********************************
  168. * helpers and fwd declarations
  169. **********************************/
  170. #define zswap_pool_debug(msg, p) \
  171. pr_debug("%s pool %s/%s\n", msg, (p)->tfm_name, \
  172. zpool_get_type((p)->zpool))
  173. static int zswap_writeback_entry(struct zpool *pool, unsigned long handle);
  174. static int zswap_pool_get(struct zswap_pool *pool);
  175. static void zswap_pool_put(struct zswap_pool *pool);
  176. static const struct zpool_ops zswap_zpool_ops = {
  177. .evict = zswap_writeback_entry
  178. };
  179. static bool zswap_is_full(void)
  180. {
  181. return totalram_pages * zswap_max_pool_percent / 100 <
  182. DIV_ROUND_UP(zswap_pool_total_size, PAGE_SIZE);
  183. }
  184. static void zswap_update_total_size(void)
  185. {
  186. struct zswap_pool *pool;
  187. u64 total = 0;
  188. rcu_read_lock();
  189. list_for_each_entry_rcu(pool, &zswap_pools, list)
  190. total += zpool_get_total_size(pool->zpool);
  191. rcu_read_unlock();
  192. zswap_pool_total_size = total;
  193. }
  194. /*********************************
  195. * zswap entry functions
  196. **********************************/
  197. static struct kmem_cache *zswap_entry_cache;
  198. static int __init zswap_entry_cache_create(void)
  199. {
  200. zswap_entry_cache = KMEM_CACHE(zswap_entry, 0);
  201. return zswap_entry_cache == NULL;
  202. }
  203. static void __init zswap_entry_cache_destroy(void)
  204. {
  205. kmem_cache_destroy(zswap_entry_cache);
  206. }
  207. static struct zswap_entry *zswap_entry_cache_alloc(gfp_t gfp)
  208. {
  209. struct zswap_entry *entry;
  210. entry = kmem_cache_alloc(zswap_entry_cache, gfp);
  211. if (!entry)
  212. return NULL;
  213. entry->refcount = 1;
  214. RB_CLEAR_NODE(&entry->rbnode);
  215. return entry;
  216. }
  217. static void zswap_entry_cache_free(struct zswap_entry *entry)
  218. {
  219. kmem_cache_free(zswap_entry_cache, entry);
  220. }
  221. /*********************************
  222. * rbtree functions
  223. **********************************/
  224. static struct zswap_entry *zswap_rb_search(struct rb_root *root, pgoff_t offset)
  225. {
  226. struct rb_node *node = root->rb_node;
  227. struct zswap_entry *entry;
  228. while (node) {
  229. entry = rb_entry(node, struct zswap_entry, rbnode);
  230. if (entry->offset > offset)
  231. node = node->rb_left;
  232. else if (entry->offset < offset)
  233. node = node->rb_right;
  234. else
  235. return entry;
  236. }
  237. return NULL;
  238. }
  239. /*
  240. * In the case that a entry with the same offset is found, a pointer to
  241. * the existing entry is stored in dupentry and the function returns -EEXIST
  242. */
  243. static int zswap_rb_insert(struct rb_root *root, struct zswap_entry *entry,
  244. struct zswap_entry **dupentry)
  245. {
  246. struct rb_node **link = &root->rb_node, *parent = NULL;
  247. struct zswap_entry *myentry;
  248. while (*link) {
  249. parent = *link;
  250. myentry = rb_entry(parent, struct zswap_entry, rbnode);
  251. if (myentry->offset > entry->offset)
  252. link = &(*link)->rb_left;
  253. else if (myentry->offset < entry->offset)
  254. link = &(*link)->rb_right;
  255. else {
  256. *dupentry = myentry;
  257. return -EEXIST;
  258. }
  259. }
  260. rb_link_node(&entry->rbnode, parent, link);
  261. rb_insert_color(&entry->rbnode, root);
  262. return 0;
  263. }
  264. static void zswap_rb_erase(struct rb_root *root, struct zswap_entry *entry)
  265. {
  266. if (!RB_EMPTY_NODE(&entry->rbnode)) {
  267. rb_erase(&entry->rbnode, root);
  268. RB_CLEAR_NODE(&entry->rbnode);
  269. }
  270. }
  271. /*
  272. * Carries out the common pattern of freeing and entry's zpool allocation,
  273. * freeing the entry itself, and decrementing the number of stored pages.
  274. */
  275. static void zswap_free_entry(struct zswap_entry *entry)
  276. {
  277. zpool_free(entry->pool->zpool, entry->handle);
  278. zswap_pool_put(entry->pool);
  279. zswap_entry_cache_free(entry);
  280. atomic_dec(&zswap_stored_pages);
  281. zswap_update_total_size();
  282. }
  283. /* caller must hold the tree lock */
  284. static void zswap_entry_get(struct zswap_entry *entry)
  285. {
  286. entry->refcount++;
  287. }
  288. /* caller must hold the tree lock
  289. * remove from the tree and free it, if nobody reference the entry
  290. */
  291. static void zswap_entry_put(struct zswap_tree *tree,
  292. struct zswap_entry *entry)
  293. {
  294. int refcount = --entry->refcount;
  295. BUG_ON(refcount < 0);
  296. if (refcount == 0) {
  297. zswap_rb_erase(&tree->rbroot, entry);
  298. zswap_free_entry(entry);
  299. }
  300. }
  301. /* caller must hold the tree lock */
  302. static struct zswap_entry *zswap_entry_find_get(struct rb_root *root,
  303. pgoff_t offset)
  304. {
  305. struct zswap_entry *entry;
  306. entry = zswap_rb_search(root, offset);
  307. if (entry)
  308. zswap_entry_get(entry);
  309. return entry;
  310. }
  311. /*********************************
  312. * per-cpu code
  313. **********************************/
  314. static DEFINE_PER_CPU(u8 *, zswap_dstmem);
  315. static int __zswap_cpu_dstmem_notifier(unsigned long action, unsigned long cpu)
  316. {
  317. u8 *dst;
  318. switch (action) {
  319. case CPU_UP_PREPARE:
  320. dst = kmalloc_node(PAGE_SIZE * 2, GFP_KERNEL, cpu_to_node(cpu));
  321. if (!dst) {
  322. pr_err("can't allocate compressor buffer\n");
  323. return NOTIFY_BAD;
  324. }
  325. per_cpu(zswap_dstmem, cpu) = dst;
  326. break;
  327. case CPU_DEAD:
  328. case CPU_UP_CANCELED:
  329. dst = per_cpu(zswap_dstmem, cpu);
  330. kfree(dst);
  331. per_cpu(zswap_dstmem, cpu) = NULL;
  332. break;
  333. default:
  334. break;
  335. }
  336. return NOTIFY_OK;
  337. }
  338. static int zswap_cpu_dstmem_notifier(struct notifier_block *nb,
  339. unsigned long action, void *pcpu)
  340. {
  341. return __zswap_cpu_dstmem_notifier(action, (unsigned long)pcpu);
  342. }
  343. static struct notifier_block zswap_dstmem_notifier = {
  344. .notifier_call = zswap_cpu_dstmem_notifier,
  345. };
  346. static int __init zswap_cpu_dstmem_init(void)
  347. {
  348. unsigned long cpu;
  349. cpu_notifier_register_begin();
  350. for_each_online_cpu(cpu)
  351. if (__zswap_cpu_dstmem_notifier(CPU_UP_PREPARE, cpu) ==
  352. NOTIFY_BAD)
  353. goto cleanup;
  354. __register_cpu_notifier(&zswap_dstmem_notifier);
  355. cpu_notifier_register_done();
  356. return 0;
  357. cleanup:
  358. for_each_online_cpu(cpu)
  359. __zswap_cpu_dstmem_notifier(CPU_UP_CANCELED, cpu);
  360. cpu_notifier_register_done();
  361. return -ENOMEM;
  362. }
  363. static void zswap_cpu_dstmem_destroy(void)
  364. {
  365. unsigned long cpu;
  366. cpu_notifier_register_begin();
  367. for_each_online_cpu(cpu)
  368. __zswap_cpu_dstmem_notifier(CPU_UP_CANCELED, cpu);
  369. __unregister_cpu_notifier(&zswap_dstmem_notifier);
  370. cpu_notifier_register_done();
  371. }
  372. static int __zswap_cpu_comp_notifier(struct zswap_pool *pool,
  373. unsigned long action, unsigned long cpu)
  374. {
  375. struct crypto_comp *tfm;
  376. switch (action) {
  377. case CPU_UP_PREPARE:
  378. if (WARN_ON(*per_cpu_ptr(pool->tfm, cpu)))
  379. break;
  380. tfm = crypto_alloc_comp(pool->tfm_name, 0, 0);
  381. if (IS_ERR_OR_NULL(tfm)) {
  382. pr_err("could not alloc crypto comp %s : %ld\n",
  383. pool->tfm_name, PTR_ERR(tfm));
  384. return NOTIFY_BAD;
  385. }
  386. *per_cpu_ptr(pool->tfm, cpu) = tfm;
  387. break;
  388. case CPU_DEAD:
  389. case CPU_UP_CANCELED:
  390. tfm = *per_cpu_ptr(pool->tfm, cpu);
  391. if (!IS_ERR_OR_NULL(tfm))
  392. crypto_free_comp(tfm);
  393. *per_cpu_ptr(pool->tfm, cpu) = NULL;
  394. break;
  395. default:
  396. break;
  397. }
  398. return NOTIFY_OK;
  399. }
  400. static int zswap_cpu_comp_notifier(struct notifier_block *nb,
  401. unsigned long action, void *pcpu)
  402. {
  403. unsigned long cpu = (unsigned long)pcpu;
  404. struct zswap_pool *pool = container_of(nb, typeof(*pool), notifier);
  405. return __zswap_cpu_comp_notifier(pool, action, cpu);
  406. }
  407. static int zswap_cpu_comp_init(struct zswap_pool *pool)
  408. {
  409. unsigned long cpu;
  410. memset(&pool->notifier, 0, sizeof(pool->notifier));
  411. pool->notifier.notifier_call = zswap_cpu_comp_notifier;
  412. cpu_notifier_register_begin();
  413. for_each_online_cpu(cpu)
  414. if (__zswap_cpu_comp_notifier(pool, CPU_UP_PREPARE, cpu) ==
  415. NOTIFY_BAD)
  416. goto cleanup;
  417. __register_cpu_notifier(&pool->notifier);
  418. cpu_notifier_register_done();
  419. return 0;
  420. cleanup:
  421. for_each_online_cpu(cpu)
  422. __zswap_cpu_comp_notifier(pool, CPU_UP_CANCELED, cpu);
  423. cpu_notifier_register_done();
  424. return -ENOMEM;
  425. }
  426. static void zswap_cpu_comp_destroy(struct zswap_pool *pool)
  427. {
  428. unsigned long cpu;
  429. cpu_notifier_register_begin();
  430. for_each_online_cpu(cpu)
  431. __zswap_cpu_comp_notifier(pool, CPU_UP_CANCELED, cpu);
  432. __unregister_cpu_notifier(&pool->notifier);
  433. cpu_notifier_register_done();
  434. }
  435. /*********************************
  436. * pool functions
  437. **********************************/
  438. static struct zswap_pool *__zswap_pool_current(void)
  439. {
  440. struct zswap_pool *pool;
  441. pool = list_first_or_null_rcu(&zswap_pools, typeof(*pool), list);
  442. WARN_ON(!pool);
  443. return pool;
  444. }
  445. static struct zswap_pool *zswap_pool_current(void)
  446. {
  447. assert_spin_locked(&zswap_pools_lock);
  448. return __zswap_pool_current();
  449. }
  450. static struct zswap_pool *zswap_pool_current_get(void)
  451. {
  452. struct zswap_pool *pool;
  453. rcu_read_lock();
  454. pool = __zswap_pool_current();
  455. if (!pool || !zswap_pool_get(pool))
  456. pool = NULL;
  457. rcu_read_unlock();
  458. return pool;
  459. }
  460. static struct zswap_pool *zswap_pool_last_get(void)
  461. {
  462. struct zswap_pool *pool, *last = NULL;
  463. rcu_read_lock();
  464. list_for_each_entry_rcu(pool, &zswap_pools, list)
  465. last = pool;
  466. if (!WARN_ON(!last) && !zswap_pool_get(last))
  467. last = NULL;
  468. rcu_read_unlock();
  469. return last;
  470. }
  471. /* type and compressor must be null-terminated */
  472. static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor)
  473. {
  474. struct zswap_pool *pool;
  475. assert_spin_locked(&zswap_pools_lock);
  476. list_for_each_entry_rcu(pool, &zswap_pools, list) {
  477. if (strcmp(pool->tfm_name, compressor))
  478. continue;
  479. if (strcmp(zpool_get_type(pool->zpool), type))
  480. continue;
  481. /* if we can't get it, it's about to be destroyed */
  482. if (!zswap_pool_get(pool))
  483. continue;
  484. return pool;
  485. }
  486. return NULL;
  487. }
  488. static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
  489. {
  490. struct zswap_pool *pool;
  491. char name[38]; /* 'zswap' + 32 char (max) num + \0 */
  492. gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM;
  493. pool = kzalloc(sizeof(*pool), GFP_KERNEL);
  494. if (!pool) {
  495. pr_err("pool alloc failed\n");
  496. return NULL;
  497. }
  498. /* unique name for each pool specifically required by zsmalloc */
  499. snprintf(name, 38, "zswap%x", atomic_inc_return(&zswap_pools_count));
  500. pool->zpool = zpool_create_pool(type, name, gfp, &zswap_zpool_ops);
  501. if (!pool->zpool) {
  502. pr_err("%s zpool not available\n", type);
  503. goto error;
  504. }
  505. pr_debug("using %s zpool\n", zpool_get_type(pool->zpool));
  506. strlcpy(pool->tfm_name, compressor, sizeof(pool->tfm_name));
  507. pool->tfm = alloc_percpu(struct crypto_comp *);
  508. if (!pool->tfm) {
  509. pr_err("percpu alloc failed\n");
  510. goto error;
  511. }
  512. if (zswap_cpu_comp_init(pool))
  513. goto error;
  514. pr_debug("using %s compressor\n", pool->tfm_name);
  515. /* being the current pool takes 1 ref; this func expects the
  516. * caller to always add the new pool as the current pool
  517. */
  518. kref_init(&pool->kref);
  519. INIT_LIST_HEAD(&pool->list);
  520. zswap_pool_debug("created", pool);
  521. return pool;
  522. error:
  523. free_percpu(pool->tfm);
  524. if (pool->zpool)
  525. zpool_destroy_pool(pool->zpool);
  526. kfree(pool);
  527. return NULL;
  528. }
  529. static __init struct zswap_pool *__zswap_pool_create_fallback(void)
  530. {
  531. if (!crypto_has_comp(zswap_compressor, 0, 0)) {
  532. if (!strcmp(zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT)) {
  533. pr_err("default compressor %s not available\n",
  534. zswap_compressor);
  535. return NULL;
  536. }
  537. pr_err("compressor %s not available, using default %s\n",
  538. zswap_compressor, ZSWAP_COMPRESSOR_DEFAULT);
  539. param_free_charp(&zswap_compressor);
  540. zswap_compressor = ZSWAP_COMPRESSOR_DEFAULT;
  541. }
  542. if (!zpool_has_pool(zswap_zpool_type)) {
  543. if (!strcmp(zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT)) {
  544. pr_err("default zpool %s not available\n",
  545. zswap_zpool_type);
  546. return NULL;
  547. }
  548. pr_err("zpool %s not available, using default %s\n",
  549. zswap_zpool_type, ZSWAP_ZPOOL_DEFAULT);
  550. param_free_charp(&zswap_zpool_type);
  551. zswap_zpool_type = ZSWAP_ZPOOL_DEFAULT;
  552. }
  553. return zswap_pool_create(zswap_zpool_type, zswap_compressor);
  554. }
  555. static void zswap_pool_destroy(struct zswap_pool *pool)
  556. {
  557. zswap_pool_debug("destroying", pool);
  558. zswap_cpu_comp_destroy(pool);
  559. free_percpu(pool->tfm);
  560. zpool_destroy_pool(pool->zpool);
  561. kfree(pool);
  562. }
  563. static int __must_check zswap_pool_get(struct zswap_pool *pool)
  564. {
  565. return kref_get_unless_zero(&pool->kref);
  566. }
  567. static void __zswap_pool_release(struct work_struct *work)
  568. {
  569. struct zswap_pool *pool = container_of(work, typeof(*pool), work);
  570. synchronize_rcu();
  571. /* nobody should have been able to get a kref... */
  572. WARN_ON(kref_get_unless_zero(&pool->kref));
  573. /* pool is now off zswap_pools list and has no references. */
  574. zswap_pool_destroy(pool);
  575. }
  576. static void __zswap_pool_empty(struct kref *kref)
  577. {
  578. struct zswap_pool *pool;
  579. pool = container_of(kref, typeof(*pool), kref);
  580. spin_lock(&zswap_pools_lock);
  581. WARN_ON(pool == zswap_pool_current());
  582. list_del_rcu(&pool->list);
  583. INIT_WORK(&pool->work, __zswap_pool_release);
  584. schedule_work(&pool->work);
  585. spin_unlock(&zswap_pools_lock);
  586. }
  587. static void zswap_pool_put(struct zswap_pool *pool)
  588. {
  589. kref_put(&pool->kref, __zswap_pool_empty);
  590. }
  591. /*********************************
  592. * param callbacks
  593. **********************************/
  594. /* val must be a null-terminated string */
  595. static int __zswap_param_set(const char *val, const struct kernel_param *kp,
  596. char *type, char *compressor)
  597. {
  598. struct zswap_pool *pool, *put_pool = NULL;
  599. char *s = strstrip((char *)val);
  600. int ret;
  601. if (zswap_init_failed) {
  602. pr_err("can't set param, initialization failed\n");
  603. return -ENODEV;
  604. }
  605. /* no change required */
  606. if (!strcmp(s, *(char **)kp->arg))
  607. return 0;
  608. /* if this is load-time (pre-init) param setting,
  609. * don't create a pool; that's done during init.
  610. */
  611. if (!zswap_init_started)
  612. return param_set_charp(s, kp);
  613. if (!type) {
  614. if (!zpool_has_pool(s)) {
  615. pr_err("zpool %s not available\n", s);
  616. return -ENOENT;
  617. }
  618. type = s;
  619. } else if (!compressor) {
  620. if (!crypto_has_comp(s, 0, 0)) {
  621. pr_err("compressor %s not available\n", s);
  622. return -ENOENT;
  623. }
  624. compressor = s;
  625. } else {
  626. WARN_ON(1);
  627. return -EINVAL;
  628. }
  629. spin_lock(&zswap_pools_lock);
  630. pool = zswap_pool_find_get(type, compressor);
  631. if (pool) {
  632. zswap_pool_debug("using existing", pool);
  633. WARN_ON(pool == zswap_pool_current());
  634. list_del_rcu(&pool->list);
  635. }
  636. spin_unlock(&zswap_pools_lock);
  637. if (!pool)
  638. pool = zswap_pool_create(type, compressor);
  639. if (pool)
  640. ret = param_set_charp(s, kp);
  641. else
  642. ret = -EINVAL;
  643. spin_lock(&zswap_pools_lock);
  644. if (!ret) {
  645. put_pool = zswap_pool_current();
  646. list_add_rcu(&pool->list, &zswap_pools);
  647. } else if (pool) {
  648. /* add the possibly pre-existing pool to the end of the pools
  649. * list; if it's new (and empty) then it'll be removed and
  650. * destroyed by the put after we drop the lock
  651. */
  652. list_add_tail_rcu(&pool->list, &zswap_pools);
  653. put_pool = pool;
  654. }
  655. spin_unlock(&zswap_pools_lock);
  656. /* drop the ref from either the old current pool,
  657. * or the new pool we failed to add
  658. */
  659. if (put_pool)
  660. zswap_pool_put(put_pool);
  661. return ret;
  662. }
  663. static int zswap_compressor_param_set(const char *val,
  664. const struct kernel_param *kp)
  665. {
  666. return __zswap_param_set(val, kp, zswap_zpool_type, NULL);
  667. }
  668. static int zswap_zpool_param_set(const char *val,
  669. const struct kernel_param *kp)
  670. {
  671. return __zswap_param_set(val, kp, NULL, zswap_compressor);
  672. }
  673. static int zswap_enabled_param_set(const char *val,
  674. const struct kernel_param *kp)
  675. {
  676. if (zswap_init_failed) {
  677. pr_err("can't enable, initialization failed\n");
  678. return -ENODEV;
  679. }
  680. return param_set_bool(val, kp);
  681. }
  682. /*********************************
  683. * writeback code
  684. **********************************/
  685. /* return enum for zswap_get_swap_cache_page */
  686. enum zswap_get_swap_ret {
  687. ZSWAP_SWAPCACHE_NEW,
  688. ZSWAP_SWAPCACHE_EXIST,
  689. ZSWAP_SWAPCACHE_FAIL,
  690. };
  691. /*
  692. * zswap_get_swap_cache_page
  693. *
  694. * This is an adaption of read_swap_cache_async()
  695. *
  696. * This function tries to find a page with the given swap entry
  697. * in the swapper_space address space (the swap cache). If the page
  698. * is found, it is returned in retpage. Otherwise, a page is allocated,
  699. * added to the swap cache, and returned in retpage.
  700. *
  701. * If success, the swap cache page is returned in retpage
  702. * Returns ZSWAP_SWAPCACHE_EXIST if page was already in the swap cache
  703. * Returns ZSWAP_SWAPCACHE_NEW if the new page needs to be populated,
  704. * the new page is added to swapcache and locked
  705. * Returns ZSWAP_SWAPCACHE_FAIL on error
  706. */
  707. static int zswap_get_swap_cache_page(swp_entry_t entry,
  708. struct page **retpage)
  709. {
  710. bool page_was_allocated;
  711. *retpage = __read_swap_cache_async(entry, GFP_KERNEL,
  712. NULL, 0, &page_was_allocated);
  713. if (page_was_allocated)
  714. return ZSWAP_SWAPCACHE_NEW;
  715. if (!*retpage)
  716. return ZSWAP_SWAPCACHE_FAIL;
  717. return ZSWAP_SWAPCACHE_EXIST;
  718. }
  719. /*
  720. * Attempts to free an entry by adding a page to the swap cache,
  721. * decompressing the entry data into the page, and issuing a
  722. * bio write to write the page back to the swap device.
  723. *
  724. * This can be thought of as a "resumed writeback" of the page
  725. * to the swap device. We are basically resuming the same swap
  726. * writeback path that was intercepted with the frontswap_store()
  727. * in the first place. After the page has been decompressed into
  728. * the swap cache, the compressed version stored by zswap can be
  729. * freed.
  730. */
  731. static int zswap_writeback_entry(struct zpool *pool, unsigned long handle)
  732. {
  733. struct zswap_header *zhdr;
  734. swp_entry_t swpentry;
  735. struct zswap_tree *tree;
  736. pgoff_t offset;
  737. struct zswap_entry *entry;
  738. struct page *page;
  739. struct crypto_comp *tfm;
  740. u8 *src, *dst;
  741. unsigned int dlen;
  742. int ret;
  743. struct writeback_control wbc = {
  744. .sync_mode = WB_SYNC_NONE,
  745. };
  746. /* extract swpentry from data */
  747. zhdr = zpool_map_handle(pool, handle, ZPOOL_MM_RO);
  748. swpentry = zhdr->swpentry; /* here */
  749. zpool_unmap_handle(pool, handle);
  750. tree = zswap_trees[swp_type(swpentry)];
  751. offset = swp_offset(swpentry);
  752. /* find and ref zswap entry */
  753. spin_lock(&tree->lock);
  754. entry = zswap_entry_find_get(&tree->rbroot, offset);
  755. if (!entry) {
  756. /* entry was invalidated */
  757. spin_unlock(&tree->lock);
  758. return 0;
  759. }
  760. spin_unlock(&tree->lock);
  761. BUG_ON(offset != entry->offset);
  762. /* try to allocate swap cache page */
  763. switch (zswap_get_swap_cache_page(swpentry, &page)) {
  764. case ZSWAP_SWAPCACHE_FAIL: /* no memory or invalidate happened */
  765. ret = -ENOMEM;
  766. goto fail;
  767. case ZSWAP_SWAPCACHE_EXIST:
  768. /* page is already in the swap cache, ignore for now */
  769. page_cache_release(page);
  770. ret = -EEXIST;
  771. goto fail;
  772. case ZSWAP_SWAPCACHE_NEW: /* page is locked */
  773. /* decompress */
  774. dlen = PAGE_SIZE;
  775. src = (u8 *)zpool_map_handle(entry->pool->zpool, entry->handle,
  776. ZPOOL_MM_RO) + sizeof(struct zswap_header);
  777. dst = kmap_atomic(page);
  778. tfm = *get_cpu_ptr(entry->pool->tfm);
  779. ret = crypto_comp_decompress(tfm, src, entry->length,
  780. dst, &dlen);
  781. put_cpu_ptr(entry->pool->tfm);
  782. kunmap_atomic(dst);
  783. zpool_unmap_handle(entry->pool->zpool, entry->handle);
  784. BUG_ON(ret);
  785. BUG_ON(dlen != PAGE_SIZE);
  786. /* page is up to date */
  787. SetPageUptodate(page);
  788. }
  789. /* move it to the tail of the inactive list after end_writeback */
  790. SetPageReclaim(page);
  791. /* start writeback */
  792. __swap_writepage(page, &wbc, end_swap_bio_write);
  793. page_cache_release(page);
  794. zswap_written_back_pages++;
  795. spin_lock(&tree->lock);
  796. /* drop local reference */
  797. zswap_entry_put(tree, entry);
  798. /*
  799. * There are two possible situations for entry here:
  800. * (1) refcount is 1(normal case), entry is valid and on the tree
  801. * (2) refcount is 0, entry is freed and not on the tree
  802. * because invalidate happened during writeback
  803. * search the tree and free the entry if find entry
  804. */
  805. if (entry == zswap_rb_search(&tree->rbroot, offset))
  806. zswap_entry_put(tree, entry);
  807. spin_unlock(&tree->lock);
  808. goto end;
  809. /*
  810. * if we get here due to ZSWAP_SWAPCACHE_EXIST
  811. * a load may happening concurrently
  812. * it is safe and okay to not free the entry
  813. * if we free the entry in the following put
  814. * it it either okay to return !0
  815. */
  816. fail:
  817. spin_lock(&tree->lock);
  818. zswap_entry_put(tree, entry);
  819. spin_unlock(&tree->lock);
  820. end:
  821. return ret;
  822. }
  823. static int zswap_shrink(void)
  824. {
  825. struct zswap_pool *pool;
  826. int ret;
  827. pool = zswap_pool_last_get();
  828. if (!pool)
  829. return -ENOENT;
  830. ret = zpool_shrink(pool->zpool, 1, NULL);
  831. zswap_pool_put(pool);
  832. return ret;
  833. }
  834. /*********************************
  835. * frontswap hooks
  836. **********************************/
  837. /* attempts to compress and store an single page */
  838. static int zswap_frontswap_store(unsigned type, pgoff_t offset,
  839. struct page *page)
  840. {
  841. struct zswap_tree *tree = zswap_trees[type];
  842. struct zswap_entry *entry, *dupentry;
  843. struct crypto_comp *tfm;
  844. int ret;
  845. unsigned int dlen = PAGE_SIZE, len;
  846. unsigned long handle;
  847. char *buf;
  848. u8 *src, *dst;
  849. struct zswap_header *zhdr;
  850. if (!zswap_enabled || !tree) {
  851. ret = -ENODEV;
  852. goto reject;
  853. }
  854. /* reclaim space if needed */
  855. if (zswap_is_full()) {
  856. zswap_pool_limit_hit++;
  857. if (zswap_shrink()) {
  858. zswap_reject_reclaim_fail++;
  859. ret = -ENOMEM;
  860. goto reject;
  861. }
  862. /* A second zswap_is_full() check after
  863. * zswap_shrink() to make sure it's now
  864. * under the max_pool_percent
  865. */
  866. if (zswap_is_full()) {
  867. ret = -ENOMEM;
  868. goto reject;
  869. }
  870. }
  871. /* allocate entry */
  872. entry = zswap_entry_cache_alloc(GFP_KERNEL);
  873. if (!entry) {
  874. zswap_reject_kmemcache_fail++;
  875. ret = -ENOMEM;
  876. goto reject;
  877. }
  878. /* if entry is successfully added, it keeps the reference */
  879. entry->pool = zswap_pool_current_get();
  880. if (!entry->pool) {
  881. ret = -EINVAL;
  882. goto freepage;
  883. }
  884. /* compress */
  885. dst = get_cpu_var(zswap_dstmem);
  886. tfm = *get_cpu_ptr(entry->pool->tfm);
  887. src = kmap_atomic(page);
  888. ret = crypto_comp_compress(tfm, src, PAGE_SIZE, dst, &dlen);
  889. kunmap_atomic(src);
  890. put_cpu_ptr(entry->pool->tfm);
  891. if (ret) {
  892. ret = -EINVAL;
  893. goto put_dstmem;
  894. }
  895. /* store */
  896. len = dlen + sizeof(struct zswap_header);
  897. ret = zpool_malloc(entry->pool->zpool, len,
  898. __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM,
  899. &handle);
  900. if (ret == -ENOSPC) {
  901. zswap_reject_compress_poor++;
  902. goto put_dstmem;
  903. }
  904. if (ret) {
  905. zswap_reject_alloc_fail++;
  906. goto put_dstmem;
  907. }
  908. zhdr = zpool_map_handle(entry->pool->zpool, handle, ZPOOL_MM_RW);
  909. zhdr->swpentry = swp_entry(type, offset);
  910. buf = (u8 *)(zhdr + 1);
  911. memcpy(buf, dst, dlen);
  912. zpool_unmap_handle(entry->pool->zpool, handle);
  913. put_cpu_var(zswap_dstmem);
  914. /* populate entry */
  915. entry->offset = offset;
  916. entry->handle = handle;
  917. entry->length = dlen;
  918. /* map */
  919. spin_lock(&tree->lock);
  920. do {
  921. ret = zswap_rb_insert(&tree->rbroot, entry, &dupentry);
  922. if (ret == -EEXIST) {
  923. zswap_duplicate_entry++;
  924. /* remove from rbtree */
  925. zswap_rb_erase(&tree->rbroot, dupentry);
  926. zswap_entry_put(tree, dupentry);
  927. }
  928. } while (ret == -EEXIST);
  929. spin_unlock(&tree->lock);
  930. /* update stats */
  931. atomic_inc(&zswap_stored_pages);
  932. zswap_update_total_size();
  933. return 0;
  934. put_dstmem:
  935. put_cpu_var(zswap_dstmem);
  936. zswap_pool_put(entry->pool);
  937. freepage:
  938. zswap_entry_cache_free(entry);
  939. reject:
  940. return ret;
  941. }
  942. /*
  943. * returns 0 if the page was successfully decompressed
  944. * return -1 on entry not found or error
  945. */
  946. static int zswap_frontswap_load(unsigned type, pgoff_t offset,
  947. struct page *page)
  948. {
  949. struct zswap_tree *tree = zswap_trees[type];
  950. struct zswap_entry *entry;
  951. struct crypto_comp *tfm;
  952. u8 *src, *dst;
  953. unsigned int dlen;
  954. int ret;
  955. /* find */
  956. spin_lock(&tree->lock);
  957. entry = zswap_entry_find_get(&tree->rbroot, offset);
  958. if (!entry) {
  959. /* entry was written back */
  960. spin_unlock(&tree->lock);
  961. return -1;
  962. }
  963. spin_unlock(&tree->lock);
  964. /* decompress */
  965. dlen = PAGE_SIZE;
  966. src = (u8 *)zpool_map_handle(entry->pool->zpool, entry->handle,
  967. ZPOOL_MM_RO) + sizeof(struct zswap_header);
  968. dst = kmap_atomic(page);
  969. tfm = *get_cpu_ptr(entry->pool->tfm);
  970. ret = crypto_comp_decompress(tfm, src, entry->length, dst, &dlen);
  971. put_cpu_ptr(entry->pool->tfm);
  972. kunmap_atomic(dst);
  973. zpool_unmap_handle(entry->pool->zpool, entry->handle);
  974. BUG_ON(ret);
  975. spin_lock(&tree->lock);
  976. zswap_entry_put(tree, entry);
  977. spin_unlock(&tree->lock);
  978. return 0;
  979. }
  980. /* frees an entry in zswap */
  981. static void zswap_frontswap_invalidate_page(unsigned type, pgoff_t offset)
  982. {
  983. struct zswap_tree *tree = zswap_trees[type];
  984. struct zswap_entry *entry;
  985. /* find */
  986. spin_lock(&tree->lock);
  987. entry = zswap_rb_search(&tree->rbroot, offset);
  988. if (!entry) {
  989. /* entry was written back */
  990. spin_unlock(&tree->lock);
  991. return;
  992. }
  993. /* remove from rbtree */
  994. zswap_rb_erase(&tree->rbroot, entry);
  995. /* drop the initial reference from entry creation */
  996. zswap_entry_put(tree, entry);
  997. spin_unlock(&tree->lock);
  998. }
  999. /* frees all zswap entries for the given swap type */
  1000. static void zswap_frontswap_invalidate_area(unsigned type)
  1001. {
  1002. struct zswap_tree *tree = zswap_trees[type];
  1003. struct zswap_entry *entry, *n;
  1004. if (!tree)
  1005. return;
  1006. /* walk the tree and free everything */
  1007. spin_lock(&tree->lock);
  1008. rbtree_postorder_for_each_entry_safe(entry, n, &tree->rbroot, rbnode)
  1009. zswap_free_entry(entry);
  1010. tree->rbroot = RB_ROOT;
  1011. spin_unlock(&tree->lock);
  1012. kfree(tree);
  1013. zswap_trees[type] = NULL;
  1014. }
  1015. static void zswap_frontswap_init(unsigned type)
  1016. {
  1017. struct zswap_tree *tree;
  1018. tree = kzalloc(sizeof(struct zswap_tree), GFP_KERNEL);
  1019. if (!tree) {
  1020. pr_err("alloc failed, zswap disabled for swap type %d\n", type);
  1021. return;
  1022. }
  1023. tree->rbroot = RB_ROOT;
  1024. spin_lock_init(&tree->lock);
  1025. zswap_trees[type] = tree;
  1026. }
  1027. static struct frontswap_ops zswap_frontswap_ops = {
  1028. .store = zswap_frontswap_store,
  1029. .load = zswap_frontswap_load,
  1030. .invalidate_page = zswap_frontswap_invalidate_page,
  1031. .invalidate_area = zswap_frontswap_invalidate_area,
  1032. .init = zswap_frontswap_init
  1033. };
  1034. /*********************************
  1035. * debugfs functions
  1036. **********************************/
  1037. #ifdef CONFIG_DEBUG_FS
  1038. #include <linux/debugfs.h>
  1039. static struct dentry *zswap_debugfs_root;
  1040. static int __init zswap_debugfs_init(void)
  1041. {
  1042. if (!debugfs_initialized())
  1043. return -ENODEV;
  1044. zswap_debugfs_root = debugfs_create_dir("zswap", NULL);
  1045. if (!zswap_debugfs_root)
  1046. return -ENOMEM;
  1047. debugfs_create_u64("pool_limit_hit", S_IRUGO,
  1048. zswap_debugfs_root, &zswap_pool_limit_hit);
  1049. debugfs_create_u64("reject_reclaim_fail", S_IRUGO,
  1050. zswap_debugfs_root, &zswap_reject_reclaim_fail);
  1051. debugfs_create_u64("reject_alloc_fail", S_IRUGO,
  1052. zswap_debugfs_root, &zswap_reject_alloc_fail);
  1053. debugfs_create_u64("reject_kmemcache_fail", S_IRUGO,
  1054. zswap_debugfs_root, &zswap_reject_kmemcache_fail);
  1055. debugfs_create_u64("reject_compress_poor", S_IRUGO,
  1056. zswap_debugfs_root, &zswap_reject_compress_poor);
  1057. debugfs_create_u64("written_back_pages", S_IRUGO,
  1058. zswap_debugfs_root, &zswap_written_back_pages);
  1059. debugfs_create_u64("duplicate_entry", S_IRUGO,
  1060. zswap_debugfs_root, &zswap_duplicate_entry);
  1061. debugfs_create_u64("pool_total_size", S_IRUGO,
  1062. zswap_debugfs_root, &zswap_pool_total_size);
  1063. debugfs_create_atomic_t("stored_pages", S_IRUGO,
  1064. zswap_debugfs_root, &zswap_stored_pages);
  1065. return 0;
  1066. }
  1067. static void __exit zswap_debugfs_exit(void)
  1068. {
  1069. debugfs_remove_recursive(zswap_debugfs_root);
  1070. }
  1071. #else
  1072. static int __init zswap_debugfs_init(void)
  1073. {
  1074. return 0;
  1075. }
  1076. static void __exit zswap_debugfs_exit(void) { }
  1077. #endif
  1078. /*********************************
  1079. * module init and exit
  1080. **********************************/
  1081. static int __init init_zswap(void)
  1082. {
  1083. struct zswap_pool *pool;
  1084. zswap_init_started = true;
  1085. if (zswap_entry_cache_create()) {
  1086. pr_err("entry cache creation failed\n");
  1087. goto cache_fail;
  1088. }
  1089. if (zswap_cpu_dstmem_init()) {
  1090. pr_err("dstmem alloc failed\n");
  1091. goto dstmem_fail;
  1092. }
  1093. pool = __zswap_pool_create_fallback();
  1094. if (!pool) {
  1095. pr_err("pool creation failed\n");
  1096. goto pool_fail;
  1097. }
  1098. pr_info("loaded using pool %s/%s\n", pool->tfm_name,
  1099. zpool_get_type(pool->zpool));
  1100. list_add(&pool->list, &zswap_pools);
  1101. frontswap_register_ops(&zswap_frontswap_ops);
  1102. if (zswap_debugfs_init())
  1103. pr_warn("debugfs initialization failed\n");
  1104. return 0;
  1105. pool_fail:
  1106. zswap_cpu_dstmem_destroy();
  1107. dstmem_fail:
  1108. zswap_entry_cache_destroy();
  1109. cache_fail:
  1110. /* if built-in, we aren't unloaded on failure; don't allow use */
  1111. zswap_init_failed = true;
  1112. zswap_enabled = false;
  1113. return -ENOMEM;
  1114. }
  1115. /* must be late so crypto has time to come up */
  1116. late_initcall(init_zswap);
  1117. MODULE_LICENSE("GPL");
  1118. MODULE_AUTHOR("Seth Jennings <sjennings@variantweb.net>");
  1119. MODULE_DESCRIPTION("Compressed cache for swap pages");