xref: /linux/include/linux/zswap.h (revision f73a058be5d70dd81a43f16b2bbff4b1576a7af8)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_ZSWAP_H
3 #define _LINUX_ZSWAP_H
4 
5 #include <linux/types.h>
6 #include <linux/mm_types.h>
7 
8 struct lruvec;
9 
10 extern atomic_t zswap_stored_pages;
11 
12 #ifdef CONFIG_ZSWAP
13 
14 struct zswap_lruvec_state {
15 	/*
16 	 * Number of pages in zswap that should be protected from the shrinker.
17 	 * This number is an estimate of the following counts:
18 	 *
19 	 * a) Recent page faults.
20 	 * b) Recent insertion to the zswap LRU. This includes new zswap stores,
21 	 *    as well as recent zswap LRU rotations.
22 	 *
23 	 * These pages are likely to be warm, and might incur IO if the are written
24 	 * to swap.
25 	 */
26 	atomic_long_t nr_zswap_protected;
27 };
28 
29 unsigned long zswap_total_pages(void);
30 bool zswap_store(struct folio *folio);
31 bool zswap_load(struct folio *folio);
32 void zswap_invalidate(swp_entry_t swp);
33 int zswap_swapon(int type, unsigned long nr_pages);
34 void zswap_swapoff(int type);
35 void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg);
36 void zswap_lruvec_state_init(struct lruvec *lruvec);
37 void zswap_folio_swapin(struct folio *folio);
38 bool is_zswap_enabled(void);
39 #else
40 
41 struct zswap_lruvec_state {};
42 
43 static inline bool zswap_store(struct folio *folio)
44 {
45 	return false;
46 }
47 
48 static inline bool zswap_load(struct folio *folio)
49 {
50 	return false;
51 }
52 
53 static inline void zswap_invalidate(swp_entry_t swp) {}
54 static inline int zswap_swapon(int type, unsigned long nr_pages)
55 {
56 	return 0;
57 }
58 static inline void zswap_swapoff(int type) {}
59 static inline void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg) {}
60 static inline void zswap_lruvec_state_init(struct lruvec *lruvec) {}
61 static inline void zswap_folio_swapin(struct folio *folio) {}
62 
63 static inline bool is_zswap_enabled(void)
64 {
65 	return false;
66 }
67 
68 #endif
69 
70 #endif /* _LINUX_ZSWAP_H */
71