zswap.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * zswap.c - zswap driver file
  4. *
  5. * zswap is a cache that takes pages that are in the process
  6. * of being swapped out and attempts to compress and store them in a
  7. * RAM-based memory pool. This can result in a significant I/O reduction on
  8. * the swap device and, in the case where decompressing from RAM is faster
  9. * than reading from the swap device, can also improve workload performance.
  10. *
  11. * Copyright (C) 2012 Seth Jennings <sjenning@linux.vnet.ibm.com>
  12. */
  13. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14. #include <linux/module.h>
  15. #include <linux/cpu.h>
  16. #include <linux/highmem.h>
  17. #include <linux/slab.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/types.h>
  20. #include <linux/atomic.h>
  21. #include <linux/swap.h>
  22. #include <linux/crypto.h>
  23. #include <linux/scatterlist.h>
  24. #include <linux/mempolicy.h>
  25. #include <linux/mempool.h>
  26. #include <linux/zpool.h>
  27. #include <crypto/acompress.h>
  28. #include <linux/zswap.h>
  29. #include <linux/mm_types.h>
  30. #include <linux/page-flags.h>
  31. #include <linux/swapops.h>
  32. #include <linux/writeback.h>
  33. #include <linux/pagemap.h>
  34. #include <linux/workqueue.h>
  35. #include <linux/list_lru.h>
  36. #include "swap.h"
  37. #include "internal.h"
  38. /*********************************
  39. * statistics
  40. **********************************/
  41. /* The number of compressed pages currently stored in zswap */
  42. atomic_t zswap_stored_pages = ATOMIC_INIT(0);
  43. /*
  44. * The statistics below are not protected from concurrent access for
  45. * performance reasons so they may not be a 100% accurate. However,
  46. * they do provide useful information on roughly how many times a
  47. * certain event is occurring.
  48. */
  49. /* Pool limit was hit (see zswap_max_pool_percent) */
  50. static u64 zswap_pool_limit_hit;
  51. /* Pages written back when pool limit was reached */
  52. static u64 zswap_written_back_pages;
  53. /* Store failed due to a reclaim failure after pool limit was reached */
  54. static u64 zswap_reject_reclaim_fail;
  55. /* Store failed due to compression algorithm failure */
  56. static u64 zswap_reject_compress_fail;
  57. /* Compressed page was too big for the allocator to (optimally) store */
  58. static u64 zswap_reject_compress_poor;
  59. /* Store failed because underlying allocator could not get memory */
  60. static u64 zswap_reject_alloc_fail;
  61. /* Store failed because the entry metadata could not be allocated (rare) */
  62. static u64 zswap_reject_kmemcache_fail;
  63. /* Shrinker work queue */
  64. static struct workqueue_struct *shrink_wq;
  65. /* Pool limit was hit, we need to calm down */
  66. static bool zswap_pool_reached_full;
  67. /*********************************
  68. * tunables
  69. **********************************/
  70. #define ZSWAP_PARAM_UNSET ""
  71. static int zswap_setup(void);
  72. /* Enable/disable zswap */
  73. static DEFINE_STATIC_KEY_MAYBE(CONFIG_ZSWAP_DEFAULT_ON, zswap_ever_enabled);
  74. static bool zswap_enabled = IS_ENABLED(CONFIG_ZSWAP_DEFAULT_ON);
  75. static int zswap_enabled_param_set(const char *,
  76. const struct kernel_param *);
  77. static const struct kernel_param_ops zswap_enabled_param_ops = {
  78. .set = zswap_enabled_param_set,
  79. .get = param_get_bool,
  80. };
  81. module_param_cb(enabled, &zswap_enabled_param_ops, &zswap_enabled, 0644);
  82. /* Crypto compressor to use */
  83. static char *zswap_compressor = CONFIG_ZSWAP_COMPRESSOR_DEFAULT;
  84. static int zswap_compressor_param_set(const char *,
  85. const struct kernel_param *);
  86. static const struct kernel_param_ops zswap_compressor_param_ops = {
  87. .set = zswap_compressor_param_set,
  88. .get = param_get_charp,
  89. .free = param_free_charp,
  90. };
  91. module_param_cb(compressor, &zswap_compressor_param_ops,
  92. &zswap_compressor, 0644);
  93. /* Compressed storage zpool to use */
  94. static char *zswap_zpool_type = CONFIG_ZSWAP_ZPOOL_DEFAULT;
  95. static int zswap_zpool_param_set(const char *, const struct kernel_param *);
  96. static const 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. /* The threshold for accepting new pages after the max_pool_percent was hit */
  106. static unsigned int zswap_accept_thr_percent = 90; /* of max pool size */
  107. module_param_named(accept_threshold_percent, zswap_accept_thr_percent,
  108. uint, 0644);
  109. /* Enable/disable memory pressure-based shrinker. */
  110. static bool zswap_shrinker_enabled = IS_ENABLED(
  111. CONFIG_ZSWAP_SHRINKER_DEFAULT_ON);
  112. module_param_named(shrinker_enabled, zswap_shrinker_enabled, bool, 0644);
  113. bool zswap_is_enabled(void)
  114. {
  115. return zswap_enabled;
  116. }
  117. bool zswap_never_enabled(void)
  118. {
  119. return !static_branch_maybe(CONFIG_ZSWAP_DEFAULT_ON, &zswap_ever_enabled);
  120. }
  121. /*********************************
  122. * data structures
  123. **********************************/
  124. struct crypto_acomp_ctx {
  125. struct crypto_acomp *acomp;
  126. struct acomp_req *req;
  127. struct crypto_wait wait;
  128. u8 *buffer;
  129. struct mutex mutex;
  130. bool is_sleepable;
  131. };
  132. /*
  133. * The lock ordering is zswap_tree.lock -> zswap_pool.lru_lock.
  134. * The only case where lru_lock is not acquired while holding tree.lock is
  135. * when a zswap_entry is taken off the lru for writeback, in that case it
  136. * needs to be verified that it's still valid in the tree.
  137. */
  138. struct zswap_pool {
  139. struct zpool *zpool;
  140. struct crypto_acomp_ctx __percpu *acomp_ctx;
  141. struct percpu_ref ref;
  142. struct list_head list;
  143. struct work_struct release_work;
  144. struct hlist_node node;
  145. char tfm_name[CRYPTO_MAX_ALG_NAME];
  146. };
  147. /* Global LRU lists shared by all zswap pools. */
  148. static struct list_lru zswap_list_lru;
  149. /* The lock protects zswap_next_shrink updates. */
  150. static DEFINE_SPINLOCK(zswap_shrink_lock);
  151. static struct mem_cgroup *zswap_next_shrink;
  152. static struct work_struct zswap_shrink_work;
  153. static struct shrinker *zswap_shrinker;
  154. /*
  155. * struct zswap_entry
  156. *
  157. * This structure contains the metadata for tracking a single compressed
  158. * page within zswap.
  159. *
  160. * swpentry - associated swap entry, the offset indexes into the red-black tree
  161. * length - the length in bytes of the compressed page data. Needed during
  162. * decompression.
  163. * referenced - true if the entry recently entered the zswap pool. Unset by the
  164. * writeback logic. The entry is only reclaimed by the writeback
  165. * logic if referenced is unset. See comments in the shrinker
  166. * section for context.
  167. * pool - the zswap_pool the entry's data is in
  168. * handle - zpool allocation handle that stores the compressed page data
  169. * objcg - the obj_cgroup that the compressed memory is charged to
  170. * lru - handle to the pool's lru used to evict pages.
  171. */
  172. struct zswap_entry {
  173. swp_entry_t swpentry;
  174. unsigned int length;
  175. bool referenced;
  176. struct zswap_pool *pool;
  177. unsigned long handle;
  178. struct obj_cgroup *objcg;
  179. struct list_head lru;
  180. };
  181. static struct xarray *zswap_trees[MAX_SWAPFILES];
  182. static unsigned int nr_zswap_trees[MAX_SWAPFILES];
  183. /* RCU-protected iteration */
  184. static LIST_HEAD(zswap_pools);
  185. /* protects zswap_pools list modification */
  186. static DEFINE_SPINLOCK(zswap_pools_lock);
  187. /* pool counter to provide unique names to zpool */
  188. static atomic_t zswap_pools_count = ATOMIC_INIT(0);
  189. enum zswap_init_type {
  190. ZSWAP_UNINIT,
  191. ZSWAP_INIT_SUCCEED,
  192. ZSWAP_INIT_FAILED
  193. };
  194. static enum zswap_init_type zswap_init_state;
  195. /* used to ensure the integrity of initialization */
  196. static DEFINE_MUTEX(zswap_init_lock);
  197. /* init completed, but couldn't create the initial pool */
  198. static bool zswap_has_pool;
  199. /*********************************
  200. * helpers and fwd declarations
  201. **********************************/
  202. static inline struct xarray *swap_zswap_tree(swp_entry_t swp)
  203. {
  204. return &zswap_trees[swp_type(swp)][swp_offset(swp)
  205. >> SWAP_ADDRESS_SPACE_SHIFT];
  206. }
  207. #define zswap_pool_debug(msg, p) \
  208. pr_debug("%s pool %s/%s\n", msg, (p)->tfm_name, \
  209. zpool_get_type((p)->zpool))
  210. /*********************************
  211. * pool functions
  212. **********************************/
  213. static void __zswap_pool_empty(struct percpu_ref *ref);
  214. static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
  215. {
  216. struct zswap_pool *pool;
  217. char name[38]; /* 'zswap' + 32 char (max) num + \0 */
  218. gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM;
  219. int ret, cpu;
  220. if (!zswap_has_pool) {
  221. /* if either are unset, pool initialization failed, and we
  222. * need both params to be set correctly before trying to
  223. * create a pool.
  224. */
  225. if (!strcmp(type, ZSWAP_PARAM_UNSET))
  226. return NULL;
  227. if (!strcmp(compressor, ZSWAP_PARAM_UNSET))
  228. return NULL;
  229. }
  230. pool = kzalloc(sizeof(*pool), GFP_KERNEL);
  231. if (!pool)
  232. return NULL;
  233. /* unique name for each pool specifically required by zsmalloc */
  234. snprintf(name, 38, "zswap%x", atomic_inc_return(&zswap_pools_count));
  235. pool->zpool = zpool_create_pool(type, name, gfp);
  236. if (!pool->zpool) {
  237. pr_err("%s zpool not available\n", type);
  238. goto error;
  239. }
  240. pr_debug("using %s zpool\n", zpool_get_type(pool->zpool));
  241. strscpy(pool->tfm_name, compressor, sizeof(pool->tfm_name));
  242. pool->acomp_ctx = alloc_percpu(*pool->acomp_ctx);
  243. if (!pool->acomp_ctx) {
  244. pr_err("percpu alloc failed\n");
  245. goto error;
  246. }
  247. for_each_possible_cpu(cpu)
  248. mutex_init(&per_cpu_ptr(pool->acomp_ctx, cpu)->mutex);
  249. ret = cpuhp_state_add_instance(CPUHP_MM_ZSWP_POOL_PREPARE,
  250. &pool->node);
  251. if (ret)
  252. goto error;
  253. /* being the current pool takes 1 ref; this func expects the
  254. * caller to always add the new pool as the current pool
  255. */
  256. ret = percpu_ref_init(&pool->ref, __zswap_pool_empty,
  257. PERCPU_REF_ALLOW_REINIT, GFP_KERNEL);
  258. if (ret)
  259. goto ref_fail;
  260. INIT_LIST_HEAD(&pool->list);
  261. zswap_pool_debug("created", pool);
  262. return pool;
  263. ref_fail:
  264. cpuhp_state_remove_instance(CPUHP_MM_ZSWP_POOL_PREPARE, &pool->node);
  265. error:
  266. if (pool->acomp_ctx)
  267. free_percpu(pool->acomp_ctx);
  268. if (pool->zpool)
  269. zpool_destroy_pool(pool->zpool);
  270. kfree(pool);
  271. return NULL;
  272. }
  273. static struct zswap_pool *__zswap_pool_create_fallback(void)
  274. {
  275. bool has_comp, has_zpool;
  276. has_comp = crypto_has_acomp(zswap_compressor, 0, 0);
  277. if (!has_comp && strcmp(zswap_compressor,
  278. CONFIG_ZSWAP_COMPRESSOR_DEFAULT)) {
  279. pr_err("compressor %s not available, using default %s\n",
  280. zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT);
  281. param_free_charp(&zswap_compressor);
  282. zswap_compressor = CONFIG_ZSWAP_COMPRESSOR_DEFAULT;
  283. has_comp = crypto_has_acomp(zswap_compressor, 0, 0);
  284. }
  285. if (!has_comp) {
  286. pr_err("default compressor %s not available\n",
  287. zswap_compressor);
  288. param_free_charp(&zswap_compressor);
  289. zswap_compressor = ZSWAP_PARAM_UNSET;
  290. }
  291. has_zpool = zpool_has_pool(zswap_zpool_type);
  292. if (!has_zpool && strcmp(zswap_zpool_type,
  293. CONFIG_ZSWAP_ZPOOL_DEFAULT)) {
  294. pr_err("zpool %s not available, using default %s\n",
  295. zswap_zpool_type, CONFIG_ZSWAP_ZPOOL_DEFAULT);
  296. param_free_charp(&zswap_zpool_type);
  297. zswap_zpool_type = CONFIG_ZSWAP_ZPOOL_DEFAULT;
  298. has_zpool = zpool_has_pool(zswap_zpool_type);
  299. }
  300. if (!has_zpool) {
  301. pr_err("default zpool %s not available\n",
  302. zswap_zpool_type);
  303. param_free_charp(&zswap_zpool_type);
  304. zswap_zpool_type = ZSWAP_PARAM_UNSET;
  305. }
  306. if (!has_comp || !has_zpool)
  307. return NULL;
  308. return zswap_pool_create(zswap_zpool_type, zswap_compressor);
  309. }
  310. static void zswap_pool_destroy(struct zswap_pool *pool)
  311. {
  312. zswap_pool_debug("destroying", pool);
  313. cpuhp_state_remove_instance(CPUHP_MM_ZSWP_POOL_PREPARE, &pool->node);
  314. free_percpu(pool->acomp_ctx);
  315. zpool_destroy_pool(pool->zpool);
  316. kfree(pool);
  317. }
  318. static void __zswap_pool_release(struct work_struct *work)
  319. {
  320. struct zswap_pool *pool = container_of(work, typeof(*pool),
  321. release_work);
  322. synchronize_rcu();
  323. /* nobody should have been able to get a ref... */
  324. WARN_ON(!percpu_ref_is_zero(&pool->ref));
  325. percpu_ref_exit(&pool->ref);
  326. /* pool is now off zswap_pools list and has no references. */
  327. zswap_pool_destroy(pool);
  328. }
  329. static struct zswap_pool *zswap_pool_current(void);
  330. static void __zswap_pool_empty(struct percpu_ref *ref)
  331. {
  332. struct zswap_pool *pool;
  333. pool = container_of(ref, typeof(*pool), ref);
  334. spin_lock_bh(&zswap_pools_lock);
  335. WARN_ON(pool == zswap_pool_current());
  336. list_del_rcu(&pool->list);
  337. INIT_WORK(&pool->release_work, __zswap_pool_release);
  338. schedule_work(&pool->release_work);
  339. spin_unlock_bh(&zswap_pools_lock);
  340. }
  341. static int __must_check zswap_pool_get(struct zswap_pool *pool)
  342. {
  343. if (!pool)
  344. return 0;
  345. return percpu_ref_tryget(&pool->ref);
  346. }
  347. static void zswap_pool_put(struct zswap_pool *pool)
  348. {
  349. percpu_ref_put(&pool->ref);
  350. }
  351. static struct zswap_pool *__zswap_pool_current(void)
  352. {
  353. struct zswap_pool *pool;
  354. pool = list_first_or_null_rcu(&zswap_pools, typeof(*pool), list);
  355. WARN_ONCE(!pool && zswap_has_pool,
  356. "%s: no page storage pool!\n", __func__);
  357. return pool;
  358. }
  359. static struct zswap_pool *zswap_pool_current(void)
  360. {
  361. assert_spin_locked(&zswap_pools_lock);
  362. return __zswap_pool_current();
  363. }
  364. static struct zswap_pool *zswap_pool_current_get(void)
  365. {
  366. struct zswap_pool *pool;
  367. rcu_read_lock();
  368. pool = __zswap_pool_current();
  369. if (!zswap_pool_get(pool))
  370. pool = NULL;
  371. rcu_read_unlock();
  372. return pool;
  373. }
  374. /* type and compressor must be null-terminated */
  375. static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor)
  376. {
  377. struct zswap_pool *pool;
  378. assert_spin_locked(&zswap_pools_lock);
  379. list_for_each_entry_rcu(pool, &zswap_pools, list) {
  380. if (strcmp(pool->tfm_name, compressor))
  381. continue;
  382. if (strcmp(zpool_get_type(pool->zpool), type))
  383. continue;
  384. /* if we can't get it, it's about to be destroyed */
  385. if (!zswap_pool_get(pool))
  386. continue;
  387. return pool;
  388. }
  389. return NULL;
  390. }
  391. static unsigned long zswap_max_pages(void)
  392. {
  393. return totalram_pages() * zswap_max_pool_percent / 100;
  394. }
  395. static unsigned long zswap_accept_thr_pages(void)
  396. {
  397. return zswap_max_pages() * zswap_accept_thr_percent / 100;
  398. }
  399. unsigned long zswap_total_pages(void)
  400. {
  401. struct zswap_pool *pool;
  402. unsigned long total = 0;
  403. rcu_read_lock();
  404. list_for_each_entry_rcu(pool, &zswap_pools, list)
  405. total += zpool_get_total_pages(pool->zpool);
  406. rcu_read_unlock();
  407. return total;
  408. }
  409. static bool zswap_check_limits(void)
  410. {
  411. unsigned long cur_pages = zswap_total_pages();
  412. unsigned long max_pages = zswap_max_pages();
  413. if (cur_pages >= max_pages) {
  414. zswap_pool_limit_hit++;
  415. zswap_pool_reached_full = true;
  416. } else if (zswap_pool_reached_full &&
  417. cur_pages <= zswap_accept_thr_pages()) {
  418. zswap_pool_reached_full = false;
  419. }
  420. return zswap_pool_reached_full;
  421. }
  422. /*********************************
  423. * param callbacks
  424. **********************************/
  425. static bool zswap_pool_changed(const char *s, const struct kernel_param *kp)
  426. {
  427. /* no change required */
  428. if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool)
  429. return false;
  430. return true;
  431. }
  432. /* val must be a null-terminated string */
  433. static int __zswap_param_set(const char *val, const struct kernel_param *kp,
  434. char *type, char *compressor)
  435. {
  436. struct zswap_pool *pool, *put_pool = NULL;
  437. char *s = strstrip((char *)val);
  438. int ret = 0;
  439. bool new_pool = false;
  440. mutex_lock(&zswap_init_lock);
  441. switch (zswap_init_state) {
  442. case ZSWAP_UNINIT:
  443. /* if this is load-time (pre-init) param setting,
  444. * don't create a pool; that's done during init.
  445. */
  446. ret = param_set_charp(s, kp);
  447. break;
  448. case ZSWAP_INIT_SUCCEED:
  449. new_pool = zswap_pool_changed(s, kp);
  450. break;
  451. case ZSWAP_INIT_FAILED:
  452. pr_err("can't set param, initialization failed\n");
  453. ret = -ENODEV;
  454. }
  455. mutex_unlock(&zswap_init_lock);
  456. /* no need to create a new pool, return directly */
  457. if (!new_pool)
  458. return ret;
  459. if (!type) {
  460. if (!zpool_has_pool(s)) {
  461. pr_err("zpool %s not available\n", s);
  462. return -ENOENT;
  463. }
  464. type = s;
  465. } else if (!compressor) {
  466. if (!crypto_has_acomp(s, 0, 0)) {
  467. pr_err("compressor %s not available\n", s);
  468. return -ENOENT;
  469. }
  470. compressor = s;
  471. } else {
  472. WARN_ON(1);
  473. return -EINVAL;
  474. }
  475. spin_lock_bh(&zswap_pools_lock);
  476. pool = zswap_pool_find_get(type, compressor);
  477. if (pool) {
  478. zswap_pool_debug("using existing", pool);
  479. WARN_ON(pool == zswap_pool_current());
  480. list_del_rcu(&pool->list);
  481. }
  482. spin_unlock_bh(&zswap_pools_lock);
  483. if (!pool)
  484. pool = zswap_pool_create(type, compressor);
  485. else {
  486. /*
  487. * Restore the initial ref dropped by percpu_ref_kill()
  488. * when the pool was decommissioned and switch it again
  489. * to percpu mode.
  490. */
  491. percpu_ref_resurrect(&pool->ref);
  492. /* Drop the ref from zswap_pool_find_get(). */
  493. zswap_pool_put(pool);
  494. }
  495. if (pool)
  496. ret = param_set_charp(s, kp);
  497. else
  498. ret = -EINVAL;
  499. spin_lock_bh(&zswap_pools_lock);
  500. if (!ret) {
  501. put_pool = zswap_pool_current();
  502. list_add_rcu(&pool->list, &zswap_pools);
  503. zswap_has_pool = true;
  504. } else if (pool) {
  505. /* add the possibly pre-existing pool to the end of the pools
  506. * list; if it's new (and empty) then it'll be removed and
  507. * destroyed by the put after we drop the lock
  508. */
  509. list_add_tail_rcu(&pool->list, &zswap_pools);
  510. put_pool = pool;
  511. }
  512. spin_unlock_bh(&zswap_pools_lock);
  513. if (!zswap_has_pool && !pool) {
  514. /* if initial pool creation failed, and this pool creation also
  515. * failed, maybe both compressor and zpool params were bad.
  516. * Allow changing this param, so pool creation will succeed
  517. * when the other param is changed. We already verified this
  518. * param is ok in the zpool_has_pool() or crypto_has_acomp()
  519. * checks above.
  520. */
  521. ret = param_set_charp(s, kp);
  522. }
  523. /* drop the ref from either the old current pool,
  524. * or the new pool we failed to add
  525. */
  526. if (put_pool)
  527. percpu_ref_kill(&put_pool->ref);
  528. return ret;
  529. }
  530. static int zswap_compressor_param_set(const char *val,
  531. const struct kernel_param *kp)
  532. {
  533. return __zswap_param_set(val, kp, zswap_zpool_type, NULL);
  534. }
  535. static int zswap_zpool_param_set(const char *val,
  536. const struct kernel_param *kp)
  537. {
  538. return __zswap_param_set(val, kp, NULL, zswap_compressor);
  539. }
  540. static int zswap_enabled_param_set(const char *val,
  541. const struct kernel_param *kp)
  542. {
  543. int ret = -ENODEV;
  544. /* if this is load-time (pre-init) param setting, only set param. */
  545. if (system_state != SYSTEM_RUNNING)
  546. return param_set_bool(val, kp);
  547. mutex_lock(&zswap_init_lock);
  548. switch (zswap_init_state) {
  549. case ZSWAP_UNINIT:
  550. if (zswap_setup())
  551. break;
  552. fallthrough;
  553. case ZSWAP_INIT_SUCCEED:
  554. if (!zswap_has_pool)
  555. pr_err("can't enable, no pool configured\n");
  556. else
  557. ret = param_set_bool(val, kp);
  558. break;
  559. case ZSWAP_INIT_FAILED:
  560. pr_err("can't enable, initialization failed\n");
  561. }
  562. mutex_unlock(&zswap_init_lock);
  563. return ret;
  564. }
  565. /*********************************
  566. * lru functions
  567. **********************************/
  568. /* should be called under RCU */
  569. #ifdef CONFIG_MEMCG
  570. static inline struct mem_cgroup *mem_cgroup_from_entry(struct zswap_entry *entry)
  571. {
  572. return entry->objcg ? obj_cgroup_memcg(entry->objcg) : NULL;
  573. }
  574. #else
  575. static inline struct mem_cgroup *mem_cgroup_from_entry(struct zswap_entry *entry)
  576. {
  577. return NULL;
  578. }
  579. #endif
  580. static inline int entry_to_nid(struct zswap_entry *entry)
  581. {
  582. return page_to_nid(virt_to_page(entry));
  583. }
  584. static void zswap_lru_add(struct list_lru *list_lru, struct zswap_entry *entry)
  585. {
  586. int nid = entry_to_nid(entry);
  587. struct mem_cgroup *memcg;
  588. /*
  589. * Note that it is safe to use rcu_read_lock() here, even in the face of
  590. * concurrent memcg offlining. Thanks to the memcg->kmemcg_id indirection
  591. * used in list_lru lookup, only two scenarios are possible:
  592. *
  593. * 1. list_lru_add() is called before memcg->kmemcg_id is updated. The
  594. * new entry will be reparented to memcg's parent's list_lru.
  595. * 2. list_lru_add() is called after memcg->kmemcg_id is updated. The
  596. * new entry will be added directly to memcg's parent's list_lru.
  597. *
  598. * Similar reasoning holds for list_lru_del().
  599. */
  600. rcu_read_lock();
  601. memcg = mem_cgroup_from_entry(entry);
  602. /* will always succeed */
  603. list_lru_add(list_lru, &entry->lru, nid, memcg);
  604. rcu_read_unlock();
  605. }
  606. static void zswap_lru_del(struct list_lru *list_lru, struct zswap_entry *entry)
  607. {
  608. int nid = entry_to_nid(entry);
  609. struct mem_cgroup *memcg;
  610. rcu_read_lock();
  611. memcg = mem_cgroup_from_entry(entry);
  612. /* will always succeed */
  613. list_lru_del(list_lru, &entry->lru, nid, memcg);
  614. rcu_read_unlock();
  615. }
  616. void zswap_lruvec_state_init(struct lruvec *lruvec)
  617. {
  618. atomic_long_set(&lruvec->zswap_lruvec_state.nr_disk_swapins, 0);
  619. }
  620. void zswap_folio_swapin(struct folio *folio)
  621. {
  622. struct lruvec *lruvec;
  623. if (folio) {
  624. lruvec = folio_lruvec(folio);
  625. atomic_long_inc(&lruvec->zswap_lruvec_state.nr_disk_swapins);
  626. }
  627. }
  628. /*
  629. * This function should be called when a memcg is being offlined.
  630. *
  631. * Since the global shrinker shrink_worker() may hold a reference
  632. * of the memcg, we must check and release the reference in
  633. * zswap_next_shrink.
  634. *
  635. * shrink_worker() must handle the case where this function releases
  636. * the reference of memcg being shrunk.
  637. */
  638. void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg)
  639. {
  640. /* lock out zswap shrinker walking memcg tree */
  641. spin_lock(&zswap_shrink_lock);
  642. if (zswap_next_shrink == memcg) {
  643. do {
  644. zswap_next_shrink = mem_cgroup_iter(NULL, zswap_next_shrink, NULL);
  645. } while (zswap_next_shrink && !mem_cgroup_online(zswap_next_shrink));
  646. }
  647. spin_unlock(&zswap_shrink_lock);
  648. }
  649. /*********************************
  650. * zswap entry functions
  651. **********************************/
  652. static struct kmem_cache *zswap_entry_cache;
  653. static struct zswap_entry *zswap_entry_cache_alloc(gfp_t gfp, int nid)
  654. {
  655. struct zswap_entry *entry;
  656. entry = kmem_cache_alloc_node(zswap_entry_cache, gfp, nid);
  657. if (!entry)
  658. return NULL;
  659. return entry;
  660. }
  661. static void zswap_entry_cache_free(struct zswap_entry *entry)
  662. {
  663. kmem_cache_free(zswap_entry_cache, entry);
  664. }
  665. /*
  666. * Carries out the common pattern of freeing and entry's zpool allocation,
  667. * freeing the entry itself, and decrementing the number of stored pages.
  668. */
  669. static void zswap_entry_free(struct zswap_entry *entry)
  670. {
  671. zswap_lru_del(&zswap_list_lru, entry);
  672. zpool_free(entry->pool->zpool, entry->handle);
  673. zswap_pool_put(entry->pool);
  674. if (entry->objcg) {
  675. obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
  676. obj_cgroup_put(entry->objcg);
  677. }
  678. zswap_entry_cache_free(entry);
  679. atomic_dec(&zswap_stored_pages);
  680. }
  681. /*********************************
  682. * compressed storage functions
  683. **********************************/
  684. static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
  685. {
  686. struct zswap_pool *pool = hlist_entry(node, struct zswap_pool, node);
  687. struct crypto_acomp_ctx *acomp_ctx = per_cpu_ptr(pool->acomp_ctx, cpu);
  688. struct crypto_acomp *acomp = NULL;
  689. struct acomp_req *req = NULL;
  690. u8 *buffer = NULL;
  691. int ret;
  692. buffer = kmalloc_node(PAGE_SIZE * 2, GFP_KERNEL, cpu_to_node(cpu));
  693. if (!buffer) {
  694. ret = -ENOMEM;
  695. goto fail;
  696. }
  697. acomp = crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_node(cpu));
  698. if (IS_ERR(acomp)) {
  699. pr_err("could not alloc crypto acomp %s : %ld\n",
  700. pool->tfm_name, PTR_ERR(acomp));
  701. ret = PTR_ERR(acomp);
  702. goto fail;
  703. }
  704. req = acomp_request_alloc(acomp);
  705. if (!req) {
  706. pr_err("could not alloc crypto acomp_request %s\n",
  707. pool->tfm_name);
  708. ret = -ENOMEM;
  709. goto fail;
  710. }
  711. /*
  712. * Only hold the mutex after completing allocations, otherwise we may
  713. * recurse into zswap through reclaim and attempt to hold the mutex
  714. * again resulting in a deadlock.
  715. */
  716. mutex_lock(&acomp_ctx->mutex);
  717. crypto_init_wait(&acomp_ctx->wait);
  718. /*
  719. * if the backend of acomp is async zip, crypto_req_done() will wakeup
  720. * crypto_wait_req(); if the backend of acomp is scomp, the callback
  721. * won't be called, crypto_wait_req() will return without blocking.
  722. */
  723. acomp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  724. crypto_req_done, &acomp_ctx->wait);
  725. acomp_ctx->buffer = buffer;
  726. acomp_ctx->acomp = acomp;
  727. acomp_ctx->is_sleepable = acomp_is_async(acomp);
  728. acomp_ctx->req = req;
  729. mutex_unlock(&acomp_ctx->mutex);
  730. return 0;
  731. fail:
  732. if (acomp)
  733. crypto_free_acomp(acomp);
  734. kfree(buffer);
  735. return ret;
  736. }
  737. static int zswap_cpu_comp_dead(unsigned int cpu, struct hlist_node *node)
  738. {
  739. struct zswap_pool *pool = hlist_entry(node, struct zswap_pool, node);
  740. struct crypto_acomp_ctx *acomp_ctx = per_cpu_ptr(pool->acomp_ctx, cpu);
  741. struct acomp_req *req;
  742. struct crypto_acomp *acomp;
  743. u8 *buffer;
  744. if (IS_ERR_OR_NULL(acomp_ctx))
  745. return 0;
  746. mutex_lock(&acomp_ctx->mutex);
  747. req = acomp_ctx->req;
  748. acomp = acomp_ctx->acomp;
  749. buffer = acomp_ctx->buffer;
  750. acomp_ctx->req = NULL;
  751. acomp_ctx->acomp = NULL;
  752. acomp_ctx->buffer = NULL;
  753. mutex_unlock(&acomp_ctx->mutex);
  754. /*
  755. * Do the actual freeing after releasing the mutex to avoid subtle
  756. * locking dependencies causing deadlocks.
  757. */
  758. if (!IS_ERR_OR_NULL(req))
  759. acomp_request_free(req);
  760. if (!IS_ERR_OR_NULL(acomp))
  761. crypto_free_acomp(acomp);
  762. kfree(buffer);
  763. return 0;
  764. }
  765. static struct crypto_acomp_ctx *acomp_ctx_get_cpu_lock(struct zswap_pool *pool)
  766. {
  767. struct crypto_acomp_ctx *acomp_ctx;
  768. for (;;) {
  769. acomp_ctx = raw_cpu_ptr(pool->acomp_ctx);
  770. mutex_lock(&acomp_ctx->mutex);
  771. if (likely(acomp_ctx->req))
  772. return acomp_ctx;
  773. /*
  774. * It is possible that we were migrated to a different CPU after
  775. * getting the per-CPU ctx but before the mutex was acquired. If
  776. * the old CPU got offlined, zswap_cpu_comp_dead() could have
  777. * already freed ctx->req (among other things) and set it to
  778. * NULL. Just try again on the new CPU that we ended up on.
  779. */
  780. mutex_unlock(&acomp_ctx->mutex);
  781. }
  782. }
  783. static void acomp_ctx_put_unlock(struct crypto_acomp_ctx *acomp_ctx)
  784. {
  785. mutex_unlock(&acomp_ctx->mutex);
  786. }
  787. static bool zswap_compress(struct folio *folio, struct zswap_entry *entry)
  788. {
  789. struct crypto_acomp_ctx *acomp_ctx;
  790. struct scatterlist input, output;
  791. int comp_ret = 0, alloc_ret = 0;
  792. unsigned int dlen = PAGE_SIZE;
  793. unsigned long handle;
  794. struct zpool *zpool;
  795. char *buf;
  796. gfp_t gfp;
  797. u8 *dst;
  798. acomp_ctx = acomp_ctx_get_cpu_lock(entry->pool);
  799. dst = acomp_ctx->buffer;
  800. sg_init_table(&input, 1);
  801. sg_set_folio(&input, folio, PAGE_SIZE, 0);
  802. /*
  803. * We need PAGE_SIZE * 2 here since there maybe over-compression case,
  804. * and hardware-accelerators may won't check the dst buffer size, so
  805. * giving the dst buffer with enough length to avoid buffer overflow.
  806. */
  807. sg_init_one(&output, dst, PAGE_SIZE * 2);
  808. acomp_request_set_params(acomp_ctx->req, &input, &output, PAGE_SIZE, dlen);
  809. /*
  810. * it maybe looks a little bit silly that we send an asynchronous request,
  811. * then wait for its completion synchronously. This makes the process look
  812. * synchronous in fact.
  813. * Theoretically, acomp supports users send multiple acomp requests in one
  814. * acomp instance, then get those requests done simultaneously. but in this
  815. * case, zswap actually does store and load page by page, there is no
  816. * existing method to send the second page before the first page is done
  817. * in one thread doing zwap.
  818. * but in different threads running on different cpu, we have different
  819. * acomp instance, so multiple threads can do (de)compression in parallel.
  820. */
  821. comp_ret = crypto_wait_req(crypto_acomp_compress(acomp_ctx->req), &acomp_ctx->wait);
  822. dlen = acomp_ctx->req->dlen;
  823. if (comp_ret)
  824. goto unlock;
  825. zpool = entry->pool->zpool;
  826. gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM;
  827. if (zpool_malloc_support_movable(zpool))
  828. gfp |= __GFP_HIGHMEM | __GFP_MOVABLE;
  829. alloc_ret = zpool_malloc(zpool, dlen, gfp, &handle);
  830. if (alloc_ret)
  831. goto unlock;
  832. buf = zpool_map_handle(zpool, handle, ZPOOL_MM_WO);
  833. memcpy(buf, dst, dlen);
  834. zpool_unmap_handle(zpool, handle);
  835. entry->handle = handle;
  836. entry->length = dlen;
  837. unlock:
  838. if (comp_ret == -ENOSPC || alloc_ret == -ENOSPC)
  839. zswap_reject_compress_poor++;
  840. else if (comp_ret)
  841. zswap_reject_compress_fail++;
  842. else if (alloc_ret)
  843. zswap_reject_alloc_fail++;
  844. acomp_ctx_put_unlock(acomp_ctx);
  845. return comp_ret == 0 && alloc_ret == 0;
  846. }
  847. static void zswap_decompress(struct zswap_entry *entry, struct folio *folio)
  848. {
  849. struct zpool *zpool = entry->pool->zpool;
  850. struct scatterlist input, output;
  851. struct crypto_acomp_ctx *acomp_ctx;
  852. u8 *src;
  853. acomp_ctx = acomp_ctx_get_cpu_lock(entry->pool);
  854. src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO);
  855. /*
  856. * If zpool_map_handle is atomic, we cannot reliably utilize its mapped buffer
  857. * to do crypto_acomp_decompress() which might sleep. In such cases, we must
  858. * resort to copying the buffer to a temporary one.
  859. * Meanwhile, zpool_map_handle() might return a non-linearly mapped buffer,
  860. * such as a kmap address of high memory or even ever a vmap address.
  861. * However, sg_init_one is only equipped to handle linearly mapped low memory.
  862. * In such cases, we also must copy the buffer to a temporary and lowmem one.
  863. */
  864. if ((acomp_ctx->is_sleepable && !zpool_can_sleep_mapped(zpool)) ||
  865. !virt_addr_valid(src)) {
  866. memcpy(acomp_ctx->buffer, src, entry->length);
  867. src = acomp_ctx->buffer;
  868. zpool_unmap_handle(zpool, entry->handle);
  869. }
  870. sg_init_one(&input, src, entry->length);
  871. sg_init_table(&output, 1);
  872. sg_set_folio(&output, folio, PAGE_SIZE, 0);
  873. acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, PAGE_SIZE);
  874. BUG_ON(crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait));
  875. BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE);
  876. if (src != acomp_ctx->buffer)
  877. zpool_unmap_handle(zpool, entry->handle);
  878. acomp_ctx_put_unlock(acomp_ctx);
  879. }
  880. /*********************************
  881. * writeback code
  882. **********************************/
  883. /*
  884. * Attempts to free an entry by adding a folio to the swap cache,
  885. * decompressing the entry data into the folio, and issuing a
  886. * bio write to write the folio back to the swap device.
  887. *
  888. * This can be thought of as a "resumed writeback" of the folio
  889. * to the swap device. We are basically resuming the same swap
  890. * writeback path that was intercepted with the zswap_store()
  891. * in the first place. After the folio has been decompressed into
  892. * the swap cache, the compressed version stored by zswap can be
  893. * freed.
  894. */
  895. static int zswap_writeback_entry(struct zswap_entry *entry,
  896. swp_entry_t swpentry)
  897. {
  898. struct xarray *tree;
  899. pgoff_t offset = swp_offset(swpentry);
  900. struct folio *folio;
  901. struct mempolicy *mpol;
  902. bool folio_was_allocated;
  903. struct writeback_control wbc = {
  904. .sync_mode = WB_SYNC_NONE,
  905. };
  906. /* try to allocate swap cache folio */
  907. mpol = get_task_policy(current);
  908. folio = __read_swap_cache_async(swpentry, GFP_KERNEL, mpol,
  909. NO_INTERLEAVE_INDEX, &folio_was_allocated, true);
  910. if (!folio)
  911. return -ENOMEM;
  912. /*
  913. * Found an existing folio, we raced with swapin or concurrent
  914. * shrinker. We generally writeback cold folios from zswap, and
  915. * swapin means the folio just became hot, so skip this folio.
  916. * For unlikely concurrent shrinker case, it will be unlinked
  917. * and freed when invalidated by the concurrent shrinker anyway.
  918. */
  919. if (!folio_was_allocated) {
  920. folio_put(folio);
  921. return -EEXIST;
  922. }
  923. /*
  924. * folio is locked, and the swapcache is now secured against
  925. * concurrent swapping to and from the slot, and concurrent
  926. * swapoff so we can safely dereference the zswap tree here.
  927. * Verify that the swap entry hasn't been invalidated and recycled
  928. * behind our backs, to avoid overwriting a new swap folio with
  929. * old compressed data. Only when this is successful can the entry
  930. * be dereferenced.
  931. */
  932. tree = swap_zswap_tree(swpentry);
  933. if (entry != xa_cmpxchg(tree, offset, entry, NULL, GFP_KERNEL)) {
  934. delete_from_swap_cache(folio);
  935. folio_unlock(folio);
  936. folio_put(folio);
  937. return -ENOMEM;
  938. }
  939. zswap_decompress(entry, folio);
  940. count_vm_event(ZSWPWB);
  941. if (entry->objcg)
  942. count_objcg_events(entry->objcg, ZSWPWB, 1);
  943. zswap_entry_free(entry);
  944. /* folio is up to date */
  945. folio_mark_uptodate(folio);
  946. /* move it to the tail of the inactive list after end_writeback */
  947. folio_set_reclaim(folio);
  948. /* start writeback */
  949. __swap_writepage(folio, &wbc);
  950. folio_put(folio);
  951. return 0;
  952. }
  953. /*********************************
  954. * shrinker functions
  955. **********************************/
  956. /*
  957. * The dynamic shrinker is modulated by the following factors:
  958. *
  959. * 1. Each zswap entry has a referenced bit, which the shrinker unsets (giving
  960. * the entry a second chance) before rotating it in the LRU list. If the
  961. * entry is considered again by the shrinker, with its referenced bit unset,
  962. * it is written back. The writeback rate as a result is dynamically
  963. * adjusted by the pool activities - if the pool is dominated by new entries
  964. * (i.e lots of recent zswapouts), these entries will be protected and
  965. * the writeback rate will slow down. On the other hand, if the pool has a
  966. * lot of stagnant entries, these entries will be reclaimed immediately,
  967. * effectively increasing the writeback rate.
  968. *
  969. * 2. Swapins counter: If we observe swapins, it is a sign that we are
  970. * overshrinking and should slow down. We maintain a swapins counter, which
  971. * is consumed and subtract from the number of eligible objects on the LRU
  972. * in zswap_shrinker_count().
  973. *
  974. * 3. Compression ratio. The better the workload compresses, the less gains we
  975. * can expect from writeback. We scale down the number of objects available
  976. * for reclaim by this ratio.
  977. */
  978. static enum lru_status shrink_memcg_cb(struct list_head *item, struct list_lru_one *l,
  979. spinlock_t *lock, void *arg)
  980. {
  981. struct zswap_entry *entry = container_of(item, struct zswap_entry, lru);
  982. bool *encountered_page_in_swapcache = (bool *)arg;
  983. swp_entry_t swpentry;
  984. enum lru_status ret = LRU_REMOVED_RETRY;
  985. int writeback_result;
  986. /*
  987. * Second chance algorithm: if the entry has its referenced bit set, give it
  988. * a second chance. Only clear the referenced bit and rotate it in the
  989. * zswap's LRU list.
  990. */
  991. if (entry->referenced) {
  992. entry->referenced = false;
  993. return LRU_ROTATE;
  994. }
  995. /*
  996. * As soon as we drop the LRU lock, the entry can be freed by
  997. * a concurrent invalidation. This means the following:
  998. *
  999. * 1. We extract the swp_entry_t to the stack, allowing
  1000. * zswap_writeback_entry() to pin the swap entry and
  1001. * then validate the zwap entry against that swap entry's
  1002. * tree using pointer value comparison. Only when that
  1003. * is successful can the entry be dereferenced.
  1004. *
  1005. * 2. Usually, objects are taken off the LRU for reclaim. In
  1006. * this case this isn't possible, because if reclaim fails
  1007. * for whatever reason, we have no means of knowing if the
  1008. * entry is alive to put it back on the LRU.
  1009. *
  1010. * So rotate it before dropping the lock. If the entry is
  1011. * written back or invalidated, the free path will unlink
  1012. * it. For failures, rotation is the right thing as well.
  1013. *
  1014. * Temporary failures, where the same entry should be tried
  1015. * again immediately, almost never happen for this shrinker.
  1016. * We don't do any trylocking; -ENOMEM comes closest,
  1017. * but that's extremely rare and doesn't happen spuriously
  1018. * either. Don't bother distinguishing this case.
  1019. */
  1020. list_move_tail(item, &l->list);
  1021. /*
  1022. * Once the lru lock is dropped, the entry might get freed. The
  1023. * swpentry is copied to the stack, and entry isn't deref'd again
  1024. * until the entry is verified to still be alive in the tree.
  1025. */
  1026. swpentry = entry->swpentry;
  1027. /*
  1028. * It's safe to drop the lock here because we return either
  1029. * LRU_REMOVED_RETRY or LRU_RETRY.
  1030. */
  1031. spin_unlock(lock);
  1032. writeback_result = zswap_writeback_entry(entry, swpentry);
  1033. if (writeback_result) {
  1034. zswap_reject_reclaim_fail++;
  1035. ret = LRU_RETRY;
  1036. /*
  1037. * Encountering a page already in swap cache is a sign that we are shrinking
  1038. * into the warmer region. We should terminate shrinking (if we're in the dynamic
  1039. * shrinker context).
  1040. */
  1041. if (writeback_result == -EEXIST && encountered_page_in_swapcache) {
  1042. ret = LRU_STOP;
  1043. *encountered_page_in_swapcache = true;
  1044. }
  1045. } else {
  1046. zswap_written_back_pages++;
  1047. }
  1048. spin_lock(lock);
  1049. return ret;
  1050. }
  1051. static unsigned long zswap_shrinker_scan(struct shrinker *shrinker,
  1052. struct shrink_control *sc)
  1053. {
  1054. unsigned long shrink_ret;
  1055. bool encountered_page_in_swapcache = false;
  1056. if (!zswap_shrinker_enabled ||
  1057. !mem_cgroup_zswap_writeback_enabled(sc->memcg)) {
  1058. sc->nr_scanned = 0;
  1059. return SHRINK_STOP;
  1060. }
  1061. shrink_ret = list_lru_shrink_walk(&zswap_list_lru, sc, &shrink_memcg_cb,
  1062. &encountered_page_in_swapcache);
  1063. if (encountered_page_in_swapcache)
  1064. return SHRINK_STOP;
  1065. return shrink_ret ? shrink_ret : SHRINK_STOP;
  1066. }
  1067. static unsigned long zswap_shrinker_count(struct shrinker *shrinker,
  1068. struct shrink_control *sc)
  1069. {
  1070. struct mem_cgroup *memcg = sc->memcg;
  1071. struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(sc->nid));
  1072. atomic_long_t *nr_disk_swapins =
  1073. &lruvec->zswap_lruvec_state.nr_disk_swapins;
  1074. unsigned long nr_backing, nr_stored, nr_freeable, nr_disk_swapins_cur,
  1075. nr_remain;
  1076. if (!zswap_shrinker_enabled || !mem_cgroup_zswap_writeback_enabled(memcg))
  1077. return 0;
  1078. /*
  1079. * The shrinker resumes swap writeback, which will enter block
  1080. * and may enter fs. XXX: Harmonize with vmscan.c __GFP_FS
  1081. * rules (may_enter_fs()), which apply on a per-folio basis.
  1082. */
  1083. if (!gfp_has_io_fs(sc->gfp_mask))
  1084. return 0;
  1085. /*
  1086. * For memcg, use the cgroup-wide ZSWAP stats since we don't
  1087. * have them per-node and thus per-lruvec. Careful if memcg is
  1088. * runtime-disabled: we can get sc->memcg == NULL, which is ok
  1089. * for the lruvec, but not for memcg_page_state().
  1090. *
  1091. * Without memcg, use the zswap pool-wide metrics.
  1092. */
  1093. if (!mem_cgroup_disabled()) {
  1094. mem_cgroup_flush_stats(memcg);
  1095. nr_backing = memcg_page_state(memcg, MEMCG_ZSWAP_B) >> PAGE_SHIFT;
  1096. nr_stored = memcg_page_state(memcg, MEMCG_ZSWAPPED);
  1097. } else {
  1098. nr_backing = zswap_total_pages();
  1099. nr_stored = atomic_read(&zswap_stored_pages);
  1100. }
  1101. if (!nr_stored)
  1102. return 0;
  1103. nr_freeable = list_lru_shrink_count(&zswap_list_lru, sc);
  1104. if (!nr_freeable)
  1105. return 0;
  1106. /*
  1107. * Subtract from the lru size the number of pages that are recently swapped
  1108. * in from disk. The idea is that had we protect the zswap's LRU by this
  1109. * amount of pages, these disk swapins would not have happened.
  1110. */
  1111. nr_disk_swapins_cur = atomic_long_read(nr_disk_swapins);
  1112. do {
  1113. if (nr_freeable >= nr_disk_swapins_cur)
  1114. nr_remain = 0;
  1115. else
  1116. nr_remain = nr_disk_swapins_cur - nr_freeable;
  1117. } while (!atomic_long_try_cmpxchg(
  1118. nr_disk_swapins, &nr_disk_swapins_cur, nr_remain));
  1119. nr_freeable -= nr_disk_swapins_cur - nr_remain;
  1120. if (!nr_freeable)
  1121. return 0;
  1122. /*
  1123. * Scale the number of freeable pages by the memory saving factor.
  1124. * This ensures that the better zswap compresses memory, the fewer
  1125. * pages we will evict to swap (as it will otherwise incur IO for
  1126. * relatively small memory saving).
  1127. */
  1128. return mult_frac(nr_freeable, nr_backing, nr_stored);
  1129. }
  1130. static struct shrinker *zswap_alloc_shrinker(void)
  1131. {
  1132. struct shrinker *shrinker;
  1133. shrinker =
  1134. shrinker_alloc(SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, "mm-zswap");
  1135. if (!shrinker)
  1136. return NULL;
  1137. shrinker->scan_objects = zswap_shrinker_scan;
  1138. shrinker->count_objects = zswap_shrinker_count;
  1139. shrinker->batch = 0;
  1140. shrinker->seeks = DEFAULT_SEEKS;
  1141. return shrinker;
  1142. }
  1143. static int shrink_memcg(struct mem_cgroup *memcg)
  1144. {
  1145. int nid, shrunk = 0, scanned = 0;
  1146. if (!mem_cgroup_zswap_writeback_enabled(memcg))
  1147. return -ENOENT;
  1148. /*
  1149. * Skip zombies because their LRUs are reparented and we would be
  1150. * reclaiming from the parent instead of the dead memcg.
  1151. */
  1152. if (memcg && !mem_cgroup_online(memcg))
  1153. return -ENOENT;
  1154. for_each_node_state(nid, N_NORMAL_MEMORY) {
  1155. unsigned long nr_to_walk = 1;
  1156. shrunk += list_lru_walk_one(&zswap_list_lru, nid, memcg,
  1157. &shrink_memcg_cb, NULL, &nr_to_walk);
  1158. scanned += 1 - nr_to_walk;
  1159. }
  1160. if (!scanned)
  1161. return -ENOENT;
  1162. return shrunk ? 0 : -EAGAIN;
  1163. }
  1164. static void shrink_worker(struct work_struct *w)
  1165. {
  1166. struct mem_cgroup *memcg;
  1167. int ret, failures = 0, attempts = 0;
  1168. unsigned long thr;
  1169. /* Reclaim down to the accept threshold */
  1170. thr = zswap_accept_thr_pages();
  1171. /*
  1172. * Global reclaim will select cgroup in a round-robin fashion from all
  1173. * online memcgs, but memcgs that have no pages in zswap and
  1174. * writeback-disabled memcgs (memory.zswap.writeback=0) are not
  1175. * candidates for shrinking.
  1176. *
  1177. * Shrinking will be aborted if we encounter the following
  1178. * MAX_RECLAIM_RETRIES times:
  1179. * - No writeback-candidate memcgs found in a memcg tree walk.
  1180. * - Shrinking a writeback-candidate memcg failed.
  1181. *
  1182. * We save iteration cursor memcg into zswap_next_shrink,
  1183. * which can be modified by the offline memcg cleaner
  1184. * zswap_memcg_offline_cleanup().
  1185. *
  1186. * Since the offline cleaner is called only once, we cannot leave an
  1187. * offline memcg reference in zswap_next_shrink.
  1188. * We can rely on the cleaner only if we get online memcg under lock.
  1189. *
  1190. * If we get an offline memcg, we cannot determine if the cleaner has
  1191. * already been called or will be called later. We must put back the
  1192. * reference before returning from this function. Otherwise, the
  1193. * offline memcg left in zswap_next_shrink will hold the reference
  1194. * until the next run of shrink_worker().
  1195. */
  1196. do {
  1197. /*
  1198. * Start shrinking from the next memcg after zswap_next_shrink.
  1199. * When the offline cleaner has already advanced the cursor,
  1200. * advancing the cursor here overlooks one memcg, but this
  1201. * should be negligibly rare.
  1202. *
  1203. * If we get an online memcg, keep the extra reference in case
  1204. * the original one obtained by mem_cgroup_iter() is dropped by
  1205. * zswap_memcg_offline_cleanup() while we are shrinking the
  1206. * memcg.
  1207. */
  1208. spin_lock(&zswap_shrink_lock);
  1209. do {
  1210. memcg = mem_cgroup_iter(NULL, zswap_next_shrink, NULL);
  1211. zswap_next_shrink = memcg;
  1212. } while (memcg && !mem_cgroup_tryget_online(memcg));
  1213. spin_unlock(&zswap_shrink_lock);
  1214. if (!memcg) {
  1215. /*
  1216. * Continue shrinking without incrementing failures if
  1217. * we found candidate memcgs in the last tree walk.
  1218. */
  1219. if (!attempts && ++failures == MAX_RECLAIM_RETRIES)
  1220. break;
  1221. attempts = 0;
  1222. goto resched;
  1223. }
  1224. ret = shrink_memcg(memcg);
  1225. /* drop the extra reference */
  1226. mem_cgroup_put(memcg);
  1227. /*
  1228. * There are no writeback-candidate pages in the memcg.
  1229. * This is not an issue as long as we can find another memcg
  1230. * with pages in zswap. Skip this without incrementing attempts
  1231. * and failures.
  1232. */
  1233. if (ret == -ENOENT)
  1234. continue;
  1235. ++attempts;
  1236. if (ret && ++failures == MAX_RECLAIM_RETRIES)
  1237. break;
  1238. resched:
  1239. cond_resched();
  1240. } while (zswap_total_pages() > thr);
  1241. }
  1242. /*********************************
  1243. * main API
  1244. **********************************/
  1245. bool zswap_store(struct folio *folio)
  1246. {
  1247. swp_entry_t swp = folio->swap;
  1248. pgoff_t offset = swp_offset(swp);
  1249. struct xarray *tree = swap_zswap_tree(swp);
  1250. struct zswap_entry *entry, *old;
  1251. struct obj_cgroup *objcg = NULL;
  1252. struct mem_cgroup *memcg = NULL;
  1253. VM_WARN_ON_ONCE(!folio_test_locked(folio));
  1254. VM_WARN_ON_ONCE(!folio_test_swapcache(folio));
  1255. /* Large folios aren't supported */
  1256. if (folio_test_large(folio))
  1257. return false;
  1258. if (!zswap_enabled)
  1259. goto check_old;
  1260. /* Check cgroup limits */
  1261. objcg = get_obj_cgroup_from_folio(folio);
  1262. if (objcg && !obj_cgroup_may_zswap(objcg)) {
  1263. memcg = get_mem_cgroup_from_objcg(objcg);
  1264. if (shrink_memcg(memcg)) {
  1265. mem_cgroup_put(memcg);
  1266. goto reject;
  1267. }
  1268. mem_cgroup_put(memcg);
  1269. }
  1270. if (zswap_check_limits())
  1271. goto reject;
  1272. /* allocate entry */
  1273. entry = zswap_entry_cache_alloc(GFP_KERNEL, folio_nid(folio));
  1274. if (!entry) {
  1275. zswap_reject_kmemcache_fail++;
  1276. goto reject;
  1277. }
  1278. /* if entry is successfully added, it keeps the reference */
  1279. entry->pool = zswap_pool_current_get();
  1280. if (!entry->pool)
  1281. goto freepage;
  1282. if (objcg) {
  1283. memcg = get_mem_cgroup_from_objcg(objcg);
  1284. if (memcg_list_lru_alloc(memcg, &zswap_list_lru, GFP_KERNEL)) {
  1285. mem_cgroup_put(memcg);
  1286. goto put_pool;
  1287. }
  1288. mem_cgroup_put(memcg);
  1289. }
  1290. if (!zswap_compress(folio, entry))
  1291. goto put_pool;
  1292. entry->swpentry = swp;
  1293. entry->objcg = objcg;
  1294. entry->referenced = true;
  1295. old = xa_store(tree, offset, entry, GFP_KERNEL);
  1296. if (xa_is_err(old)) {
  1297. int err = xa_err(old);
  1298. WARN_ONCE(err != -ENOMEM, "unexpected xarray error: %d\n", err);
  1299. zswap_reject_alloc_fail++;
  1300. goto store_failed;
  1301. }
  1302. /*
  1303. * We may have had an existing entry that became stale when
  1304. * the folio was redirtied and now the new version is being
  1305. * swapped out. Get rid of the old.
  1306. */
  1307. if (old)
  1308. zswap_entry_free(old);
  1309. if (objcg) {
  1310. obj_cgroup_charge_zswap(objcg, entry->length);
  1311. count_objcg_events(objcg, ZSWPOUT, 1);
  1312. }
  1313. /*
  1314. * We finish initializing the entry while it's already in xarray.
  1315. * This is safe because:
  1316. *
  1317. * 1. Concurrent stores and invalidations are excluded by folio lock.
  1318. *
  1319. * 2. Writeback is excluded by the entry not being on the LRU yet.
  1320. * The publishing order matters to prevent writeback from seeing
  1321. * an incoherent entry.
  1322. */
  1323. if (entry->length) {
  1324. INIT_LIST_HEAD(&entry->lru);
  1325. zswap_lru_add(&zswap_list_lru, entry);
  1326. }
  1327. /* update stats */
  1328. atomic_inc(&zswap_stored_pages);
  1329. count_vm_event(ZSWPOUT);
  1330. return true;
  1331. store_failed:
  1332. zpool_free(entry->pool->zpool, entry->handle);
  1333. put_pool:
  1334. zswap_pool_put(entry->pool);
  1335. freepage:
  1336. zswap_entry_cache_free(entry);
  1337. reject:
  1338. obj_cgroup_put(objcg);
  1339. if (zswap_pool_reached_full)
  1340. queue_work(shrink_wq, &zswap_shrink_work);
  1341. check_old:
  1342. /*
  1343. * If the zswap store fails or zswap is disabled, we must invalidate the
  1344. * possibly stale entry which was previously stored at this offset.
  1345. * Otherwise, writeback could overwrite the new data in the swapfile.
  1346. */
  1347. entry = xa_erase(tree, offset);
  1348. if (entry)
  1349. zswap_entry_free(entry);
  1350. return false;
  1351. }
  1352. bool zswap_load(struct folio *folio)
  1353. {
  1354. swp_entry_t swp = folio->swap;
  1355. pgoff_t offset = swp_offset(swp);
  1356. bool swapcache = folio_test_swapcache(folio);
  1357. struct xarray *tree = swap_zswap_tree(swp);
  1358. struct zswap_entry *entry;
  1359. VM_WARN_ON_ONCE(!folio_test_locked(folio));
  1360. if (zswap_never_enabled())
  1361. return false;
  1362. /*
  1363. * Large folios should not be swapped in while zswap is being used, as
  1364. * they are not properly handled. Zswap does not properly load large
  1365. * folios, and a large folio may only be partially in zswap.
  1366. *
  1367. * Return true without marking the folio uptodate so that an IO error is
  1368. * emitted (e.g. do_swap_page() will sigbus).
  1369. */
  1370. if (WARN_ON_ONCE(folio_test_large(folio)))
  1371. return true;
  1372. /*
  1373. * When reading into the swapcache, invalidate our entry. The
  1374. * swapcache can be the authoritative owner of the page and
  1375. * its mappings, and the pressure that results from having two
  1376. * in-memory copies outweighs any benefits of caching the
  1377. * compression work.
  1378. *
  1379. * (Most swapins go through the swapcache. The notable
  1380. * exception is the singleton fault on SWP_SYNCHRONOUS_IO
  1381. * files, which reads into a private page and may free it if
  1382. * the fault fails. We remain the primary owner of the entry.)
  1383. */
  1384. if (swapcache)
  1385. entry = xa_erase(tree, offset);
  1386. else
  1387. entry = xa_load(tree, offset);
  1388. if (!entry)
  1389. return false;
  1390. zswap_decompress(entry, folio);
  1391. count_vm_event(ZSWPIN);
  1392. if (entry->objcg)
  1393. count_objcg_events(entry->objcg, ZSWPIN, 1);
  1394. if (swapcache) {
  1395. zswap_entry_free(entry);
  1396. folio_mark_dirty(folio);
  1397. }
  1398. folio_mark_uptodate(folio);
  1399. return true;
  1400. }
  1401. void zswap_invalidate(swp_entry_t swp)
  1402. {
  1403. pgoff_t offset = swp_offset(swp);
  1404. struct xarray *tree = swap_zswap_tree(swp);
  1405. struct zswap_entry *entry;
  1406. entry = xa_erase(tree, offset);
  1407. if (entry)
  1408. zswap_entry_free(entry);
  1409. }
  1410. int zswap_swapon(int type, unsigned long nr_pages)
  1411. {
  1412. struct xarray *trees, *tree;
  1413. unsigned int nr, i;
  1414. nr = DIV_ROUND_UP(nr_pages, SWAP_ADDRESS_SPACE_PAGES);
  1415. trees = kvcalloc(nr, sizeof(*tree), GFP_KERNEL);
  1416. if (!trees) {
  1417. pr_err("alloc failed, zswap disabled for swap type %d\n", type);
  1418. return -ENOMEM;
  1419. }
  1420. for (i = 0; i < nr; i++)
  1421. xa_init(trees + i);
  1422. nr_zswap_trees[type] = nr;
  1423. zswap_trees[type] = trees;
  1424. return 0;
  1425. }
  1426. void zswap_swapoff(int type)
  1427. {
  1428. struct xarray *trees = zswap_trees[type];
  1429. unsigned int i;
  1430. if (!trees)
  1431. return;
  1432. /* try_to_unuse() invalidated all the entries already */
  1433. for (i = 0; i < nr_zswap_trees[type]; i++)
  1434. WARN_ON_ONCE(!xa_empty(trees + i));
  1435. kvfree(trees);
  1436. nr_zswap_trees[type] = 0;
  1437. zswap_trees[type] = NULL;
  1438. }
  1439. /*********************************
  1440. * debugfs functions
  1441. **********************************/
  1442. #ifdef CONFIG_DEBUG_FS
  1443. #include <linux/debugfs.h>
  1444. static struct dentry *zswap_debugfs_root;
  1445. static int debugfs_get_total_size(void *data, u64 *val)
  1446. {
  1447. *val = zswap_total_pages() * PAGE_SIZE;
  1448. return 0;
  1449. }
  1450. DEFINE_DEBUGFS_ATTRIBUTE(total_size_fops, debugfs_get_total_size, NULL, "%llu\n");
  1451. static int zswap_debugfs_init(void)
  1452. {
  1453. if (!debugfs_initialized())
  1454. return -ENODEV;
  1455. zswap_debugfs_root = debugfs_create_dir("zswap", NULL);
  1456. debugfs_create_u64("pool_limit_hit", 0444,
  1457. zswap_debugfs_root, &zswap_pool_limit_hit);
  1458. debugfs_create_u64("reject_reclaim_fail", 0444,
  1459. zswap_debugfs_root, &zswap_reject_reclaim_fail);
  1460. debugfs_create_u64("reject_alloc_fail", 0444,
  1461. zswap_debugfs_root, &zswap_reject_alloc_fail);
  1462. debugfs_create_u64("reject_kmemcache_fail", 0444,
  1463. zswap_debugfs_root, &zswap_reject_kmemcache_fail);
  1464. debugfs_create_u64("reject_compress_fail", 0444,
  1465. zswap_debugfs_root, &zswap_reject_compress_fail);
  1466. debugfs_create_u64("reject_compress_poor", 0444,
  1467. zswap_debugfs_root, &zswap_reject_compress_poor);
  1468. debugfs_create_u64("written_back_pages", 0444,
  1469. zswap_debugfs_root, &zswap_written_back_pages);
  1470. debugfs_create_file("pool_total_size", 0444,
  1471. zswap_debugfs_root, NULL, &total_size_fops);
  1472. debugfs_create_atomic_t("stored_pages", 0444,
  1473. zswap_debugfs_root, &zswap_stored_pages);
  1474. return 0;
  1475. }
  1476. #else
  1477. static int zswap_debugfs_init(void)
  1478. {
  1479. return 0;
  1480. }
  1481. #endif
  1482. /*********************************
  1483. * module init and exit
  1484. **********************************/
  1485. static int zswap_setup(void)
  1486. {
  1487. struct zswap_pool *pool;
  1488. int ret;
  1489. zswap_entry_cache = KMEM_CACHE(zswap_entry, 0);
  1490. if (!zswap_entry_cache) {
  1491. pr_err("entry cache creation failed\n");
  1492. goto cache_fail;
  1493. }
  1494. ret = cpuhp_setup_state_multi(CPUHP_MM_ZSWP_POOL_PREPARE,
  1495. "mm/zswap_pool:prepare",
  1496. zswap_cpu_comp_prepare,
  1497. zswap_cpu_comp_dead);
  1498. if (ret)
  1499. goto hp_fail;
  1500. shrink_wq = alloc_workqueue("zswap-shrink",
  1501. WQ_UNBOUND|WQ_MEM_RECLAIM, 1);
  1502. if (!shrink_wq)
  1503. goto shrink_wq_fail;
  1504. zswap_shrinker = zswap_alloc_shrinker();
  1505. if (!zswap_shrinker)
  1506. goto shrinker_fail;
  1507. if (list_lru_init_memcg(&zswap_list_lru, zswap_shrinker))
  1508. goto lru_fail;
  1509. shrinker_register(zswap_shrinker);
  1510. INIT_WORK(&zswap_shrink_work, shrink_worker);
  1511. pool = __zswap_pool_create_fallback();
  1512. if (pool) {
  1513. pr_info("loaded using pool %s/%s\n", pool->tfm_name,
  1514. zpool_get_type(pool->zpool));
  1515. list_add(&pool->list, &zswap_pools);
  1516. zswap_has_pool = true;
  1517. static_branch_enable(&zswap_ever_enabled);
  1518. } else {
  1519. pr_err("pool creation failed\n");
  1520. zswap_enabled = false;
  1521. }
  1522. if (zswap_debugfs_init())
  1523. pr_warn("debugfs initialization failed\n");
  1524. zswap_init_state = ZSWAP_INIT_SUCCEED;
  1525. return 0;
  1526. lru_fail:
  1527. shrinker_free(zswap_shrinker);
  1528. shrinker_fail:
  1529. destroy_workqueue(shrink_wq);
  1530. shrink_wq_fail:
  1531. cpuhp_remove_multi_state(CPUHP_MM_ZSWP_POOL_PREPARE);
  1532. hp_fail:
  1533. kmem_cache_destroy(zswap_entry_cache);
  1534. cache_fail:
  1535. /* if built-in, we aren't unloaded on failure; don't allow use */
  1536. zswap_init_state = ZSWAP_INIT_FAILED;
  1537. zswap_enabled = false;
  1538. return -ENOMEM;
  1539. }
  1540. static int __init zswap_init(void)
  1541. {
  1542. if (!zswap_enabled)
  1543. return 0;
  1544. return zswap_setup();
  1545. }
  1546. /* must be late so crypto has time to come up */
  1547. late_initcall(zswap_init);
  1548. MODULE_AUTHOR("Seth Jennings <sjennings@variantweb.net>");
  1549. MODULE_DESCRIPTION("Compressed cache for swap pages");